001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.image.HookFactory;
018    import com.liferay.portal.kernel.image.Hook;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.Base64;
022    import com.liferay.portal.model.Image;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class ImageImpl extends ImageModelImpl implements Image {
028    
029            public ImageImpl() {
030            }
031    
032            public byte[] getTextObj() {
033                    if (_textObj == null) {
034                            try {
035                                    Hook hook = HookFactory.getInstance();
036    
037                                    _textObj = hook.getImageAsBytes(this);
038                            }
039                            catch (Exception e) {
040                                    _log.error("Error reading image " + getImageId(), e);
041                            }
042                    }
043    
044                    return _textObj;
045            }
046    
047            public void setTextObj(byte[] textObj) {
048                    _textObj = textObj;
049    
050                    super.setText(Base64.objectToString(textObj));
051            }
052    
053            private byte[] _textObj;
054    
055            private static Log _log = LogFactoryUtil.getLog(ImageImpl.class);
056    
057    }