001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.webproxy.action;
016    
017    import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
018    import com.liferay.portal.kernel.servlet.SessionMessages;
019    import com.liferay.portal.kernel.util.Constants;
020    import com.liferay.portal.kernel.util.HttpUtil;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portal.kernel.util.StringUtil;
023    import com.liferay.portlet.PortletPreferencesFactoryUtil;
024    
025    import javax.portlet.ActionRequest;
026    import javax.portlet.ActionResponse;
027    import javax.portlet.PortletConfig;
028    import javax.portlet.PortletPreferences;
029    import javax.portlet.RenderRequest;
030    import javax.portlet.RenderResponse;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     */
035    public class ConfigurationActionImpl extends BaseConfigurationAction {
036    
037            public void processAction(
038                            PortletConfig portletConfig, ActionRequest actionRequest,
039                            ActionResponse actionResponse)
040                    throws Exception {
041    
042                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
043    
044                    if (!cmd.equals(Constants.UPDATE)) {
045                            return;
046                    }
047    
048                    String initUrl = ParamUtil.getString(actionRequest, "initUrl");
049    
050                    if (!initUrl.startsWith("/") &&
051                            !StringUtil.startsWith(initUrl, "http://") &&
052                            !StringUtil.startsWith(initUrl, "https://") &&
053                            !StringUtil.startsWith(initUrl, "mhtml://")) {
054    
055                            initUrl = HttpUtil.getProtocol(actionRequest) + "://" + initUrl;
056                    }
057    
058                    String scope = ParamUtil.getString(actionRequest, "scope");
059                    String proxyHost = ParamUtil.getString(actionRequest, "proxyHost");
060                    String proxyPort = ParamUtil.getString(actionRequest, "proxyPort");
061                    String proxyAuthentication = ParamUtil.getString(
062                            actionRequest, "proxyAuthentication");
063                    String proxyAuthenticationUsername = ParamUtil.getString(
064                            actionRequest, "proxyAuthenticationUsername");
065                    String proxyAuthenticationPassword = ParamUtil.getString(
066                            actionRequest, "proxyAuthenticationPassword");
067                    String proxyAuthenticationHost = ParamUtil.getString(
068                            actionRequest, "proxyAuthenticationHost");
069                    String proxyAuthenticationDomain = ParamUtil.getString(
070                            actionRequest, "proxyAuthenticationDomain");
071                    String stylesheet = ParamUtil.getString(actionRequest, "stylesheet");
072    
073                    String portletResource = ParamUtil.getString(
074                            actionRequest, "portletResource");
075    
076                    PortletPreferences preferences =
077                            PortletPreferencesFactoryUtil.getPortletSetup(
078                                    actionRequest, portletResource);
079    
080                    preferences.setValue("initUrl", initUrl);
081                    preferences.setValue("scope", scope);
082                    preferences.setValue("proxyHost", proxyHost);
083                    preferences.setValue("proxyPort", proxyPort);
084                    preferences.setValue("proxyAuthentication", proxyAuthentication);
085                    preferences.setValue(
086                            "proxyAuthenticationUsername", proxyAuthenticationUsername);
087                    preferences.setValue(
088                            "proxyAuthenticationPassword", proxyAuthenticationPassword);
089                    preferences.setValue(
090                            "proxyAuthenticationHost", proxyAuthenticationHost);
091                    preferences.setValue(
092                            "proxyAuthenticationDomain", proxyAuthenticationDomain);
093                    preferences.setValue("stylesheet", stylesheet);
094    
095                    preferences.store();
096    
097                    SessionMessages.add(
098                            actionRequest, portletConfig.getPortletName() + ".doConfigure");
099            }
100    
101            public String render(
102                            PortletConfig portletConfig, RenderRequest renderRequest,
103                            RenderResponse renderResponse)
104                    throws Exception {
105    
106                    return "/html/portlet/web_proxy/configuration.jsp";
107            }
108    
109    }