1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.model.impl;
16  
17  import com.liferay.portal.image.Hook;
18  import com.liferay.portal.image.HookFactory;
19  import com.liferay.portal.kernel.image.ImageProcessor;
20  import com.liferay.portal.kernel.log.Log;
21  import com.liferay.portal.kernel.log.LogFactoryUtil;
22  import com.liferay.portal.kernel.util.Base64;
23  import com.liferay.portal.model.Image;
24  
25  /**
26   * <a href="ImageImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class ImageImpl extends ImageModelImpl implements Image {
31  
32      public static final String TYPE_BMP = ImageProcessor.TYPE_BMP;
33  
34      public static final String TYPE_GIF = ImageProcessor.TYPE_GIF;
35  
36      public static final String TYPE_JPEG = ImageProcessor.TYPE_JPEG;
37  
38      public static final String TYPE_PNG = ImageProcessor.TYPE_PNG;
39  
40      public static final String TYPE_TIFF = ImageProcessor.TYPE_TIFF;
41  
42      public static final String TYPE_NOT_AVAILABLE =
43          ImageProcessor.TYPE_NOT_AVAILABLE;
44  
45      public ImageImpl() {
46      }
47  
48      public byte[] getTextObj() {
49          if (_textObj == null) {
50              try {
51                  Hook hook = HookFactory.getInstance();
52  
53                  _textObj = hook.getImageAsBytes(this);
54              }
55              catch (Exception e) {
56                  _log.error("Error reading image " + getImageId(), e);
57              }
58          }
59  
60          return _textObj;
61      }
62  
63      public void setTextObj(byte[] textObj) {
64          _textObj = textObj;
65  
66          super.setText(Base64.objectToString(textObj));
67      }
68  
69      private byte[] _textObj;
70  
71      private static Log _log = LogFactoryUtil.getLog(ImageImpl.class);
72  
73  }