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.currencyconverter.action;
16  
17  import com.liferay.portal.kernel.servlet.SessionErrors;
18  import com.liferay.portal.kernel.servlet.SessionMessages;
19  import com.liferay.portal.kernel.util.Constants;
20  import com.liferay.portal.kernel.util.ParamUtil;
21  import com.liferay.portal.kernel.util.StringUtil;
22  import com.liferay.portal.struts.PortletAction;
23  
24  import javax.portlet.ActionRequest;
25  import javax.portlet.ActionResponse;
26  import javax.portlet.PortletConfig;
27  import javax.portlet.PortletPreferences;
28  import javax.portlet.RenderRequest;
29  import javax.portlet.RenderResponse;
30  import javax.portlet.ValidatorException;
31  
32  import org.apache.struts.action.ActionForm;
33  import org.apache.struts.action.ActionForward;
34  import org.apache.struts.action.ActionMapping;
35  
36  /**
37   * <a href="EditPreferencesAction.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   */
41  public class EditPreferencesAction extends PortletAction {
42  
43      public void processAction(
44              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
45              ActionRequest actionRequest, 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          PortletPreferences preferences = actionRequest.getPreferences();
55  
56          String[] symbols = StringUtil.split(
57              ParamUtil.getString(actionRequest, "symbols").toUpperCase());
58  
59          preferences.setValues("symbols", symbols);
60  
61          try {
62              preferences.store();
63          }
64          catch (ValidatorException ve) {
65              SessionErrors.add(
66                  actionRequest, ValidatorException.class.getName(), ve);
67  
68              return;
69          }
70  
71          SessionMessages.add(
72              actionRequest, portletConfig.getPortletName() + ".doEdit");
73      }
74  
75      public ActionForward render(
76              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
77              RenderRequest renderRequest, RenderResponse renderResponse)
78          throws Exception {
79  
80          return mapping.findForward("portlet.currency_converter.edit");
81      }
82  
83  }