1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.journal.model.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.util.LocaleUtil;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.kernel.util.Validator;
22  import com.liferay.portal.kernel.workflow.StatusConstants;
23  import com.liferay.portal.model.Image;
24  import com.liferay.portal.service.ImageLocalServiceUtil;
25  import com.liferay.portlet.journal.model.JournalArticle;
26  import com.liferay.portlet.journal.util.LocaleTransformerListener;
27  import com.liferay.util.LocalizationUtil;
28  
29  /**
30   * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   * @author Wesley Gong
34   */
35  public class JournalArticleImpl
36      extends JournalArticleModelImpl implements JournalArticle {
37  
38      public static String getContentByLocale(
39          String content, boolean templateDriven, String languageId) {
40  
41          LocaleTransformerListener listener = new LocaleTransformerListener();
42  
43          listener.setTemplateDriven(templateDriven);
44          listener.setLanguageId(languageId);
45  
46          return listener.onXml(content);
47      }
48  
49      public JournalArticleImpl() {
50      }
51  
52      public String[] getAvailableLocales() {
53          return LocalizationUtil.getAvailableLocales(getContent());
54      }
55  
56      public String getContentByLocale(String languageId) {
57          return getContentByLocale(getContent(), isTemplateDriven(), languageId);
58      }
59  
60      public String getDefaultLocale() {
61          String xml = getContent();
62  
63          if (xml == null) {
64              return StringPool.BLANK;
65          }
66  
67          String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
68  
69          if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
70              defaultLanguageId = LocaleUtil.toLanguageId(
71                  LocaleUtil.getDefault());
72          }
73  
74          return defaultLanguageId;
75      }
76  
77      public String getSmallImageType() throws PortalException, SystemException {
78          if (_smallImageType == null && isSmallImage()) {
79              Image smallImage =  ImageLocalServiceUtil.getImage(
80                  getSmallImageId());
81  
82              _smallImageType = smallImage.getType();
83          }
84  
85          return _smallImageType;
86      }
87  
88      public boolean isApproved() {
89          if (getStatus() == StatusConstants.APPROVED) {
90              return true;
91          }
92          else {
93              return false;
94          }
95      }
96  
97      public boolean isExpired() {
98          if (getStatus() == StatusConstants.EXPIRED) {
99              return true;
100         }
101         else {
102             return false;
103         }
104     }
105 
106     public boolean isTemplateDriven() {
107         if (Validator.isNull(getStructureId())) {
108             return false;
109         }
110         else {
111             return true;
112         }
113     }
114 
115     public void setSmallImageType(String smallImageType) {
116         _smallImageType = smallImageType;
117     }
118 
119     private String _smallImageType;
120 
121 }