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.LocalizationUtil;
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.portlet.journal.model.JournalArticle;
26  import com.liferay.portlet.journal.util.LocaleTransformerListener;
27  
28  /**
29   * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   * @author Wesley Gong
33   */
34  public class JournalArticleImpl
35      extends JournalArticleModelImpl implements JournalArticle {
36  
37      public static String getContentByLocale(
38          String content, boolean templateDriven, String languageId) {
39  
40          LocaleTransformerListener listener = new LocaleTransformerListener();
41  
42          listener.setTemplateDriven(templateDriven);
43          listener.setLanguageId(languageId);
44  
45          return listener.onXml(content);
46      }
47  
48      public JournalArticleImpl() {
49      }
50  
51      public String[] getAvailableLocales() {
52          return LocalizationUtil.getAvailableLocales(getContent());
53      }
54  
55      public String getContentByLocale(String languageId) {
56          return getContentByLocale(getContent(), isTemplateDriven(), languageId);
57      }
58  
59      public String getDefaultLocale() {
60          String xml = getContent();
61  
62          if (xml == null) {
63              return StringPool.BLANK;
64          }
65  
66          String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
67  
68          if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
69              defaultLanguageId = LocaleUtil.toLanguageId(
70                  LocaleUtil.getDefault());
71          }
72  
73          return defaultLanguageId;
74      }
75  
76      public String getSmallImageType() throws PortalException, SystemException {
77          if (_smallImageType == null && isSmallImage()) {
78              Image smallImage =  ImageLocalServiceUtil.getImage(
79                  getSmallImageId());
80  
81              _smallImageType = smallImage.getType();
82          }
83  
84          return _smallImageType;
85      }
86  
87      public boolean isTemplateDriven() {
88          if (Validator.isNull(getStructureId())) {
89              return false;
90          }
91          else {
92              return true;
93          }
94      }
95  
96      public void setSmallImageType(String smallImageType) {
97          _smallImageType = smallImageType;
98      }
99  
100     private String _smallImageType;
101 
102 }