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.iframe.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 src = ParamUtil.getString(req, "src");
056:
057: if (!src.startsWith("/")
058: && !StringUtil.startsWith(src, "http://")
059: && !StringUtil.startsWith(src, "https://")
060: && !StringUtil.startsWith(src, "mhtml://")) {
061:
062: src = Http.getProtocol(req) + "://" + src;
063: }
064:
065: boolean relative = ParamUtil.getBoolean(req, "relative");
066:
067: boolean auth = ParamUtil.getBoolean(req, "auth");
068: String authType = ParamUtil.getString(req, "authType");
069: String formMethod = ParamUtil.getString(req, "formMethod");
070: String userName = ParamUtil.getString(req, "userName");
071: String password = ParamUtil.getString(req, "password");
072: String hiddenVariables = ParamUtil.getString(req,
073: "hiddenVariables");
074:
075: String[] htmlAttributes = StringUtil.split(ParamUtil.getString(
076: req, "htmlAttributes"), "\n");
077:
078: String portletResource = ParamUtil.getString(req,
079: "portletResource");
080:
081: PortletPreferences prefs = PortletPreferencesFactoryUtil
082: .getPortletSetup(req, portletResource, true, true);
083:
084: prefs.setValue("src", src);
085: prefs.setValue("relative", String.valueOf(relative));
086:
087: prefs.setValue("auth", String.valueOf(auth));
088: prefs.setValue("auth-type", authType);
089: prefs.setValue("form-method", formMethod);
090: prefs.setValue("user-name", userName);
091: prefs.setValue("password", password);
092: prefs.setValue("hidden-variables", hiddenVariables);
093:
094: for (int i = 0; i < htmlAttributes.length; i++) {
095: int pos = htmlAttributes[i].indexOf("=");
096:
097: if (pos != -1) {
098: String key = htmlAttributes[i].substring(0, pos);
099: String value = htmlAttributes[i].substring(pos + 1,
100: htmlAttributes[i].length());
101:
102: prefs.setValue(key, value);
103: }
104: }
105:
106: prefs.store();
107:
108: SessionMessages.add(req, config.getPortletName()
109: + ".doConfigure");
110: }
111:
112: public String render(PortletConfig config, RenderRequest req,
113: RenderResponse res) throws Exception {
114:
115: return "/html/portlet/iframe/configuration.jsp";
116: }
117:
118: }
|