1
14
15 package com.liferay.portlet.journal.model.impl;
16
17 import com.liferay.portal.kernel.exception.PortalException;
18 import com.liferay.portal.kernel.exception.SystemException;
19 import com.liferay.portal.kernel.util.LocaleUtil;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.kernel.util.Validator;
22 import com.liferay.portal.kernel.workflow.StatusConstants;
23 import com.liferay.portal.model.Image;
24 import com.liferay.portal.service.ImageLocalServiceUtil;
25 import com.liferay.portlet.journal.model.JournalArticle;
26 import com.liferay.portlet.journal.util.LocaleTransformerListener;
27 import com.liferay.util.LocalizationUtil;
28
29
35 public class JournalArticleImpl
36 extends JournalArticleModelImpl implements JournalArticle {
37
38 public static String getContentByLocale(
39 String content, boolean templateDriven, String languageId) {
40
41 LocaleTransformerListener listener = new LocaleTransformerListener();
42
43 listener.setTemplateDriven(templateDriven);
44 listener.setLanguageId(languageId);
45
46 return listener.onXml(content);
47 }
48
49 public JournalArticleImpl() {
50 }
51
52 public String[] getAvailableLocales() {
53 return LocalizationUtil.getAvailableLocales(getContent());
54 }
55
56 public String getContentByLocale(String languageId) {
57 return getContentByLocale(getContent(), isTemplateDriven(), languageId);
58 }
59
60 public String getDefaultLocale() {
61 String xml = getContent();
62
63 if (xml == null) {
64 return StringPool.BLANK;
65 }
66
67 String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
68
69 if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
70 defaultLanguageId = LocaleUtil.toLanguageId(
71 LocaleUtil.getDefault());
72 }
73
74 return defaultLanguageId;
75 }
76
77 public String getSmallImageType() throws PortalException, SystemException {
78 if (_smallImageType == null && isSmallImage()) {
79 Image smallImage = ImageLocalServiceUtil.getImage(
80 getSmallImageId());
81
82 _smallImageType = smallImage.getType();
83 }
84
85 return _smallImageType;
86 }
87
88 public boolean isApproved() {
89 if (getStatus() == StatusConstants.APPROVED) {
90 return true;
91 }
92 else {
93 return false;
94 }
95 }
96
97 public boolean isExpired() {
98 if (getStatus() == StatusConstants.EXPIRED) {
99 return true;
100 }
101 else {
102 return false;
103 }
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 }