001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.webproxy.action;
022:
023: import com.liferay.portal.kernel.portlet.ConfigurationAction;
024: import com.liferay.portal.kernel.util.Constants;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.StringUtil;
027: import com.liferay.portlet.PortletPreferencesFactoryUtil;
028: import com.liferay.util.Http;
029: import com.liferay.util.servlet.SessionMessages;
030:
031: import javax.portlet.ActionRequest;
032: import javax.portlet.ActionResponse;
033: import javax.portlet.PortletConfig;
034: import javax.portlet.PortletPreferences;
035: import javax.portlet.RenderRequest;
036: import javax.portlet.RenderResponse;
037:
038: /**
039: * <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class ConfigurationActionImpl implements ConfigurationAction {
045:
046: public void processAction(PortletConfig config, ActionRequest req,
047: ActionResponse res) throws Exception {
048:
049: String cmd = ParamUtil.getString(req, Constants.CMD);
050:
051: if (!cmd.equals(Constants.UPDATE)) {
052: return;
053: }
054:
055: String initUrl = ParamUtil.getString(req, "initUrl");
056:
057: if (!initUrl.startsWith("/")
058: && !StringUtil.startsWith(initUrl, "http://")
059: && !StringUtil.startsWith(initUrl, "https://")
060: && !StringUtil.startsWith(initUrl, "mhtml://")) {
061:
062: initUrl = Http.getProtocol(req) + "://" + initUrl;
063: }
064:
065: String scope = ParamUtil.getString(req, "scope");
066: String proxyHost = ParamUtil.getString(req, "proxyHost");
067: String proxyPort = ParamUtil.getString(req, "proxyPort");
068: String proxyAuthentication = ParamUtil.getString(req,
069: "proxyAuthentication");
070: String proxyAuthenticationUsername = ParamUtil.getString(req,
071: "proxyAuthenticationUsername");
072: String proxyAuthenticationPassword = ParamUtil.getString(req,
073: "proxyAuthenticationPassword");
074: String proxyAuthenticationHost = ParamUtil.getString(req,
075: "proxyAuthenticationHost");
076: String proxyAuthenticationDomain = ParamUtil.getString(req,
077: "proxyAuthenticationDomain");
078: String stylesheet = ParamUtil.getString(req, "stylesheet");
079:
080: String portletResource = ParamUtil.getString(req,
081: "portletResource");
082:
083: PortletPreferences prefs = PortletPreferencesFactoryUtil
084: .getPortletSetup(req, portletResource, true, true);
085:
086: prefs.setValue("initUrl", initUrl);
087: prefs.setValue("scope", scope);
088: prefs.setValue("proxyHost", proxyHost);
089: prefs.setValue("proxyPort", proxyPort);
090: prefs.setValue("proxyAuthentication", proxyAuthentication);
091: prefs.setValue("proxyAuthenticationUsername",
092: proxyAuthenticationUsername);
093: prefs.setValue("proxyAuthenticationPassword",
094: proxyAuthenticationPassword);
095: prefs.setValue("proxyAuthenticationHost",
096: proxyAuthenticationHost);
097: prefs.setValue("proxyAuthenticationDomain",
098: proxyAuthenticationDomain);
099: prefs.setValue("stylesheet", stylesheet);
100:
101: prefs.store();
102:
103: SessionMessages.add(req, config.getPortletName()
104: + ".doConfigure");
105: }
106:
107: public String render(PortletConfig config, RenderRequest req,
108: RenderResponse res) throws Exception {
109:
110: return "/html/portlet/web_proxy/configuration.jsp";
111: }
112:
113: }
|