001
014
015 package com.liferay.portlet.blogs.util;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018 import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.LocaleUtil;
021 import com.liferay.portal.kernel.util.LocalizationUtil;
022 import com.liferay.portal.kernel.util.PropsKeys;
023 import com.liferay.portal.kernel.util.StringPool;
024 import com.liferay.portal.kernel.util.Validator;
025 import com.liferay.portal.model.ModelHintsUtil;
026 import com.liferay.portal.util.PortalUtil;
027 import com.liferay.portal.util.PropsUtil;
028 import com.liferay.portal.util.PropsValues;
029 import com.liferay.portlet.blogs.model.BlogsEntry;
030 import com.liferay.util.ContentUtil;
031
032 import java.util.Locale;
033 import java.util.Map;
034
035 import javax.portlet.PortletPreferences;
036
037
041 public class BlogsUtil {
042
043 public static Map<Locale, String> getEmailEntryAddedBodyMap(
044 PortletPreferences preferences) {
045
046 Map<Locale, String> map = LocalizationUtil.getLocalizationMap(
047 preferences, "emailEntryAddedBody");
048
049 Locale defaultLocale = LocaleUtil.getDefault();
050
051 String defaultValue = map.get(defaultLocale);
052
053 if (Validator.isNotNull(defaultValue)) {
054 return map;
055 }
056
057 map.put(
058 defaultLocale,
059 ContentUtil.get(
060 PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_BODY)));
061
062 return map;
063 }
064
065 public static boolean getEmailEntryAddedEnabled(
066 PortletPreferences preferences) {
067
068 String emailEntryAddedEnabled = preferences.getValue(
069 "emailEntryAddedEnabled", StringPool.BLANK);
070
071 if (Validator.isNotNull(emailEntryAddedEnabled)) {
072 return GetterUtil.getBoolean(emailEntryAddedEnabled);
073 }
074 else {
075 return GetterUtil.getBoolean(
076 PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_ENABLED));
077 }
078 }
079
080 public static Map<Locale, String> getEmailEntryAddedSubjectMap(
081 PortletPreferences preferences) {
082
083 Map<Locale, String> map = LocalizationUtil.getLocalizationMap(
084 preferences, "emailEntryAddedSubject");
085
086 Locale defaultLocale = LocaleUtil.getDefault();
087
088 String defaultValue = map.get(defaultLocale);
089
090 if (Validator.isNotNull(defaultValue)) {
091 return map;
092 }
093
094 map.put(
095 defaultLocale,
096 ContentUtil.get(
097 PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_SUBJECT)));
098
099 return map;
100 }
101
102 public static Map<Locale, String> getEmailEntryUpdatedBodyMap(
103 PortletPreferences preferences) {
104
105 Map<Locale, String> map = LocalizationUtil.getLocalizationMap(
106 preferences, "emailEntryUpdatedBody");
107
108 Locale defaultLocale = LocaleUtil.getDefault();
109
110 String defaultValue = map.get(defaultLocale);
111
112 if (Validator.isNotNull(defaultValue)) {
113 return map;
114 }
115
116 map.put(
117 defaultLocale,
118 ContentUtil.get(
119 PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_BODY)));
120
121 return map;
122 }
123
124 public static boolean getEmailEntryUpdatedEnabled(
125 PortletPreferences preferences) {
126
127 String emailEntryUpdatedEnabled = preferences.getValue(
128 "emailEntryUpdatedEnabled", StringPool.BLANK);
129
130 if (Validator.isNotNull(emailEntryUpdatedEnabled)) {
131 return GetterUtil.getBoolean(emailEntryUpdatedEnabled);
132 }
133 else {
134 return GetterUtil.getBoolean(
135 PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_ENABLED));
136 }
137 }
138
139 public static Map<Locale, String> getEmailEntryUpdatedSubjectMap(
140 PortletPreferences preferences) {
141
142 Map<Locale, String> map = LocalizationUtil.getLocalizationMap(
143 preferences, "emailEntryUpdatedSubject");
144
145 Locale defaultLocale = LocaleUtil.getDefault();
146
147 String defaultValue = map.get(defaultLocale);
148
149 if (Validator.isNotNull(defaultValue)) {
150 return map;
151 }
152
153 map.put(
154 defaultLocale,
155 ContentUtil.get(
156 PropsUtil.get(PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_SUBJECT)));
157
158 return map;
159 }
160
161 public static String getEmailFromAddress(
162 PortletPreferences preferences, long companyId)
163 throws SystemException {
164
165 return PortalUtil.getEmailFromAddress(
166 preferences, companyId, PropsValues.BLOGS_EMAIL_FROM_ADDRESS);
167 }
168
169 public static String getEmailFromName(
170 PortletPreferences preferences, long companyId)
171 throws SystemException {
172
173 return PortalUtil.getEmailFromName(
174 preferences, companyId, PropsValues.BLOGS_EMAIL_FROM_NAME);
175 }
176
177 public static String getUrlTitle(long entryId, String title) {
178 if (title == null) {
179 return String.valueOf(entryId);
180 }
181
182 title = title.trim().toLowerCase();
183
184 if (Validator.isNull(title) || Validator.isNumber(title) ||
185 title.equals("rss")) {
186
187 title = String.valueOf(entryId);
188 }
189 else {
190 title = FriendlyURLNormalizerUtil.normalize(
191 title, _URL_TITLE_REPLACE_CHARS);
192 }
193
194 return ModelHintsUtil.trimString(
195 BlogsEntry.class.getName(), "urlTitle", title);
196 }
197
198 private static final char[] _URL_TITLE_REPLACE_CHARS = new char[] {
199 '.', '/'
200 };
201
202 }