1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.imagegallery.model.impl;
21  
22  import com.liferay.portal.SystemException;
23  import com.liferay.portal.kernel.log.Log;
24  import com.liferay.portal.kernel.log.LogFactoryUtil;
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.model.Image;
28  import com.liferay.portal.service.ImageLocalServiceUtil;
29  import com.liferay.portal.util.PortalUtil;
30  import com.liferay.portlet.imagegallery.model.IGFolder;
31  import com.liferay.portlet.imagegallery.model.IGImage;
32  import com.liferay.portlet.imagegallery.service.IGFolderLocalServiceUtil;
33  
34  /**
35   * <a href="IGImageImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class IGImageImpl extends IGImageModelImpl implements IGImage {
41  
42      public static String getNameWithExtension(String name, String type) {
43          if (Validator.isNotNull(type)) {
44              name += StringPool.PERIOD + type;
45          }
46  
47          return name;
48      }
49  
50      public IGImageImpl() {
51      }
52  
53      public String getUserUuid() throws SystemException {
54          return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
55      }
56  
57      public void setUserUuid(String userUuid) {
58          _userUuid = userUuid;
59      }
60  
61      public IGFolder getFolder() {
62          IGFolder folder = null;
63  
64          try {
65              folder = IGFolderLocalServiceUtil.getFolder(getFolderId());
66          }
67          catch (Exception e) {
68              folder = new IGFolderImpl();
69  
70              _log.error(e);
71          }
72  
73          return folder;
74      }
75  
76      public String getNameWithExtension() {
77          String nameWithExtension = getName();
78  
79          if (Validator.isNull(nameWithExtension)) {
80              nameWithExtension = String.valueOf(getImageId());
81          }
82  
83          String type = getImageType();
84  
85          return getNameWithExtension(nameWithExtension, type);
86      }
87  
88      public String getImageType() {
89          if (_imageType == null) {
90              try {
91                  Image largeImage = ImageLocalServiceUtil.getImage(
92                      getLargeImageId());
93  
94                  _imageType = largeImage.getType();
95              }
96              catch (Exception e) {
97                  _imageType = StringPool.BLANK;
98  
99                  _log.error(e);
100             }
101         }
102 
103         return _imageType;
104     }
105 
106     public void setImageType(String imageType) {
107         _imageType = imageType;
108     }
109 
110     public int getImageSize() {
111         if (_imageSize == null) {
112             try {
113                 Image largeImage = ImageLocalServiceUtil.getImage(
114                     getLargeImageId());
115 
116                 _imageSize = new Integer(largeImage.getSize());
117             }
118             catch (Exception e) {
119                 _imageSize = new Integer(0);
120 
121                 _log.error(e);
122             }
123         }
124 
125         return _imageSize.intValue();
126     }
127 
128     private static Log _log = LogFactoryUtil.getLog(IGImageImpl.class);
129 
130     private String _userUuid;
131     private String _imageType;
132     private Integer _imageSize;
133 
134 }