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.PortalUtil;
33  import com.liferay.portal.util.PropsKeys;
34  import com.liferay.portal.util.PropsUtil;
35  import com.liferay.portlet.expando.model.ExpandoBridge;
36  import com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl;
37  import com.liferay.portlet.journal.model.JournalArticle;
38  import com.liferay.portlet.journal.util.LocaleTransformerListener;
39  import com.liferay.util.LocalizationUtil;
40  
41  /**
42   * <a href="JournalArticleImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * @author Brian Wing Shun Chan
45   *
46   */
47  public class JournalArticleImpl
48      extends JournalArticleModelImpl implements JournalArticle {
49  
50      public static final double DEFAULT_VERSION = 1.0;
51  
52      public static final String PORTLET = "portlet";
53  
54      public static final String STAND_ALONE = "stand-alone";
55  
56      public static final String[] TYPES =
57          PropsUtil.getArray(PropsKeys.JOURNAL_ARTICLE_TYPES);
58  
59      public static String getContentByLocale(
60          String content, boolean templateDriven, String languageId) {
61  
62          LocaleTransformerListener listener = new LocaleTransformerListener();
63  
64          listener.setTemplateDriven(templateDriven);
65          listener.setLanguageId(languageId);
66  
67          return listener.onXml(content);
68      }
69  
70      public JournalArticleImpl() {
71      }
72  
73      public String getApprovedByUserUuid() throws SystemException {
74          return PortalUtil.getUserValue(
75              getApprovedByUserId(), "uuid", _approvedByUserUuid);
76      }
77  
78      public String[] getAvailableLocales() {
79          return LocalizationUtil.getAvailableLocales(getContent());
80      }
81  
82      public String getContentByLocale(String languageId) {
83          return getContentByLocale(getContent(), isTemplateDriven(), languageId);
84      }
85  
86      public String getDefaultLocale() {
87          String xml = getContent();
88  
89          if (xml == null) {
90              return StringPool.BLANK;
91          }
92  
93          if (isTemplateDriven()) {
94              String defaultLanguageId = LocaleUtil.toLanguageId(
95                  LocaleUtil.getDefault());
96  
97              return defaultLanguageId;
98          }
99          else {
100             return LocalizationUtil.getDefaultLocale(xml);
101         }
102     }
103 
104     public ExpandoBridge getExpandoBridge() {
105         if (_expandoBridge == null) {
106             _expandoBridge = new ExpandoBridgeImpl(
107                 JournalArticle.class.getName(), getResourcePrimKey());
108         }
109 
110         return _expandoBridge;
111     }
112 
113     public String getSmallImageType() throws PortalException, SystemException {
114         if (_smallImageType == null && isSmallImage()) {
115             Image smallImage =  ImageLocalServiceUtil.getImage(
116                 getSmallImageId());
117 
118             _smallImageType = smallImage.getType();
119         }
120 
121         return _smallImageType;
122     }
123 
124     public boolean isTemplateDriven() {
125         if (Validator.isNull(getStructureId())) {
126             return false;
127         }
128         else {
129             return true;
130         }
131     }
132 
133     public void setApprovedByUserUuid(String approvedByUserUuid) {
134         _approvedByUserUuid = approvedByUserUuid;
135     }
136 
137     public void setSmallImageType(String smallImageType) {
138         _smallImageType = smallImageType;
139     }
140 
141     private String _approvedByUserUuid;
142     private ExpandoBridge _expandoBridge;
143     private String _smallImageType;
144 
145 }