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.webproxy.action;
16  
17  import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
18  import com.liferay.portal.kernel.servlet.SessionMessages;
19  import com.liferay.portal.kernel.util.Constants;
20  import com.liferay.portal.kernel.util.HttpUtil;
21  import com.liferay.portal.kernel.util.ParamUtil;
22  import com.liferay.portal.kernel.util.StringUtil;
23  import com.liferay.portlet.PortletPreferencesFactoryUtil;
24  
25  import javax.portlet.ActionRequest;
26  import javax.portlet.ActionResponse;
27  import javax.portlet.PortletConfig;
28  import javax.portlet.PortletPreferences;
29  import javax.portlet.RenderRequest;
30  import javax.portlet.RenderResponse;
31  
32  /**
33   * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class ConfigurationActionImpl extends BaseConfigurationAction {
38  
39      public void processAction(
40              PortletConfig portletConfig, ActionRequest actionRequest,
41              ActionResponse actionResponse)
42          throws Exception {
43  
44          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
45  
46          if (!cmd.equals(Constants.UPDATE)) {
47              return;
48          }
49  
50          String initUrl = ParamUtil.getString(actionRequest, "initUrl");
51  
52          if (!initUrl.startsWith("/") &&
53              !StringUtil.startsWith(initUrl, "http://") &&
54              !StringUtil.startsWith(initUrl, "https://") &&
55              !StringUtil.startsWith(initUrl, "mhtml://")) {
56  
57              initUrl = HttpUtil.getProtocol(actionRequest) + "://" + initUrl;
58          }
59  
60          String scope = ParamUtil.getString(actionRequest, "scope");
61          String proxyHost = ParamUtil.getString(actionRequest, "proxyHost");
62          String proxyPort = ParamUtil.getString(actionRequest, "proxyPort");
63          String proxyAuthentication = ParamUtil.getString(
64              actionRequest, "proxyAuthentication");
65          String proxyAuthenticationUsername = ParamUtil.getString(
66              actionRequest, "proxyAuthenticationUsername");
67          String proxyAuthenticationPassword = ParamUtil.getString(
68              actionRequest, "proxyAuthenticationPassword");
69          String proxyAuthenticationHost = ParamUtil.getString(
70              actionRequest, "proxyAuthenticationHost");
71          String proxyAuthenticationDomain = ParamUtil.getString(
72              actionRequest, "proxyAuthenticationDomain");
73          String stylesheet = ParamUtil.getString(actionRequest, "stylesheet");
74  
75          String portletResource = ParamUtil.getString(
76              actionRequest, "portletResource");
77  
78          PortletPreferences preferences =
79              PortletPreferencesFactoryUtil.getPortletSetup(
80                  actionRequest, portletResource);
81  
82          preferences.setValue("initUrl", initUrl);
83          preferences.setValue("scope", scope);
84          preferences.setValue("proxyHost", proxyHost);
85          preferences.setValue("proxyPort", proxyPort);
86          preferences.setValue("proxyAuthentication", proxyAuthentication);
87          preferences.setValue(
88              "proxyAuthenticationUsername", proxyAuthenticationUsername);
89          preferences.setValue(
90              "proxyAuthenticationPassword", proxyAuthenticationPassword);
91          preferences.setValue(
92              "proxyAuthenticationHost", proxyAuthenticationHost);
93          preferences.setValue(
94              "proxyAuthenticationDomain", proxyAuthenticationDomain);
95          preferences.setValue("stylesheet", stylesheet);
96  
97          preferences.store();
98  
99          SessionMessages.add(
100             actionRequest, portletConfig.getPortletName() + ".doConfigure");
101     }
102 
103     public String render(
104             PortletConfig portletConfig, RenderRequest renderRequest,
105             RenderResponse renderResponse)
106         throws Exception {
107 
108         return "/html/portlet/web_proxy/configuration.jsp";
109     }
110 
111 }