001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.blogs.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.Constants;
020    import com.liferay.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.kernel.util.Validator;
022    
023    import javax.portlet.ActionRequest;
024    import javax.portlet.ActionResponse;
025    import javax.portlet.PortletConfig;
026    
027    /**
028     * @author Jorge Ferrer
029     * @author Thiago Moreira
030     */
031    public class ConfigurationActionImpl extends DefaultConfigurationAction {
032    
033            @Override
034            public void processAction(
035                            PortletConfig portletConfig, ActionRequest actionRequest,
036                            ActionResponse actionResponse)
037                    throws Exception {
038    
039                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
040    
041                    String tabs2 = ParamUtil.getString(actionRequest, "tabs2");
042    
043                    if (Validator.isNotNull(cmd)) {
044                            if (tabs2.equals("email-from")) {
045                                    validateEmailFrom(actionRequest);
046                            }
047                            else if (tabs2.equals("entry-added-email")) {
048                                    validateEmailEntryAdded(actionRequest);
049                            }
050                            else if (tabs2.equals("entry-updated-email")) {
051                                    validateEmailEntryUpdated(actionRequest);
052                            }
053                    }
054    
055                    super.processAction(portletConfig, actionRequest, actionResponse);
056            }
057    
058            protected void validateEmailFrom(ActionRequest actionRequest)
059                    throws Exception {
060    
061                    String emailFromName = getParameter(actionRequest, "emailFromName");
062                    String emailFromAddress = getParameter(
063                            actionRequest, "emailFromAddress");
064    
065                    if (Validator.isNull(emailFromName)) {
066                            SessionErrors.add(actionRequest, "emailFromName");
067                    }
068                    else if (!Validator.isEmailAddress(emailFromAddress) &&
069                                     !Validator.isVariableTerm(emailFromAddress)) {
070    
071                            SessionErrors.add(actionRequest, "emailFromAddress");
072                    }
073            }
074    
075            protected void validateEmailEntryAdded(ActionRequest actionRequest)
076                    throws Exception {
077    
078                    String emailEntryAddedSubject = getLocalizedParameter(
079                            actionRequest, "emailEntryAddedSubject");
080                    String emailEntryAddedBody = getLocalizedParameter(
081                            actionRequest, "emailEntryAddedBody");
082    
083                    if (Validator.isNull(emailEntryAddedSubject)) {
084                            SessionErrors.add(actionRequest, "emailEntryAddedSubject");
085                    }
086                    else if (Validator.isNull(emailEntryAddedBody)) {
087                            SessionErrors.add(actionRequest, "emailEntryAddedBody");
088                    }
089            }
090    
091            protected void validateEmailEntryUpdated(ActionRequest actionRequest)
092                    throws Exception {
093    
094                    String emailEntryUpdatedSubject = getLocalizedParameter(
095                            actionRequest, "emailEntryUpdatedSubject");
096                    String emailEntryUpdatedBody = getLocalizedParameter(
097                            actionRequest, "emailEntryUpdatedBody");
098    
099                    if (Validator.isNull(emailEntryUpdatedSubject)) {
100                            SessionErrors.add(actionRequest, "emailEntryUpdatedSubject");
101                    }
102                    else if (Validator.isNull(emailEntryUpdatedBody)) {
103                            SessionErrors.add(actionRequest, "emailEntryUpdatedBody");
104                    }
105            }
106    
107    }