1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.wsrp.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.struts.PortletAction;
27  import com.liferay.portal.util.WebKeys;
28  import com.liferay.util.servlet.SessionMessages;
29  
30  import javax.portlet.ActionRequest;
31  import javax.portlet.ActionResponse;
32  import javax.portlet.PortletConfig;
33  import javax.portlet.PortletPreferences;
34  import javax.portlet.PortletSession;
35  import javax.portlet.RenderRequest;
36  import javax.portlet.RenderResponse;
37  
38  import org.apache.struts.action.ActionForm;
39  import org.apache.struts.action.ActionForward;
40  import org.apache.struts.action.ActionMapping;
41  
42  /**
43   * <a href="EditLocalPreferencesAction.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Michael Young
46   *
47   */
48  public class EditLocalPreferencesAction extends PortletAction {
49  
50      public void processAction(
51              ActionMapping mapping, ActionForm form, PortletConfig config,
52              ActionRequest req, ActionResponse res)
53          throws Exception {
54  
55          PortletPreferences prefs = req.getPreferences();
56  
57          String wsrpServiceUrl = ParamUtil.getString(req, "wsrp_service_url");
58          String markupEndpoint = ParamUtil.getString(req, "markup_endpoint");
59          String serviceDescriptionEndpoint = ParamUtil.getString(req,
60                  "service_description_endpoint");
61          String registrationEndpoint = ParamUtil.getString(req,
62                  "registration_endpoint");
63          String portletManagementEndpoint = ParamUtil.getString(req,
64                  "portlet_management_endpoint");
65          String portletHandle = ParamUtil.getString(req, "portlet_handle");
66  
67          prefs.setValue("wsrp-service-url", wsrpServiceUrl);
68          prefs.setValue("markup-endpoint", markupEndpoint);
69          prefs.setValue("service-description-endpoint",
70                  serviceDescriptionEndpoint);
71          prefs.setValue("registration-endpoint", registrationEndpoint);
72          prefs.setValue("portlet-management-endpoint",
73                          portletManagementEndpoint);
74  
75          String oldPortletHandle = prefs.getValue("portlet-handle", "");
76          if (!portletHandle.equals(oldPortletHandle)) {
77              prefs.reset("parent-handle");
78          }
79          prefs.setValue("portlet-handle", portletHandle);
80  
81          // start a new wsrp session on next render
82          PortletSession ses = req.getPortletSession();
83          ses.setAttribute(WebKeys.WSRP_NEW_SESSION, "true");
84  
85          prefs.store();
86  
87          SessionMessages.add(req, config.getPortletName() + ".doEdit");
88  
89          setForward(req, "portlet.wsrp.edit");
90      }
91  
92      public ActionForward render(
93              ActionMapping mapping, ActionForm form, PortletConfig config,
94              RenderRequest req, RenderResponse res)
95          throws Exception {
96  
97          return mapping.findForward(
98              getForward(req, "portlet.wsrp.edit_local_preferences"));
99      }
100 
101 }