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.amazonrankings.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.StringPool;
23  import com.liferay.portal.kernel.util.StringUtil;
24  import com.liferay.portlet.PortletPreferencesFactoryUtil;
25  
26  import java.util.Arrays;
27  
28  import javax.portlet.ActionRequest;
29  import javax.portlet.ActionResponse;
30  import javax.portlet.PortletConfig;
31  import javax.portlet.PortletPreferences;
32  import javax.portlet.RenderRequest;
33  import javax.portlet.RenderResponse;
34  import javax.portlet.ValidatorException;
35  
36  /**
37   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class ConfigurationActionImpl extends BaseConfigurationAction {
42  
43      public void processAction(
44              PortletConfig portletConfig, ActionRequest actionRequest,
45              ActionResponse actionResponse)
46          throws Exception {
47  
48          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
49  
50          if (!cmd.equals(Constants.UPDATE)) {
51              return;
52          }
53  
54          String[] isbns = StringUtil.split(
55              ParamUtil.getString(actionRequest, "isbns").toUpperCase(),
56              StringPool.SPACE);
57  
58          Arrays.sort(isbns);
59  
60          String portletResource = ParamUtil.getString(
61              actionRequest, "portletResource");
62  
63          PortletPreferences preferences =
64              PortletPreferencesFactoryUtil.getPortletSetup(
65                  actionRequest, portletResource);
66  
67          preferences.setValues("isbns", isbns);
68  
69          try {
70              preferences.store();
71          }
72          catch (ValidatorException ve) {
73              SessionErrors.add(
74                  actionRequest, ValidatorException.class.getName(), ve);
75  
76              return;
77          }
78  
79          SessionMessages.add(
80              actionRequest, portletConfig.getPortletName() + ".doConfigure");
81      }
82  
83      public String render(
84              PortletConfig portletConfig, RenderRequest renderRequest,
85              RenderResponse renderResponse)
86          throws Exception {
87  
88          return "/html/portlet/amazon_rankings/configuration.jsp";
89      }
90  
91  }