001
014
015 package com.liferay.portlet.journal.model.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.util.LocaleUtil;
020 import com.liferay.portal.kernel.util.LocalizationUtil;
021 import com.liferay.portal.kernel.util.StringPool;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portal.model.Image;
024 import com.liferay.portal.service.ImageLocalServiceUtil;
025 import com.liferay.portlet.journal.model.JournalArticleResource;
026 import com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil;
027 import com.liferay.portlet.journal.util.LocaleTransformerListener;
028
029 import java.util.Locale;
030 import java.util.Map;
031 import java.util.Set;
032 import java.util.TreeSet;
033
034
038 public class JournalArticleImpl extends JournalArticleBaseImpl {
039
040 public static String getContentByLocale(
041 String content, boolean templateDriven, String languageId) {
042
043 LocaleTransformerListener listener = new LocaleTransformerListener();
044
045 listener.setTemplateDriven(templateDriven);
046 listener.setLanguageId(languageId);
047
048 return listener.onXml(content);
049 }
050
051 public JournalArticleImpl() {
052 }
053
054 public JournalArticleResource getArticleResource()
055 throws PortalException, SystemException {
056
057 return JournalArticleResourceLocalServiceUtil.getArticleResource(
058 getResourcePrimKey());
059 }
060
061 public String getArticleResourceUuid()
062 throws PortalException, SystemException {
063
064 JournalArticleResource articleResource = getArticleResource();
065
066 return articleResource.getUuid();
067 }
068
069 public String[] getAvailableLocales() {
070 Set<String> availableLocales = new TreeSet<String>();
071
072
073
074 Map<Locale, String> titleMap = getTitleMap();
075
076 for (Map.Entry<Locale, String> entry : titleMap.entrySet()) {
077 Locale locale = entry.getKey();
078 String value = entry.getValue();
079
080 if (Validator.isNotNull(value)) {
081 availableLocales.add(locale.toString());
082 }
083 }
084
085
086
087 Map<Locale, String> descriptionMap = getDescriptionMap();
088
089 for (Map.Entry<Locale, String> entry : descriptionMap.entrySet()) {
090 Locale locale = entry.getKey();
091 String value = entry.getValue();
092
093 if (Validator.isNotNull(value)) {
094 availableLocales.add(locale.toString());
095 }
096 }
097
098
099
100 String[] availableLocalesArray = LocalizationUtil.getAvailableLocales(
101 getContent());
102
103 for (String availableLocale : availableLocalesArray) {
104 availableLocales.add(availableLocale);
105 }
106
107 return availableLocales.toArray(new String[availableLocales.size()]);
108 }
109
110 public String getContentByLocale(String languageId) {
111 return getContentByLocale(getContent(), isTemplateDriven(), languageId);
112 }
113
114 public String getDefaultLocale() {
115 String xml = getContent();
116
117 if (xml == null) {
118 return StringPool.BLANK;
119 }
120
121 String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);
122
123 if (isTemplateDriven() && Validator.isNull(defaultLanguageId)) {
124 defaultLanguageId = LocaleUtil.toLanguageId(
125 LocaleUtil.getDefault());
126 }
127
128 return defaultLanguageId;
129 }
130
131 public String getSmallImageType() throws PortalException, SystemException {
132 if ((_smallImageType == null) && isSmallImage()) {
133 Image smallImage = ImageLocalServiceUtil.getImage(
134 getSmallImageId());
135
136 _smallImageType = smallImage.getType();
137 }
138
139 return _smallImageType;
140 }
141
142 public boolean isTemplateDriven() {
143 if (Validator.isNull(getStructureId())) {
144 return false;
145 }
146 else {
147 return true;
148 }
149 }
150
151 public void setSmallImageType(String smallImageType) {
152 _smallImageType = smallImageType;
153 }
154
155 private String _smallImageType;
156
157 }