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.PropsKeys;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.kernel.util.Validator;
31 import com.liferay.portal.model.Image;
32 import com.liferay.portal.service.ImageLocalServiceUtil;
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 PORTLET = "portlet";
50
51 public static final String STAND_ALONE = "stand-alone";
52
53 public static final String[] TYPES =
54 PropsUtil.getArray(PropsKeys.JOURNAL_ARTICLE_TYPES);
55
56 public static String getContentByLocale(
57 String content, boolean templateDriven, String languageId) {
58
59 LocaleTransformerListener listener = new LocaleTransformerListener();
60
61 listener.setTemplateDriven(templateDriven);
62 listener.setLanguageId(languageId);
63
64 return listener.onXml(content);
65 }
66
67 public JournalArticleImpl() {
68 }
69
70 public String[] getAvailableLocales() {
71 return LocalizationUtil.getAvailableLocales(getContent());
72 }
73
74 public String getContentByLocale(String languageId) {
75 return getContentByLocale(getContent(), isTemplateDriven(), languageId);
76 }
77
78 public String getDefaultLocale() {
79 String xml = getContent();
80
81 if (xml == null) {
82 return StringPool.BLANK;
83 }
84
85 String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
86
87 if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
88 defaultLanguageId = LocaleUtil.toLanguageId(
89 LocaleUtil.getDefault());
90 }
91
92 return defaultLanguageId;
93 }
94
95 public String getSmallImageType() throws PortalException, SystemException {
96 if (_smallImageType == null && isSmallImage()) {
97 Image smallImage = ImageLocalServiceUtil.getImage(
98 getSmallImageId());
99
100 _smallImageType = smallImage.getType();
101 }
102
103 return _smallImageType;
104 }
105
106 public boolean isTemplateDriven() {
107 if (Validator.isNull(getStructureId())) {
108 return false;
109 }
110 else {
111 return true;
112 }
113 }
114
115 public void setSmallImageType(String smallImageType) {
116 _smallImageType = smallImageType;
117 }
118
119 private String _smallImageType;
120
121 }