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