1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portlet.journal.model.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.util.LocaleUtil;
20  import com.liferay.portal.kernel.util.LocalizationUtil;
21  import com.liferay.portal.kernel.util.PropsKeys;
22  import com.liferay.portal.kernel.util.StringPool;
23  import com.liferay.portal.kernel.util.Validator;
24  import com.liferay.portal.model.Image;
25  import com.liferay.portal.service.ImageLocalServiceUtil;
26  import com.liferay.portal.util.PropsUtil;
27  import com.liferay.portlet.journal.model.JournalArticle;
28  import com.liferay.portlet.journal.util.LocaleTransformerListener;
29  
30  /**
31   * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Wesley Gong
35   */
36  public class JournalArticleImpl
37      extends JournalArticleModelImpl implements JournalArticle {
38  
39      public static final double DEFAULT_VERSION = 1.0;
40  
41      public static final String PORTLET = "portlet";
42  
43      public static final String STAND_ALONE = "stand-alone";
44  
45      public static final String[] TYPES =
46          PropsUtil.getArray(PropsKeys.JOURNAL_ARTICLE_TYPES);
47  
48      public static String getContentByLocale(
49          String content, boolean templateDriven, String languageId) {
50  
51          LocaleTransformerListener listener = new LocaleTransformerListener();
52  
53          listener.setTemplateDriven(templateDriven);
54          listener.setLanguageId(languageId);
55  
56          return listener.onXml(content);
57      }
58  
59      public JournalArticleImpl() {
60      }
61  
62      public String[] getAvailableLocales() {
63          return LocalizationUtil.getAvailableLocales(getContent());
64      }
65  
66      public String getContentByLocale(String languageId) {
67          return getContentByLocale(getContent(), isTemplateDriven(), languageId);
68      }
69  
70      public String getDefaultLocale() {
71          String xml = getContent();
72  
73          if (xml == null) {
74              return StringPool.BLANK;
75          }
76  
77          String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
78  
79          if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
80              defaultLanguageId = LocaleUtil.toLanguageId(
81                  LocaleUtil.getDefault());
82          }
83  
84          return defaultLanguageId;
85      }
86  
87      public String getSmallImageType() throws PortalException, SystemException {
88          if (_smallImageType == null && isSmallImage()) {
89              Image smallImage =  ImageLocalServiceUtil.getImage(
90                  getSmallImageId());
91  
92              _smallImageType = smallImage.getType();
93          }
94  
95          return _smallImageType;
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 void setSmallImageType(String smallImageType) {
108         _smallImageType = smallImageType;
109     }
110 
111     private String _smallImageType;
112 
113 }