1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.journal.model.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.kernel.util.LocaleUtil;
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.model.Image;
28  import com.liferay.portal.service.ImageLocalServiceUtil;
29  import com.liferay.portal.util.PortalUtil;
30  import com.liferay.portal.util.PropsKeys;
31  import com.liferay.portal.util.PropsUtil;
32  import com.liferay.portlet.journal.model.JournalArticle;
33  import com.liferay.portlet.journal.util.LocaleTransformerListener;
34  import com.liferay.util.LocalizationUtil;
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(PropsKeys.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 getUserUuid() throws SystemException {
58          return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
59      }
60  
61      public void setUserUuid(String userUuid) {
62          _userUuid = userUuid;
63      }
64  
65      public String[] getAvailableLocales() {
66          return LocalizationUtil.getAvailableLocales(getContent());
67      }
68  
69      public String getContentByLocale(String languageId){
70          LocaleTransformerListener listener = new LocaleTransformerListener();
71  
72          listener.setTemplateDriven(isTemplateDriven());
73          listener.setLanguageId(languageId);
74  
75          return listener.onXml(getContent());
76      }
77  
78      public String getDefaultLocale() {
79          String xml = getContent();
80  
81          if (xml == null) {
82              return StringPool.BLANK;
83          }
84  
85          if (isTemplateDriven()) {
86              String defaultLanguageId = LocaleUtil.toLanguageId(
87                  LocaleUtil.getDefault());
88  
89              return defaultLanguageId;
90          }
91          else {
92              return LocalizationUtil.getDefaultLocale(xml);
93          }
94      }
95  
96      public boolean isTemplateDriven() {
97          if (Validator.isNull(getStructureId())) {
98              return false;
99          }
100         else {
101             return true;
102         }
103     }
104 
105     public String getApprovedByUserUuid() throws SystemException {
106         return PortalUtil.getUserValue(
107             getApprovedByUserId(), "uuid", _approvedByUserUuid);
108     }
109 
110     public void setApprovedByUserUuid(String approvedByUserUuid) {
111         _approvedByUserUuid = approvedByUserUuid;
112     }
113 
114     public String getSmallImageType() throws PortalException, SystemException {
115         if (_smallImageType == null && isSmallImage()) {
116             Image smallImage =  ImageLocalServiceUtil.getImage(
117                 getSmallImageId());
118 
119             _smallImageType = smallImage.getType();
120         }
121 
122         return _smallImageType;
123     }
124 
125     public void setSmallImageType(String smallImageType) {
126         _smallImageType = smallImageType;
127     }
128 
129     private String _userUuid;
130     private String _approvedByUserUuid;
131     private String _smallImageType;
132 
133 }