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.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  }