1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.amazonrankings.action;
21  
22  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
23  import com.liferay.portal.kernel.servlet.SessionErrors;
24  import com.liferay.portal.kernel.servlet.SessionMessages;
25  import com.liferay.portal.kernel.util.Constants;
26  import com.liferay.portal.kernel.util.ParamUtil;
27  import com.liferay.portal.kernel.util.StringPool;
28  import com.liferay.portal.kernel.util.StringUtil;
29  import com.liferay.portlet.PortletPreferencesFactoryUtil;
30  
31  import java.util.Arrays;
32  
33  import javax.portlet.ActionRequest;
34  import javax.portlet.ActionResponse;
35  import javax.portlet.PortletConfig;
36  import javax.portlet.PortletPreferences;
37  import javax.portlet.RenderRequest;
38  import javax.portlet.RenderResponse;
39  import javax.portlet.ValidatorException;
40  
41  /**
42   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
43   *
44   * @author Brian Wing Shun Chan
45   *
46   */
47  public class ConfigurationActionImpl extends BaseConfigurationAction {
48  
49      public void processAction(
50              PortletConfig portletConfig, ActionRequest actionRequest,
51              ActionResponse actionResponse)
52          throws Exception {
53  
54          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
55  
56          if (!cmd.equals(Constants.UPDATE)) {
57              return;
58          }
59  
60          String[] isbns = StringUtil.split(
61              ParamUtil.getString(actionRequest, "isbns").toUpperCase(),
62              StringPool.SPACE);
63  
64          Arrays.sort(isbns);
65  
66          String portletResource = ParamUtil.getString(
67              actionRequest, "portletResource");
68  
69          PortletPreferences preferences =
70              PortletPreferencesFactoryUtil.getPortletSetup(
71                  actionRequest, portletResource);
72  
73          preferences.setValues("isbns", isbns);
74  
75          try {
76              preferences.store();
77          }
78          catch (ValidatorException ve) {
79              SessionErrors.add(
80                  actionRequest, ValidatorException.class.getName(), ve);
81  
82              return;
83          }
84  
85          SessionMessages.add(
86              actionRequest, portletConfig.getPortletName() + ".doConfigure");
87      }
88  
89      public String render(
90              PortletConfig portletConfig, RenderRequest renderRequest,
91              RenderResponse renderResponse)
92          throws Exception {
93  
94          return "/html/portlet/amazon_rankings/configuration.jsp";
95      }
96  
97  }