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