1
14
15 package com.liferay.portlet.blogs.action;
16
17 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18 import com.liferay.portal.kernel.servlet.SessionErrors;
19 import com.liferay.portal.kernel.servlet.SessionMessages;
20 import com.liferay.portal.kernel.util.Constants;
21 import com.liferay.portal.kernel.util.ParamUtil;
22 import com.liferay.portal.kernel.util.Validator;
23 import com.liferay.portlet.PortletPreferencesFactoryUtil;
24
25 import javax.portlet.ActionRequest;
26 import javax.portlet.ActionResponse;
27 import javax.portlet.PortletConfig;
28 import javax.portlet.PortletPreferences;
29 import javax.portlet.RenderRequest;
30 import javax.portlet.RenderResponse;
31
32
38 public class ConfigurationActionImpl extends BaseConfigurationAction {
39
40 public void processAction(
41 PortletConfig portletConfig, ActionRequest actionRequest,
42 ActionResponse actionResponse)
43 throws Exception {
44
45 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
46
47 if (!cmd.equals(Constants.UPDATE)) {
48 return;
49 }
50
51 String portletResource = ParamUtil.getString(
52 actionRequest, "portletResource");
53
54 PortletPreferences preferences =
55 PortletPreferencesFactoryUtil.getPortletSetup(
56 actionRequest, portletResource);
57
58 String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
59
60 if (tabs2.equals("display-settings")) {
61 updateDisplaySettings(actionRequest, preferences);
62 }
63 else if (tabs2.equals("email-from")) {
64 updateEmailFrom(actionRequest, preferences);
65 }
66 else if (tabs2.equals("entry-added-email")) {
67 updateEmailEntryAdded(actionRequest, preferences);
68 }
69 else if (tabs2.equals("entry-updated-email")) {
70 updateEmailEntryUpdated(actionRequest, preferences);
71 }
72 else if (tabs2.equals("rss")) {
73 updateRSS(actionRequest, preferences);
74 }
75
76 if (SessionErrors.isEmpty(actionRequest)) {
77 preferences.store();
78
79 SessionMessages.add(
80 actionRequest, portletConfig.getPortletName() + ".doConfigure");
81 }
82 }
83
84 public String render(
85 PortletConfig portletConfig, RenderRequest renderRequest,
86 RenderResponse renderResponse)
87 throws Exception {
88
89 return "/html/portlet/blogs/configuration.jsp";
90 }
91
92 protected void updateDisplaySettings(
93 ActionRequest actionRequest, PortletPreferences preferences)
94 throws Exception {
95
96 int pageDelta = ParamUtil.getInteger(actionRequest, "pageDelta");
97 String pageDisplayStyle = ParamUtil.getString(
98 actionRequest, "pageDisplayStyle");
99 boolean enableFlags = ParamUtil.getBoolean(
100 actionRequest, "enableFlags");
101 boolean enableRatings = ParamUtil.getBoolean(
102 actionRequest, "enableRatings");
103 boolean enableComments = ParamUtil.getBoolean(
104 actionRequest, "enableComments");
105 boolean enableCommentRatings = ParamUtil.getBoolean(
106 actionRequest, "enableCommentRatings");
107
108 preferences.setValue("page-delta", String.valueOf(pageDelta));
109 preferences.setValue("page-display-style", pageDisplayStyle);
110 preferences.setValue("enable-flags", String.valueOf(enableFlags));
111 preferences.setValue("enable-ratings", String.valueOf(enableRatings));
112 preferences.setValue("enable-comments", String.valueOf(enableComments));
113 preferences.setValue(
114 "enable-comment-ratings", String.valueOf(enableCommentRatings));
115 }
116
117 protected void updateEmailFrom(
118 ActionRequest actionRequest, PortletPreferences preferences)
119 throws Exception {
120
121 String emailFromName = ParamUtil.getString(
122 actionRequest, "emailFromName");
123 String emailFromAddress = ParamUtil.getString(
124 actionRequest, "emailFromAddress");
125
126 if (Validator.isNull(emailFromName)) {
127 SessionErrors.add(actionRequest, "emailFromName");
128 }
129 else if (!Validator.isEmailAddress(emailFromAddress) &&
130 !Validator.isVariableTerm(emailFromAddress)) {
131
132 SessionErrors.add(actionRequest, "emailFromAddress");
133 }
134 else {
135 preferences.setValue("email-from-name", emailFromName);
136 preferences.setValue("email-from-address", emailFromAddress);
137 }
138 }
139
140 protected void updateEmailEntryAdded(
141 ActionRequest actionRequest, PortletPreferences preferences)
142 throws Exception {
143
144 boolean emailEntryAddedEnabled = ParamUtil.getBoolean(
145 actionRequest, "emailEntryAddedEnabled");
146 String emailEntryAddedSubject = ParamUtil.getString(
147 actionRequest, "emailEntryAddedSubject");
148 String emailEntryAddedBody = ParamUtil.getString(
149 actionRequest, "emailEntryAddedBody");
150
151 if (Validator.isNull(emailEntryAddedSubject)) {
152 SessionErrors.add(actionRequest, "emailEntryAddedSubject");
153 }
154 else if (Validator.isNull(emailEntryAddedBody)) {
155 SessionErrors.add(actionRequest, "emailEntryAddedBody");
156 }
157 else {
158 preferences.setValue(
159 "email-entry-added-enabled",
160 String.valueOf(emailEntryAddedEnabled));
161 preferences.setValue(
162 "email-entry-added-subject", emailEntryAddedSubject);
163 preferences.setValue("email-entry-added-body", emailEntryAddedBody);
164 }
165 }
166
167 protected void updateEmailEntryUpdated(
168 ActionRequest actionRequest, PortletPreferences preferences)
169 throws Exception {
170
171 boolean emailEntryUpdatedEnabled = ParamUtil.getBoolean(
172 actionRequest, "emailEntryUpdatedEnabled");
173 String emailEntryUpdatedSubject = ParamUtil.getString(
174 actionRequest, "emailEntryUpdatedSubject");
175 String emailEntryUpdatedBody = ParamUtil.getString(
176 actionRequest, "emailEntryUpdatedBody");
177
178 if (Validator.isNull(emailEntryUpdatedSubject)) {
179 SessionErrors.add(actionRequest, "emailEntryUpdatedSubject");
180 }
181 else if (Validator.isNull(emailEntryUpdatedBody)) {
182 SessionErrors.add(actionRequest, "emailEntryUpdatedBody");
183 }
184 else {
185 preferences.setValue(
186 "email-entry-updated-enabled",
187 String.valueOf(emailEntryUpdatedEnabled));
188 preferences.setValue(
189 "email-entry-updated-subject", emailEntryUpdatedSubject);
190 preferences.setValue(
191 "email-entry-updated-body", emailEntryUpdatedBody);
192 }
193 }
194
195 protected void updateRSS(
196 ActionRequest actionRequest, PortletPreferences preferences)
197 throws Exception {
198
199 int rssDelta = ParamUtil.getInteger(actionRequest, "rssDelta");
200 String rssDisplayStyle = ParamUtil.getString(
201 actionRequest, "rssDisplayStyle");
202 String rssFormat = ParamUtil.getString(actionRequest, "rssFormat");
203
204 preferences.setValue("rss-delta", String.valueOf(rssDelta));
205 preferences.setValue("rss-display-style", rssDisplayStyle);
206 preferences.setValue("rss-format", rssFormat);
207 }
208
209 }