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