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.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
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 String getUserUuid() throws SystemException {
125 return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
126 }
127
128 public boolean isTemplateDriven() {
129 if (Validator.isNull(getStructureId())) {
130 return false;
131 }
132 else {
133 return true;
134 }
135 }
136
137 public void setApprovedByUserUuid(String approvedByUserUuid) {
138 _approvedByUserUuid = approvedByUserUuid;
139 }
140
141 public void setSmallImageType(String smallImageType) {
142 _smallImageType = smallImageType;
143 }
144
145 public void setUserUuid(String userUuid) {
146 _userUuid = userUuid;
147 }
148
149 private String _approvedByUserUuid;
150 private ExpandoBridge _expandoBridge;
151 private String _smallImageType;
152 private String _userUuid;
153
154 }