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