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.PropsKeys;
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 JournalArticleImpl() {
57 }
58
59 public String[] getAvailableLocales() {
60 return LocalizationUtil.getAvailableLocales(getContent());
61 }
62
63 public String getContentByLocale(String languageId) {
64 LocaleTransformerListener listener = new LocaleTransformerListener();
65
66 listener.setTemplateDriven(isTemplateDriven());
67 listener.setLanguageId(languageId);
68
69 return listener.onXml(getContent());
70 }
71
72 public String getDefaultLocale() {
73 String xml = getContent();
74
75 if (xml == null) {
76 return StringPool.BLANK;
77 }
78
79 String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
80
81 if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
82 defaultLanguageId = LocaleUtil.toLanguageId(
83 LocaleUtil.getDefault());
84 }
85
86 return defaultLanguageId;
87 }
88
89 public String getSmallImageType() throws PortalException, SystemException {
90 if (_smallImageType == null && isSmallImage()) {
91 Image smallImage = ImageLocalServiceUtil.getImage(
92 getSmallImageId());
93
94 _smallImageType = smallImage.getType();
95 }
96
97 return _smallImageType;
98 }
99
100 public boolean isTemplateDriven() {
101 if (Validator.isNull(getStructureId())) {
102 return false;
103 }
104 else {
105 return true;
106 }
107 }
108
109 public void setSmallImageType(String smallImageType) {
110 _smallImageType = smallImageType;
111 }
112
113 private String _smallImageType;
114
115 }