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.PropsKeys;
34  import com.liferay.portal.util.PropsUtil;
35  import com.liferay.portlet.journal.model.JournalArticle;
36  import com.liferay.portlet.journal.util.LocaleTransformerListener;
37  import com.liferay.util.LocalizationUtil;
38  
39  /**
40   * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class JournalArticleImpl
46      extends JournalArticleModelImpl implements JournalArticle {
47  
48      public static final double DEFAULT_VERSION = 1.0;
49  
50      public static final String[] TYPES =
51          PropsUtil.getArray(PropsKeys.JOURNAL_ARTICLE_TYPES);
52  
53      public static final String PORTLET = "portlet";
54  
55      public static final String STAND_ALONE = "stand-alone";
56  
57      public JournalArticleImpl() {
58      }
59  
60      public String getUserUuid() throws SystemException {
61          return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
62      }
63  
64      public void setUserUuid(String userUuid) {
65          _userUuid = userUuid;
66      }
67  
68      public String[] getAvailableLocales() {
69          return LocalizationUtil.getAvailableLocales(getContent());
70      }
71  
72      public String getContentByLocale(String languageId){
73          LocaleTransformerListener listener = new LocaleTransformerListener();
74  
75          listener.setTemplateDriven(isTemplateDriven());
76          listener.setLanguageId(languageId);
77  
78          return listener.onXml(getContent());
79      }
80  
81      public String getDefaultLocale() {
82          String xml = getContent();
83  
84          if (xml == null) {
85              return StringPool.BLANK;
86          }
87  
88          if (isTemplateDriven()) {
89              String defaultLanguageId = LocaleUtil.toLanguageId(
90                  LocaleUtil.getDefault());
91  
92              return defaultLanguageId;
93          }
94          else {
95              return LocalizationUtil.getDefaultLocale(xml);
96          }
97      }
98  
99      public boolean isTemplateDriven() {
100         if (Validator.isNull(getStructureId())) {
101             return false;
102         }
103         else {
104             return true;
105         }
106     }
107 
108     public String getApprovedByUserUuid() throws SystemException {
109         return PortalUtil.getUserValue(
110             getApprovedByUserId(), "uuid", _approvedByUserUuid);
111     }
112 
113     public void setApprovedByUserUuid(String approvedByUserUuid) {
114         _approvedByUserUuid = approvedByUserUuid;
115     }
116 
117     public String getSmallImageType() throws PortalException, SystemException {
118         if (_smallImageType == null && isSmallImage()) {
119             Image smallImage =  ImageLocalServiceUtil.getImage(
120                 getSmallImageId());
121 
122             _smallImageType = smallImage.getType();
123         }
124 
125         return _smallImageType;
126     }
127 
128     public void setSmallImageType(String smallImageType) {
129         _smallImageType = smallImageType;
130     }
131 
132     private String _userUuid;
133     private String _approvedByUserUuid;
134     private String _smallImageType;
135 
136 }