001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.journal.action;
022:
023: import com.liferay.portal.kernel.portlet.ConfigurationAction;
024: import com.liferay.portal.kernel.util.Constants;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portlet.PortletPreferencesFactoryUtil;
028: import com.liferay.util.servlet.SessionErrors;
029: import com.liferay.util.servlet.SessionMessages;
030:
031: import javax.portlet.ActionRequest;
032: import javax.portlet.ActionResponse;
033: import javax.portlet.PortletConfig;
034: import javax.portlet.PortletPreferences;
035: import javax.portlet.RenderRequest;
036: import javax.portlet.RenderResponse;
037:
038: /**
039: * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class ConfigurationActionImpl implements ConfigurationAction {
045:
046: public void processAction(PortletConfig config, ActionRequest req,
047: ActionResponse res) throws Exception {
048:
049: String cmd = ParamUtil.getString(req, Constants.CMD);
050:
051: if (!cmd.equals(Constants.UPDATE)) {
052: return;
053: }
054:
055: String portletResource = ParamUtil.getString(req,
056: "portletResource");
057:
058: PortletPreferences prefs = PortletPreferencesFactoryUtil
059: .getPortletSetup(req, portletResource, false, true);
060:
061: String tabs2 = ParamUtil.getString(req, "tabs2");
062:
063: if (tabs2.equals("email-from")) {
064: updateEmailFrom(req, prefs);
065: } else if (tabs2.equals("article-approval-denied-email")) {
066: updateEmailArticleApprovalDenied(req, prefs);
067: } else if (tabs2.equals("article-approval-granted-email")) {
068: updateEmailArticleApprovalGranted(req, prefs);
069: } else if (tabs2.equals("article-approval-requested-email")) {
070: updateEmailArticleApprovalRequested(req, prefs);
071: } else if (tabs2.equals("article-review-email")) {
072: updateEmailArticleReview(req, prefs);
073: }
074:
075: if (SessionErrors.isEmpty(req)) {
076: prefs.store();
077:
078: SessionMessages.add(req, config.getPortletName()
079: + ".doConfigure");
080: }
081: }
082:
083: public String render(PortletConfig config, RenderRequest req,
084: RenderResponse res) throws Exception {
085:
086: return "/html/portlet/journal/configuration.jsp";
087: }
088:
089: protected void updateEmailFrom(ActionRequest req,
090: PortletPreferences prefs) throws Exception {
091:
092: String emailFromName = ParamUtil
093: .getString(req, "emailFromName");
094: String emailFromAddress = ParamUtil.getString(req,
095: "emailFromAddress");
096:
097: if (Validator.isNull(emailFromName)) {
098: SessionErrors.add(req, "emailFromName");
099: } else if (!Validator.isEmailAddress(emailFromAddress)) {
100: SessionErrors.add(req, "emailFromAddress");
101: } else {
102: prefs.setValue("email-from-name", emailFromName);
103: prefs.setValue("email-from-address", emailFromAddress);
104: }
105: }
106:
107: protected void updateEmailArticleApprovalDenied(ActionRequest req,
108: PortletPreferences prefs) throws Exception {
109:
110: String emailArticleApprovalDeniedEnabled = ParamUtil.getString(
111: req, "emailArticleApprovalDeniedEnabled");
112: String emailArticleApprovalDeniedSubject = ParamUtil.getString(
113: req, "emailArticleApprovalDeniedSubject");
114: String emailArticleApprovalDeniedBody = ParamUtil.getString(
115: req, "emailArticleApprovalDeniedBody");
116:
117: if (Validator.isNull(emailArticleApprovalDeniedSubject)) {
118: SessionErrors.add(req, "emailArticleApprovalDeniedSubject");
119: } else if (Validator.isNull(emailArticleApprovalDeniedBody)) {
120: SessionErrors.add(req, "emailArticleApprovalDeniedBody");
121: } else {
122: prefs.setValue("email-article-approval-denied-enabled",
123: emailArticleApprovalDeniedEnabled);
124: prefs.setValue("email-article-approval-denied-subject",
125: emailArticleApprovalDeniedSubject);
126: prefs.setValue("email-article-approval-denied-body",
127: emailArticleApprovalDeniedBody);
128: }
129: }
130:
131: protected void updateEmailArticleApprovalGranted(ActionRequest req,
132: PortletPreferences prefs) throws Exception {
133:
134: String emailArticleApprovalGrantedEnabled = ParamUtil
135: .getString(req, "emailArticleApprovalGrantedEnabled");
136: String emailArticleApprovalGrantedSubject = ParamUtil
137: .getString(req, "emailArticleApprovalGrantedSubject");
138: String emailArticleApprovalGrantedBody = ParamUtil.getString(
139: req, "emailArticleApprovalGrantedBody");
140:
141: if (Validator.isNull(emailArticleApprovalGrantedSubject)) {
142: SessionErrors
143: .add(req, "emailArticleApprovalGrantedSubject");
144: } else if (Validator.isNull(emailArticleApprovalGrantedBody)) {
145: SessionErrors.add(req, "emailArticleApprovalGrantedBody");
146: } else {
147: prefs.setValue("email-article-approval-granted-enabled",
148: emailArticleApprovalGrantedEnabled);
149: prefs.setValue("email-article-approval-granted-subject",
150: emailArticleApprovalGrantedSubject);
151: prefs.setValue("email-article-approval-granted-body",
152: emailArticleApprovalGrantedBody);
153: }
154: }
155:
156: protected void updateEmailArticleApprovalRequested(
157: ActionRequest req, PortletPreferences prefs)
158: throws Exception {
159:
160: String emailArticleApprovalRequestedEnabled = ParamUtil
161: .getString(req, "emailArticleApprovalRequestedEnabled");
162: String emailArticleApprovalRequestedSubject = ParamUtil
163: .getString(req, "emailArticleApprovalRequestedSubject");
164: String emailArticleApprovalRequestedBody = ParamUtil.getString(
165: req, "emailArticleApprovalRequestedBody");
166:
167: if (Validator.isNull(emailArticleApprovalRequestedSubject)) {
168: SessionErrors.add(req,
169: "emailArticleApprovalRequestedSubject");
170: } else if (Validator.isNull(emailArticleApprovalRequestedBody)) {
171: SessionErrors.add(req, "emailArticleApprovalRequestedBody");
172: } else {
173: prefs.setValue("email-article-approval-requested-enabled",
174: emailArticleApprovalRequestedEnabled);
175: prefs.setValue("email-article-approval-requested-subject",
176: emailArticleApprovalRequestedSubject);
177: prefs.setValue("email-article-approval-requested-body",
178: emailArticleApprovalRequestedBody);
179: }
180: }
181:
182: protected void updateEmailArticleReview(ActionRequest req,
183: PortletPreferences prefs) throws Exception {
184:
185: String emailArticleReviewEnabled = ParamUtil.getString(req,
186: "emailArticleReviewEnabled");
187: String emailArticleReviewSubject = ParamUtil.getString(req,
188: "emailArticleReviewSubject");
189: String emailArticleReviewBody = ParamUtil.getString(req,
190: "emailArticleReviewBody");
191:
192: if (Validator.isNull(emailArticleReviewSubject)) {
193: SessionErrors.add(req, "emailArticleReviewSubject");
194: } else if (Validator.isNull(emailArticleReviewBody)) {
195: SessionErrors.add(req, "emailArticleReviewBody");
196: } else {
197: prefs.setValue("email-article-review-enabled",
198: emailArticleReviewEnabled);
199: prefs.setValue("email-article-review-subject",
200: emailArticleReviewSubject);
201: prefs.setValue("email-article-review-body",
202: emailArticleReviewBody);
203: }
204: }
205:
206: }
|