1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.kernel.util.LocaleUtil;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portal.util.PropsUtil;
29  import com.liferay.portlet.journal.model.JournalArticle;
30  import com.liferay.portlet.journal.util.LocaleTransformerListener;
31  import com.liferay.util.LocalizationUtil;
32  
33  import org.apache.commons.logging.Log;
34  import org.apache.commons.logging.LogFactory;
35  
36  /**
37   * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class JournalArticleImpl
43      extends JournalArticleModelImpl implements JournalArticle {
44  
45      public static final double DEFAULT_VERSION = 1.0;
46  
47      public static final String[] TYPES =
48          PropsUtil.getArray(PropsUtil.JOURNAL_ARTICLE_TYPES);
49  
50      public static final String PORTLET = "portlet";
51  
52      public static final String STAND_ALONE = "stand-alone";
53  
54      public JournalArticleImpl() {
55      }
56  
57      public String[] getAvailableLocales() {
58          return LocalizationUtil.getAvailableLocales(getContent());
59      }
60  
61      public String getContentByLocale(String languageId){
62          LocaleTransformerListener listener = new LocaleTransformerListener();
63  
64          listener.setTemplateDriven(isTemplateDriven());
65          listener.setLanguageId(languageId);
66  
67          return listener.onXml(getContent());
68      }
69  
70      public String getDefaultLocale() {
71          String xml = getContent();
72  
73          if (xml == null) {
74              return StringPool.BLANK;
75          }
76  
77          if (isTemplateDriven()) {
78              String defaultLanguageId = LocaleUtil.toLanguageId(
79                  LocaleUtil.getDefault());
80  
81              return defaultLanguageId;
82          }
83          else {
84              return LocalizationUtil.getDefaultLocale(xml);
85          }
86      }
87  
88      public boolean isTemplateDriven() {
89          if (Validator.isNull(getStructureId())) {
90              return false;
91          }
92          else {
93              return true;
94          }
95      }
96  
97      private static Log _log = LogFactory.getLog(JournalArticleImpl.class);
98  
99  }