1   /**
2    * Copyright (c) 2000-2009 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[] getAvailableLocales() {
61          return LocalizationUtil.getAvailableLocales(getContent());
62      }
63  
64      public String getContentByLocale(String languageId){
65          LocaleTransformerListener listener = new LocaleTransformerListener();
66  
67          listener.setTemplateDriven(isTemplateDriven());
68          listener.setLanguageId(languageId);
69  
70          return listener.onXml(getContent());
71      }
72  
73      public String getDefaultLocale() {
74          String xml = getContent();
75  
76          if (xml == null) {
77              return StringPool.BLANK;
78          }
79  
80          if (isTemplateDriven()) {
81              String defaultLanguageId = LocaleUtil.toLanguageId(
82                  LocaleUtil.getDefault());
83  
84              return defaultLanguageId;
85          }
86          else {
87              return LocalizationUtil.getDefaultLocale(xml);
88          }
89      }
90  
91      public boolean isTemplateDriven() {
92          if (Validator.isNull(getStructureId())) {
93              return false;
94          }
95          else {
96              return true;
97          }
98      }
99  
100     public String getApprovedByUserUuid() throws SystemException {
101         return PortalUtil.getUserValue(
102             getApprovedByUserId(), "uuid", _approvedByUserUuid);
103     }
104 
105     public void setApprovedByUserUuid(String approvedByUserUuid) {
106         _approvedByUserUuid = approvedByUserUuid;
107     }
108 
109     public String getSmallImageType() throws PortalException, SystemException {
110         if (_smallImageType == null && isSmallImage()) {
111             Image smallImage =  ImageLocalServiceUtil.getImage(
112                 getSmallImageId());
113 
114             _smallImageType = smallImage.getType();
115         }
116 
117         return _smallImageType;
118     }
119 
120     public void setSmallImageType(String smallImageType) {
121         _smallImageType = smallImageType;
122     }
123 
124     private String _approvedByUserUuid;
125     private String _smallImageType;
126 
127 }