1
22
23 package com.liferay.portlet.blogs.util;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.PropsKeys;
27 import com.liferay.portal.kernel.util.StringPool;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.util.ContentUtil;
30 import com.liferay.portal.util.FriendlyURLNormalizer;
31 import com.liferay.portal.util.PropsUtil;
32 import com.liferay.portal.util.PropsValues;
33
34 import javax.portlet.PortletPreferences;
35
36
42 public class BlogsUtil {
43
44 public static final String POP_PORTLET_PREFIX = "blogs.";
45
46 public static String getEmailEntryAddedBody(
47 PortletPreferences preferences) {
48
49 String emailEntryAddedBody = preferences.getValue(
50 "email-entry-added-body", StringPool.BLANK);
51
52 if (Validator.isNotNull(emailEntryAddedBody)) {
53 return emailEntryAddedBody;
54 }
55 else {
56 return ContentUtil.get(PropsUtil.get(
57 PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_BODY));
58 }
59 }
60
61 public static boolean getEmailEntryAddedEnabled(
62 PortletPreferences preferences) {
63
64 String emailEntryAddedEnabled = preferences.getValue(
65 "email-entry-added-enabled", StringPool.BLANK);
66
67 if (Validator.isNotNull(emailEntryAddedEnabled)) {
68 return GetterUtil.getBoolean(emailEntryAddedEnabled);
69 }
70 else {
71 return GetterUtil.getBoolean(PropsUtil.get(
72 PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_ENABLED));
73 }
74 }
75
76 public static String getEmailEntryAddedSubject(
77 PortletPreferences preferences) {
78
79 String emailEntryAddedSubject = preferences.getValue(
80 "email-entry-added-subject", StringPool.BLANK);
81
82 if (Validator.isNotNull(emailEntryAddedSubject)) {
83 return emailEntryAddedSubject;
84 }
85 else {
86 return ContentUtil.get(PropsUtil.get(
87 PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_SUBJECT));
88 }
89 }
90
91 public static String getEmailEntryUpdatedBody(
92 PortletPreferences preferences) {
93
94 String emailEntryUpdatedBody = preferences.getValue(
95 "email-entry-updated-body", StringPool.BLANK);
96
97 if (Validator.isNotNull(emailEntryUpdatedBody)) {
98 return emailEntryUpdatedBody;
99 }
100 else {
101 return ContentUtil.get(PropsUtil.get(
102 PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_BODY));
103 }
104 }
105
106 public static boolean getEmailEntryUpdatedEnabled(
107 PortletPreferences preferences) {
108
109 String emailEntryUpdatedEnabled = preferences.getValue(
110 "email-entry-updated-enabled", StringPool.BLANK);
111
112 if (Validator.isNotNull(emailEntryUpdatedEnabled)) {
113 return GetterUtil.getBoolean(emailEntryUpdatedEnabled);
114 }
115 else {
116 return GetterUtil.getBoolean(PropsUtil.get(
117 PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_ENABLED));
118 }
119 }
120
121 public static String getEmailEntryUpdatedSubject(
122 PortletPreferences preferences) {
123
124 String emailEntryUpdatedSubject = preferences.getValue(
125 "email-entry-updated-subject", StringPool.BLANK);
126
127 if (Validator.isNotNull(emailEntryUpdatedSubject)) {
128 return emailEntryUpdatedSubject;
129 }
130 else {
131 return ContentUtil.get(PropsUtil.get(
132 PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_SUBJECT));
133 }
134 }
135
136 public static String getEmailFromAddress(PortletPreferences preferences) {
137 String emailFromAddress = PropsUtil.get(
138 PropsKeys.BLOGS_EMAIL_FROM_ADDRESS);
139
140 return preferences.getValue("email-from-address", emailFromAddress);
141 }
142
143 public static String getEmailFromName(PortletPreferences preferences) {
144 String emailFromName = PropsUtil.get(PropsKeys.BLOGS_EMAIL_FROM_NAME);
145
146 return preferences.getValue("email-from-name", emailFromName);
147 }
148
149 public static String getMailId(String mx, long entryId) {
150 StringBuilder sb = new StringBuilder();
151
152 sb.append(StringPool.LESS_THAN);
153 sb.append(POP_PORTLET_PREFIX);
154 sb.append(entryId);
155 sb.append(StringPool.AT);
156 sb.append(PropsValues.POP_SERVER_SUBDOMAIN);
157 sb.append(StringPool.PERIOD);
158 sb.append(mx);
159 sb.append(StringPool.GREATER_THAN);
160
161 return sb.toString();
162 }
163
164 public static String getUrlTitle(long entryId, String title) {
165 title = title.trim().toLowerCase();
166
167 if (Validator.isNull(title) || Validator.isNumber(title) ||
168 title.equals("rss")) {
169
170 return String.valueOf(entryId);
171 }
172 else {
173 return FriendlyURLNormalizer.normalize(
174 title, _URL_TITLE_REPLACE_CHARS);
175 }
176 }
177
178 private static final char[] _URL_TITLE_REPLACE_CHARS = new char[] {
179 '.', '/'
180 };
181
182 }