1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.model.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.util.LocaleUtil;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.portal.kernel.util.Validator;
30  import com.liferay.portal.model.Image;
31  import com.liferay.portal.service.ImageLocalServiceUtil;
32  import com.liferay.portal.util.PortalUtil;
33  import com.liferay.portal.util.PropsUtil;
34  import com.liferay.portlet.journal.model.JournalArticle;
35  import com.liferay.portlet.journal.util.LocaleTransformerListener;
36  import com.liferay.util.LocalizationUtil;
37  
38  /**
39   * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   *
43   */
44  public class JournalArticleImpl
45      extends JournalArticleModelImpl implements JournalArticle {
46  
47      public static final double DEFAULT_VERSION = 1.0;
48  
49      public static final String[] TYPES =
50          PropsUtil.getArray(PropsUtil.JOURNAL_ARTICLE_TYPES);
51  
52      public static final String PORTLET = "portlet";
53  
54      public static final String STAND_ALONE = "stand-alone";
55  
56      public JournalArticleImpl() {
57      }
58  
59      public String getUserUuid() throws SystemException {
60          return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
61      }
62  
63      public void setUserUuid(String userUuid) {
64          _userUuid = userUuid;
65      }
66  
67      public String[] getAvailableLocales() {
68          return LocalizationUtil.getAvailableLocales(getContent());
69      }
70  
71      public String getContentByLocale(String languageId){
72          LocaleTransformerListener listener = new LocaleTransformerListener();
73  
74          listener.setTemplateDriven(isTemplateDriven());
75          listener.setLanguageId(languageId);
76  
77          return listener.onXml(getContent());
78      }
79  
80      public String getDefaultLocale() {
81          String xml = getContent();
82  
83          if (xml == null) {
84              return StringPool.BLANK;
85          }
86  
87          if (isTemplateDriven()) {
88              String defaultLanguageId = LocaleUtil.toLanguageId(
89                  LocaleUtil.getDefault());
90  
91              return defaultLanguageId;
92          }
93          else {
94              return LocalizationUtil.getDefaultLocale(xml);
95          }
96      }
97  
98      public boolean isTemplateDriven() {
99          if (Validator.isNull(getStructureId())) {
100             return false;
101         }
102         else {
103             return true;
104         }
105     }
106 
107     public String getApprovedByUserUuid() throws SystemException {
108         return PortalUtil.getUserValue(
109             getApprovedByUserId(), "uuid", _approvedByUserUuid);
110     }
111 
112     public void setApprovedByUserUuid(String approvedByUserUuid) {
113         _approvedByUserUuid = approvedByUserUuid;
114     }
115 
116     public String getSmallImageType() throws PortalException, SystemException {
117         if (_smallImageType == null && isSmallImage()) {
118             Image smallImage =  ImageLocalServiceUtil.getImage(
119                 getSmallImageId());
120 
121             _smallImageType = smallImage.getType();
122         }
123 
124         return _smallImageType;
125     }
126 
127     public void setSmallImageType(String smallImageType) {
128         _smallImageType = smallImageType;
129     }
130 
131     private String _userUuid;
132     private String _approvedByUserUuid;
133     private String _smallImageType;
134 
135 }