001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }