1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.util.Base64;
22  import com.liferay.portal.model.Image;
23  
24  /**
25   * <a href="ImageImpl.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class ImageImpl extends ImageModelImpl implements Image {
30  
31      public ImageImpl() {
32      }
33  
34      public byte[] getTextObj() {
35          if (_textObj == null) {
36              try {
37                  Hook hook = HookFactory.getInstance();
38  
39                  _textObj = hook.getImageAsBytes(this);
40              }
41              catch (Exception e) {
42                  _log.error("Error reading image " + getImageId(), e);
43              }
44          }
45  
46          return _textObj;
47      }
48  
49      public void setTextObj(byte[] textObj) {
50          _textObj = textObj;
51  
52          super.setText(Base64.objectToString(textObj));
53      }
54  
55      private byte[] _textObj;
56  
57      private static Log _log = LogFactoryUtil.getLog(ImageImpl.class);
58  
59  }