1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.PropsKeys;
29  import com.liferay.portal.kernel.util.StringPool;
30  import com.liferay.portal.kernel.util.Validator;
31  import com.liferay.portal.model.Image;
32  import com.liferay.portal.service.ImageLocalServiceUtil;
33  import com.liferay.portal.util.PropsUtil;
34  import com.liferay.portlet.journal.model.JournalArticle;
35  import com.liferay.portlet.journal.util.LocaleTransformerListener;
36  import com.liferay.util.LocalizationUtil;
37  
38  /**
39   * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   * @author Wesley Gong
43   */
44  public class JournalArticleImpl
45      extends JournalArticleModelImpl implements JournalArticle {
46  
47      public static final double DEFAULT_VERSION = 1.0;
48  
49      public static final String PORTLET = "portlet";
50  
51      public static final String STAND_ALONE = "stand-alone";
52  
53      public static final String[] TYPES =
54          PropsUtil.getArray(PropsKeys.JOURNAL_ARTICLE_TYPES);
55  
56      public static String getContentByLocale(
57          String content, boolean templateDriven, String languageId) {
58  
59          LocaleTransformerListener listener = new LocaleTransformerListener();
60  
61          listener.setTemplateDriven(templateDriven);
62          listener.setLanguageId(languageId);
63  
64          return listener.onXml(content);
65      }
66  
67      public JournalArticleImpl() {
68      }
69  
70      public String[] getAvailableLocales() {
71          return LocalizationUtil.getAvailableLocales(getContent());
72      }
73  
74      public String getContentByLocale(String languageId) {
75          return getContentByLocale(getContent(), isTemplateDriven(), languageId);
76      }
77  
78      public String getDefaultLocale() {
79          String xml = getContent();
80  
81          if (xml == null) {
82              return StringPool.BLANK;
83          }
84  
85          String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
86  
87          if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
88              defaultLanguageId = LocaleUtil.toLanguageId(
89                  LocaleUtil.getDefault());
90          }
91  
92          return defaultLanguageId;
93      }
94  
95      public String getSmallImageType() throws PortalException, SystemException {
96          if (_smallImageType == null && isSmallImage()) {
97              Image smallImage =  ImageLocalServiceUtil.getImage(
98                  getSmallImageId());
99  
100             _smallImageType = smallImage.getType();
101         }
102 
103         return _smallImageType;
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 }