1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.invitation.action;
16  
17  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18  import com.liferay.portal.kernel.servlet.SessionErrors;
19  import com.liferay.portal.kernel.servlet.SessionMessages;
20  import com.liferay.portal.kernel.util.Constants;
21  import com.liferay.portal.kernel.util.ParamUtil;
22  import com.liferay.portal.kernel.util.Validator;
23  import com.liferay.portlet.PortletPreferencesFactoryUtil;
24  
25  import javax.portlet.ActionRequest;
26  import javax.portlet.ActionResponse;
27  import javax.portlet.PortletConfig;
28  import javax.portlet.PortletPreferences;
29  import javax.portlet.RenderRequest;
30  import javax.portlet.RenderResponse;
31  
32  /**
33   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class ConfigurationActionImpl extends BaseConfigurationAction {
38  
39      public void processAction(
40              PortletConfig portletConfig, ActionRequest actionRequest,
41              ActionResponse actionResponse)
42          throws Exception {
43  
44          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
45  
46          if (!cmd.equals(Constants.UPDATE)) {
47              return;
48          }
49  
50          String emailMessageSubject = ParamUtil.getString(
51              actionRequest, "emailMessageSubject");
52          String emailMessageBody = ParamUtil.getString(
53              actionRequest, "emailMessageBody");
54  
55          if (Validator.isNull(emailMessageSubject)) {
56              SessionErrors.add(actionRequest, "emailMessageSubject");
57          }
58          else if (Validator.isNull(emailMessageBody)) {
59              SessionErrors.add(actionRequest, "emailMessageBody");
60          }
61          else {
62              String portletResource = ParamUtil.getString(
63                  actionRequest, "portletResource");
64  
65              PortletPreferences preferences =
66                  PortletPreferencesFactoryUtil.getPortletSetup(
67                      actionRequest, portletResource);
68  
69              preferences.setValue("email-message-subject", emailMessageSubject);
70              preferences.setValue("email-message-body", emailMessageBody);
71  
72              preferences.store();
73  
74              SessionMessages.add(
75                  actionRequest, portletConfig.getPortletName() + ".doConfigure");
76          }
77      }
78  
79      public String render(
80              PortletConfig portletConfig, RenderRequest renderRequest,
81              RenderResponse renderResponse)
82          throws Exception {
83  
84          return "/html/portlet/invitation/configuration.jsp";
85      }
86  
87  }