001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.action;
016    
017    import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionErrors;
019    import com.liferay.portal.kernel.util.ParamUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    
022    import javax.portlet.ActionRequest;
023    import javax.portlet.ActionResponse;
024    import javax.portlet.PortletConfig;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class ConfigurationActionImpl extends DefaultConfigurationAction {
030    
031            @Override
032            public void processAction(
033                            PortletConfig portletConfig, ActionRequest actionRequest,
034                            ActionResponse actionResponse)
035                    throws Exception {
036    
037                    String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
038    
039                    if (tabs2.equals("email-from")) {
040                            validateEmailFrom(actionRequest);
041                    }
042                    else if (tabs2.equals("web-content-added-email")) {
043                            validateEmailArticleAdded(actionRequest);
044                    }
045                    else if (tabs2.equals("web-content-approval-denied-email")) {
046                            validateEmailArticleApprovalDenied(actionRequest);
047                    }
048                    else if (tabs2.equals("web-content-approval-granted-email")) {
049                            validateEmailArticleApprovalGranted(actionRequest);
050                    }
051                    else if (tabs2.equals("web-content-approval-requested-email")) {
052                            validateEmailArticleApprovalRequested(actionRequest);
053                    }
054                    else if (tabs2.equals("web-content-review-email")) {
055                            validateEmailArticleReview(actionRequest);
056                    }
057                    else if (tabs2.equals("web-content-updated-email")) {
058                            validateEmailArticleUpdated(actionRequest);
059                    }
060    
061                    super.processAction(portletConfig, actionRequest, actionResponse);
062            }
063    
064            protected void validateEmailArticleAdded(ActionRequest actionRequest)
065                    throws Exception {
066    
067                    String emailArticleAddedSubject = getParameter(
068                            actionRequest, "emailArticleAddedSubject");
069                    String emailArticleAddedBody = getParameter(
070                            actionRequest, "emailArticleAddedBody");
071    
072                    if (Validator.isNull(emailArticleAddedSubject)) {
073                            SessionErrors.add(actionRequest, "emailArticleAddedSubject");
074                    }
075                    else if (Validator.isNull(emailArticleAddedBody)) {
076                            SessionErrors.add(actionRequest, "emailArticleAddedBody");
077                    }
078            }
079    
080            protected void validateEmailArticleApprovalDenied(
081                            ActionRequest actionRequest)
082                    throws Exception {
083    
084                    String emailArticleApprovalDeniedSubject = getParameter(
085                            actionRequest, "emailArticleApprovalDeniedSubject");
086                    String emailArticleApprovalDeniedBody = getParameter(
087                            actionRequest, "emailArticleApprovalDeniedBody");
088    
089                    if (Validator.isNull(emailArticleApprovalDeniedSubject)) {
090                            SessionErrors.add(
091                                    actionRequest, "emailArticleApprovalDeniedSubject");
092                    }
093                    else if (Validator.isNull(emailArticleApprovalDeniedBody)) {
094                            SessionErrors.add(actionRequest, "emailArticleApprovalDeniedBody");
095                    }
096            }
097    
098            protected void validateEmailArticleApprovalGranted(
099                            ActionRequest actionRequest)
100                    throws Exception {
101    
102                    String emailArticleApprovalGrantedSubject = getParameter(
103                            actionRequest, "emailArticleApprovalGrantedSubject");
104                    String emailArticleApprovalGrantedBody = getParameter(
105                            actionRequest, "emailArticleApprovalGrantedBody");
106    
107                    if (Validator.isNull(emailArticleApprovalGrantedSubject)) {
108                            SessionErrors.add(
109                                    actionRequest, "emailArticleApprovalGrantedSubject");
110                    }
111                    else if (Validator.isNull(emailArticleApprovalGrantedBody)) {
112                            SessionErrors.add(actionRequest, "emailArticleApprovalGrantedBody");
113                    }
114            }
115    
116            protected void validateEmailArticleApprovalRequested(
117                            ActionRequest actionRequest)
118                    throws Exception {
119    
120                    String emailArticleApprovalRequestedSubject = getParameter(
121                            actionRequest, "emailArticleApprovalRequestedSubject");
122                    String emailArticleApprovalRequestedBody = getParameter(
123                            actionRequest, "emailArticleApprovalRequestedBody");
124    
125                    if (Validator.isNull(emailArticleApprovalRequestedSubject)) {
126                            SessionErrors.add(
127                                    actionRequest, "emailArticleApprovalRequestedSubject");
128                    }
129                    else if (Validator.isNull(emailArticleApprovalRequestedBody)) {
130                            SessionErrors.add(
131                                    actionRequest, "emailArticleApprovalRequestedBody");
132                    }
133            }
134    
135            protected void validateEmailArticleReview(ActionRequest actionRequest)
136                    throws Exception {
137    
138                    String emailArticleReviewSubject = getParameter(
139                            actionRequest, "emailArticleReviewSubject");
140                    String emailArticleReviewBody = getParameter(
141                            actionRequest, "emailArticleReviewBody");
142    
143                    if (Validator.isNull(emailArticleReviewSubject)) {
144                            SessionErrors.add(actionRequest, "emailArticleReviewSubject");
145                    }
146                    else if (Validator.isNull(emailArticleReviewBody)) {
147                            SessionErrors.add(actionRequest, "emailArticleReviewBody");
148                    }
149            }
150    
151            protected void validateEmailArticleUpdated(ActionRequest actionRequest)
152                    throws Exception {
153    
154                    String emailArticleUpdatedSubject = getParameter(
155                            actionRequest, "emailArticleUpdatedSubject");
156                    String emailArticleUpdatedBody = getParameter(
157                            actionRequest, "emailArticleUpdatedBody");
158    
159                    if (Validator.isNull(emailArticleUpdatedSubject)) {
160                            SessionErrors.add(actionRequest, "emailArticleUpdatedSubject");
161                    }
162                    else if (Validator.isNull(emailArticleUpdatedBody)) {
163                            SessionErrors.add(actionRequest, "emailArticleUpdatedBody");
164                    }
165            }
166    
167            protected void validateEmailFrom(ActionRequest actionRequest)
168                    throws Exception {
169    
170                    String emailFromName = getParameter(actionRequest, "emailFromName");
171                    String emailFromAddress = getParameter(
172                            actionRequest, "emailFromAddress");
173    
174                    if (Validator.isNull(emailFromName)) {
175                            SessionErrors.add(actionRequest, "emailFromName");
176                    }
177                    else if (!Validator.isEmailAddress(emailFromAddress)) {
178                            SessionErrors.add(actionRequest, "emailFromAddress");
179                    }
180            }
181    
182    }