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.PropsKeys;
21  import com.liferay.portal.kernel.util.StringPool;
22  import com.liferay.portal.kernel.util.Validator;
23  import com.liferay.portal.model.Image;
24  import com.liferay.portal.service.ImageLocalServiceUtil;
25  import com.liferay.portal.util.PropsUtil;
26  import com.liferay.portlet.journal.model.JournalArticle;
27  import com.liferay.portlet.journal.util.LocaleTransformerListener;
28  import com.liferay.util.LocalizationUtil;
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 JournalArticleImpl() {
49      }
50  
51      public String[] getAvailableLocales() {
52          return LocalizationUtil.getAvailableLocales(getContent());
53      }
54  
55      public String getContentByLocale(String languageId) {
56          LocaleTransformerListener listener = new LocaleTransformerListener();
57  
58          listener.setTemplateDriven(isTemplateDriven());
59          listener.setLanguageId(languageId);
60  
61          return listener.onXml(getContent());
62      }
63  
64      public String getDefaultLocale() {
65          String xml = getContent();
66  
67          if (xml == null) {
68              return StringPool.BLANK;
69          }
70  
71          String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
72  
73          if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
74              defaultLanguageId = LocaleUtil.toLanguageId(
75                  LocaleUtil.getDefault());
76          }
77  
78          return defaultLanguageId;
79      }
80  
81      public String getSmallImageType() throws PortalException, SystemException {
82          if (_smallImageType == null && isSmallImage()) {
83              Image smallImage =  ImageLocalServiceUtil.getImage(
84                  getSmallImageId());
85  
86              _smallImageType = smallImage.getType();
87          }
88  
89          return _smallImageType;
90      }
91  
92      public boolean isTemplateDriven() {
93          if (Validator.isNull(getStructureId())) {
94              return false;
95          }
96          else {
97              return true;
98          }
99      }
100 
101     public void setSmallImageType(String smallImageType) {
102         _smallImageType = smallImageType;
103     }
104 
105     private String _smallImageType;
106 
107 }