1
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.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
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[] TYPES =
50 PropsUtil.getArray(PropsUtil.JOURNAL_ARTICLE_TYPES);
51
52 public static final String PORTLET = "portlet";
53
54 public static final String STAND_ALONE = "stand-alone";
55
56 public JournalArticleImpl() {
57 }
58
59 public String getUserUuid() throws SystemException {
60 return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
61 }
62
63 public void setUserUuid(String userUuid) {
64 _userUuid = userUuid;
65 }
66
67 public String[] getAvailableLocales() {
68 return LocalizationUtil.getAvailableLocales(getContent());
69 }
70
71 public String getContentByLocale(String languageId){
72 LocaleTransformerListener listener = new LocaleTransformerListener();
73
74 listener.setTemplateDriven(isTemplateDriven());
75 listener.setLanguageId(languageId);
76
77 return listener.onXml(getContent());
78 }
79
80 public String getDefaultLocale() {
81 String xml = getContent();
82
83 if (xml == null) {
84 return StringPool.BLANK;
85 }
86
87 if (isTemplateDriven()) {
88 String defaultLanguageId = LocaleUtil.toLanguageId(
89 LocaleUtil.getDefault());
90
91 return defaultLanguageId;
92 }
93 else {
94 return LocalizationUtil.getDefaultLocale(xml);
95 }
96 }
97
98 public boolean isTemplateDriven() {
99 if (Validator.isNull(getStructureId())) {
100 return false;
101 }
102 else {
103 return true;
104 }
105 }
106
107 public String getApprovedByUserUuid() throws SystemException {
108 return PortalUtil.getUserValue(
109 getApprovedByUserId(), "uuid", _approvedByUserUuid);
110 }
111
112 public void setApprovedByUserUuid(String approvedByUserUuid) {
113 _approvedByUserUuid = approvedByUserUuid;
114 }
115
116 public String getSmallImageType() throws PortalException, SystemException {
117 if (_smallImageType == null && isSmallImage()) {
118 Image smallImage = ImageLocalServiceUtil.getImage(
119 getSmallImageId());
120
121 _smallImageType = smallImage.getType();
122 }
123
124 return _smallImageType;
125 }
126
127 public void setSmallImageType(String smallImageType) {
128 _smallImageType = smallImageType;
129 }
130
131 private String _userUuid;
132 private String _approvedByUserUuid;
133 private String _smallImageType;
134
135 }