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.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 validateEmailEntryAdded(ActionRequest actionRequest)
059                    throws Exception {
060    
061                    String emailEntryAddedSubject = getLocalizedParameter(
062                            actionRequest, "emailEntryAddedSubject");
063                    String emailEntryAddedBody = getLocalizedParameter(
064                            actionRequest, "emailEntryAddedBody");
065    
066                    if (Validator.isNull(emailEntryAddedSubject)) {
067                            SessionErrors.add(actionRequest, "emailEntryAddedSubject");
068                    }
069                    else if (Validator.isNull(emailEntryAddedBody)) {
070                            SessionErrors.add(actionRequest, "emailEntryAddedBody");
071                    }
072            }
073    
074            protected void validateEmailEntryUpdated(ActionRequest actionRequest)
075                    throws Exception {
076    
077                    String emailEntryUpdatedSubject = getLocalizedParameter(
078                            actionRequest, "emailEntryUpdatedSubject");
079                    String emailEntryUpdatedBody = getLocalizedParameter(
080                            actionRequest, "emailEntryUpdatedBody");
081    
082                    if (Validator.isNull(emailEntryUpdatedSubject)) {
083                            SessionErrors.add(actionRequest, "emailEntryUpdatedSubject");
084                    }
085                    else if (Validator.isNull(emailEntryUpdatedBody)) {
086                            SessionErrors.add(actionRequest, "emailEntryUpdatedBody");
087                    }
088            }
089    
090            protected void validateEmailFrom(ActionRequest actionRequest)
091                    throws Exception {
092    
093                    String emailFromName = getParameter(actionRequest, "emailFromName");
094                    String emailFromAddress = getParameter(
095                            actionRequest, "emailFromAddress");
096    
097                    if (Validator.isNull(emailFromName)) {
098                            SessionErrors.add(actionRequest, "emailFromName");
099                    }
100                    else if (!Validator.isEmailAddress(emailFromAddress) &&
101                                     !Validator.isVariableTerm(emailFromAddress)) {
102    
103                            SessionErrors.add(actionRequest, "emailFromAddress");
104                    }
105            }
106    
107    }