1
14
15 package com.liferay.portlet.journal.model.impl;
16
17 import com.liferay.portal.PortalException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.kernel.util.LocaleUtil;
20 import com.liferay.portal.kernel.util.LocalizationUtil;
21 import com.liferay.portal.kernel.util.PropsKeys;
22 import com.liferay.portal.kernel.util.StringPool;
23 import com.liferay.portal.kernel.util.Validator;
24 import com.liferay.portal.model.Image;
25 import com.liferay.portal.service.ImageLocalServiceUtil;
26 import com.liferay.portal.util.PropsUtil;
27 import com.liferay.portlet.journal.model.JournalArticle;
28 import com.liferay.portlet.journal.util.LocaleTransformerListener;
29
30
36 public class JournalArticleImpl
37 extends JournalArticleModelImpl implements JournalArticle {
38
39 public static final double DEFAULT_VERSION = 1.0;
40
41 public static final String PORTLET = "portlet";
42
43 public static final String STAND_ALONE = "stand-alone";
44
45 public static final String[] TYPES =
46 PropsUtil.getArray(PropsKeys.JOURNAL_ARTICLE_TYPES);
47
48 public static String getContentByLocale(
49 String content, boolean templateDriven, String languageId) {
50
51 LocaleTransformerListener listener = new LocaleTransformerListener();
52
53 listener.setTemplateDriven(templateDriven);
54 listener.setLanguageId(languageId);
55
56 return listener.onXml(content);
57 }
58
59 public JournalArticleImpl() {
60 }
61
62 public String[] getAvailableLocales() {
63 return LocalizationUtil.getAvailableLocales(getContent());
64 }
65
66 public String getContentByLocale(String languageId) {
67 return getContentByLocale(getContent(), isTemplateDriven(), languageId);
68 }
69
70 public String getDefaultLocale() {
71 String xml = getContent();
72
73 if (xml == null) {
74 return StringPool.BLANK;
75 }
76
77 String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
78
79 if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
80 defaultLanguageId = LocaleUtil.toLanguageId(
81 LocaleUtil.getDefault());
82 }
83
84 return defaultLanguageId;
85 }
86
87 public String getSmallImageType() throws PortalException, SystemException {
88 if (_smallImageType == null && isSmallImage()) {
89 Image smallImage = ImageLocalServiceUtil.getImage(
90 getSmallImageId());
91
92 _smallImageType = smallImage.getType();
93 }
94
95 return _smallImageType;
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 void setSmallImageType(String smallImageType) {
108 _smallImageType = smallImageType;
109 }
110
111 private String _smallImageType;
112
113 }