1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }