001
014
015 package com.liferay.portlet.blogs.action;
016
017 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018 import com.liferay.portal.kernel.servlet.SessionErrors;
019 import com.liferay.portal.kernel.servlet.SessionMessages;
020 import com.liferay.portal.kernel.util.Constants;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portlet.PortletPreferencesFactoryUtil;
024
025 import javax.portlet.ActionRequest;
026 import javax.portlet.ActionResponse;
027 import javax.portlet.PortletConfig;
028 import javax.portlet.PortletPreferences;
029 import javax.portlet.RenderRequest;
030 import javax.portlet.RenderResponse;
031
032
036 public class ConfigurationActionImpl extends BaseConfigurationAction {
037
038 public void processAction(
039 PortletConfig portletConfig, ActionRequest actionRequest,
040 ActionResponse actionResponse)
041 throws Exception {
042
043 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
044
045 if (!cmd.equals(Constants.UPDATE)) {
046 return;
047 }
048
049 String portletResource = ParamUtil.getString(
050 actionRequest, "portletResource");
051
052 PortletPreferences preferences =
053 PortletPreferencesFactoryUtil.getPortletSetup(
054 actionRequest, portletResource);
055
056 String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
057
058 if (tabs2.equals("display-settings")) {
059 updateDisplaySettings(actionRequest, preferences);
060 }
061 else if (tabs2.equals("email-from")) {
062 updateEmailFrom(actionRequest, preferences);
063 }
064 else if (tabs2.equals("entry-added-email")) {
065 updateEmailEntryAdded(actionRequest, preferences);
066 }
067 else if (tabs2.equals("entry-updated-email")) {
068 updateEmailEntryUpdated(actionRequest, preferences);
069 }
070 else if (tabs2.equals("rss")) {
071 updateRSS(actionRequest, preferences);
072 }
073
074 if (SessionErrors.isEmpty(actionRequest)) {
075 preferences.store();
076
077 SessionMessages.add(
078 actionRequest, portletConfig.getPortletName() + ".doConfigure");
079 }
080 }
081
082 public String render(
083 PortletConfig portletConfig, RenderRequest renderRequest,
084 RenderResponse renderResponse)
085 throws Exception {
086
087 return "/html/portlet/blogs/configuration.jsp";
088 }
089
090 protected void updateDisplaySettings(
091 ActionRequest actionRequest, PortletPreferences preferences)
092 throws Exception {
093
094 int pageDelta = ParamUtil.getInteger(actionRequest, "pageDelta");
095 String pageDisplayStyle = ParamUtil.getString(
096 actionRequest, "pageDisplayStyle");
097 boolean enableFlags = ParamUtil.getBoolean(
098 actionRequest, "enableFlags");
099 boolean enableRatings = ParamUtil.getBoolean(
100 actionRequest, "enableRatings");
101 boolean enableComments = ParamUtil.getBoolean(
102 actionRequest, "enableComments");
103 boolean enableCommentRatings = ParamUtil.getBoolean(
104 actionRequest, "enableCommentRatings");
105
106 preferences.setValue("page-delta", String.valueOf(pageDelta));
107 preferences.setValue("page-display-style", pageDisplayStyle);
108 preferences.setValue("enable-flags", String.valueOf(enableFlags));
109 preferences.setValue("enable-ratings", String.valueOf(enableRatings));
110 preferences.setValue("enable-comments", String.valueOf(enableComments));
111 preferences.setValue(
112 "enable-comment-ratings", String.valueOf(enableCommentRatings));
113 }
114
115 protected void updateEmailFrom(
116 ActionRequest actionRequest, PortletPreferences preferences)
117 throws Exception {
118
119 String emailFromName = ParamUtil.getString(
120 actionRequest, "emailFromName");
121 String emailFromAddress = ParamUtil.getString(
122 actionRequest, "emailFromAddress");
123
124 if (Validator.isNull(emailFromName)) {
125 SessionErrors.add(actionRequest, "emailFromName");
126 }
127 else if (!Validator.isEmailAddress(emailFromAddress) &&
128 !Validator.isVariableTerm(emailFromAddress)) {
129
130 SessionErrors.add(actionRequest, "emailFromAddress");
131 }
132 else {
133 preferences.setValue("email-from-name", emailFromName);
134 preferences.setValue("email-from-address", emailFromAddress);
135 }
136 }
137
138 protected void updateEmailEntryAdded(
139 ActionRequest actionRequest, PortletPreferences preferences)
140 throws Exception {
141
142 boolean emailEntryAddedEnabled = ParamUtil.getBoolean(
143 actionRequest, "emailEntryAddedEnabled");
144 String emailEntryAddedSubject = ParamUtil.getString(
145 actionRequest, "emailEntryAddedSubject");
146 String emailEntryAddedBody = ParamUtil.getString(
147 actionRequest, "emailEntryAddedBody");
148
149 if (Validator.isNull(emailEntryAddedSubject)) {
150 SessionErrors.add(actionRequest, "emailEntryAddedSubject");
151 }
152 else if (Validator.isNull(emailEntryAddedBody)) {
153 SessionErrors.add(actionRequest, "emailEntryAddedBody");
154 }
155 else {
156 preferences.setValue(
157 "email-entry-added-enabled",
158 String.valueOf(emailEntryAddedEnabled));
159 preferences.setValue(
160 "email-entry-added-subject", emailEntryAddedSubject);
161 preferences.setValue("email-entry-added-body", emailEntryAddedBody);
162 }
163 }
164
165 protected void updateEmailEntryUpdated(
166 ActionRequest actionRequest, PortletPreferences preferences)
167 throws Exception {
168
169 boolean emailEntryUpdatedEnabled = ParamUtil.getBoolean(
170 actionRequest, "emailEntryUpdatedEnabled");
171 String emailEntryUpdatedSubject = ParamUtil.getString(
172 actionRequest, "emailEntryUpdatedSubject");
173 String emailEntryUpdatedBody = ParamUtil.getString(
174 actionRequest, "emailEntryUpdatedBody");
175
176 if (Validator.isNull(emailEntryUpdatedSubject)) {
177 SessionErrors.add(actionRequest, "emailEntryUpdatedSubject");
178 }
179 else if (Validator.isNull(emailEntryUpdatedBody)) {
180 SessionErrors.add(actionRequest, "emailEntryUpdatedBody");
181 }
182 else {
183 preferences.setValue(
184 "email-entry-updated-enabled",
185 String.valueOf(emailEntryUpdatedEnabled));
186 preferences.setValue(
187 "email-entry-updated-subject", emailEntryUpdatedSubject);
188 preferences.setValue(
189 "email-entry-updated-body", emailEntryUpdatedBody);
190 }
191 }
192
193 protected void updateRSS(
194 ActionRequest actionRequest, PortletPreferences preferences)
195 throws Exception {
196
197 int rssDelta = ParamUtil.getInteger(actionRequest, "rssDelta");
198 String rssDisplayStyle = ParamUtil.getString(
199 actionRequest, "rssDisplayStyle");
200 String rssFormat = ParamUtil.getString(actionRequest, "rssFormat");
201
202 preferences.setValue("rss-delta", String.valueOf(rssDelta));
203 preferences.setValue("rss-display-style", rssDisplayStyle);
204 preferences.setValue("rss-format", rssFormat);
205 }
206
207 }