001    /**
002     * Copyright (c) 2000-2012 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.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    }