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