001
014
015 package com.liferay.portlet.blogs.util;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018 import com.liferay.portal.kernel.util.PropsKeys;
019 import com.liferay.portal.kernel.util.StringBundler;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.kernel.util.Validator;
022 import com.liferay.portal.util.ContentUtil;
023 import com.liferay.portal.util.FriendlyURLNormalizer;
024 import com.liferay.portal.util.PropsUtil;
025 import com.liferay.portal.util.PropsValues;
026
027 import javax.portlet.PortletPreferences;
028
029
033 public class BlogsUtil {
034
035 public static final String POP_PORTLET_PREFIX = "blogs.";
036
037 public static String getEmailEntryAddedBody(
038 PortletPreferences preferences) {
039
040 String emailEntryAddedBody = preferences.getValue(
041 "email-entry-added-body", StringPool.BLANK);
042
043 if (Validator.isNotNull(emailEntryAddedBody)) {
044 return emailEntryAddedBody;
045 }
046 else {
047 return ContentUtil.get(PropsUtil.get(
048 PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_BODY));
049 }
050 }
051
052 public static boolean getEmailEntryAddedEnabled(
053 PortletPreferences preferences) {
054
055 String emailEntryAddedEnabled = preferences.getValue(
056 "email-entry-added-enabled", StringPool.BLANK);
057
058 if (Validator.isNotNull(emailEntryAddedEnabled)) {
059 return GetterUtil.getBoolean(emailEntryAddedEnabled);
060 }
061 else {
062 return GetterUtil.getBoolean(PropsUtil.get(
063 PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_ENABLED));
064 }
065 }
066
067 public static String getEmailEntryAddedSubject(
068 PortletPreferences preferences) {
069
070 String emailEntryAddedSubject = preferences.getValue(
071 "email-entry-added-subject", StringPool.BLANK);
072
073 if (Validator.isNotNull(emailEntryAddedSubject)) {
074 return emailEntryAddedSubject;
075 }
076 else {
077 return ContentUtil.get(PropsUtil.get(
078 PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_SUBJECT));
079 }
080 }
081
082 public static String getEmailEntryUpdatedBody(
083 PortletPreferences preferences) {
084
085 String emailEntryUpdatedBody = preferences.getValue(
086 "email-entry-updated-body", StringPool.BLANK);
087
088 if (Validator.isNotNull(emailEntryUpdatedBody)) {
089 return emailEntryUpdatedBody;
090 }
091 else {
092 return ContentUtil.get(PropsUtil.get(
093 PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_BODY));
094 }
095 }
096
097 public static boolean getEmailEntryUpdatedEnabled(
098 PortletPreferences preferences) {
099
100 String emailEntryUpdatedEnabled = preferences.getValue(
101 "email-entry-updated-enabled", StringPool.BLANK);
102
103 if (Validator.isNotNull(emailEntryUpdatedEnabled)) {
104 return GetterUtil.getBoolean(emailEntryUpdatedEnabled);
105 }
106 else {
107 return GetterUtil.getBoolean(PropsUtil.get(
108 PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_ENABLED));
109 }
110 }
111
112 public static String getEmailEntryUpdatedSubject(
113 PortletPreferences preferences) {
114
115 String emailEntryUpdatedSubject = preferences.getValue(
116 "email-entry-updated-subject", StringPool.BLANK);
117
118 if (Validator.isNotNull(emailEntryUpdatedSubject)) {
119 return emailEntryUpdatedSubject;
120 }
121 else {
122 return ContentUtil.get(PropsUtil.get(
123 PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_SUBJECT));
124 }
125 }
126
127 public static String getEmailFromAddress(PortletPreferences preferences) {
128 String emailFromAddress = PropsUtil.get(
129 PropsKeys.BLOGS_EMAIL_FROM_ADDRESS);
130
131 return preferences.getValue("email-from-address", emailFromAddress);
132 }
133
134 public static String getEmailFromName(PortletPreferences preferences) {
135 String emailFromName = PropsUtil.get(PropsKeys.BLOGS_EMAIL_FROM_NAME);
136
137 return preferences.getValue("email-from-name", emailFromName);
138 }
139
140 public static String getMailId(String mx, long entryId) {
141 StringBundler sb = new StringBundler(8);
142
143 sb.append(StringPool.LESS_THAN);
144 sb.append(POP_PORTLET_PREFIX);
145 sb.append(entryId);
146 sb.append(StringPool.AT);
147 sb.append(PropsValues.POP_SERVER_SUBDOMAIN);
148 sb.append(StringPool.PERIOD);
149 sb.append(mx);
150 sb.append(StringPool.GREATER_THAN);
151
152 return sb.toString();
153 }
154
155 public static String getUrlTitle(long entryId, String title) {
156 title = title.trim().toLowerCase();
157
158 if (Validator.isNull(title) || Validator.isNumber(title) ||
159 title.equals("rss")) {
160
161 return String.valueOf(entryId);
162 }
163 else {
164 return FriendlyURLNormalizer.normalize(
165 title, _URL_TITLE_REPLACE_CHARS);
166 }
167 }
168
169 private static final char[] _URL_TITLE_REPLACE_CHARS = new char[] {
170 '.', '/'
171 };
172
173 }