001
014
015 package com.liferay.portlet.iframe.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.CharPool;
020 import com.liferay.portal.kernel.util.Constants;
021 import com.liferay.portal.kernel.util.HttpUtil;
022 import com.liferay.portal.kernel.util.ParamUtil;
023 import com.liferay.portal.kernel.util.StringPool;
024 import com.liferay.portal.kernel.util.StringUtil;
025 import com.liferay.portlet.PortletPreferencesFactoryUtil;
026
027 import javax.portlet.ActionRequest;
028 import javax.portlet.ActionResponse;
029 import javax.portlet.PortletConfig;
030 import javax.portlet.PortletPreferences;
031 import javax.portlet.RenderRequest;
032 import javax.portlet.RenderResponse;
033
034
037 public class ConfigurationActionImpl extends BaseConfigurationAction {
038
039 public void processAction(
040 PortletConfig portletConfig, ActionRequest actionRequest,
041 ActionResponse actionResponse)
042 throws Exception {
043
044 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
045
046 if (!cmd.equals(Constants.UPDATE)) {
047 return;
048 }
049
050 String src = ParamUtil.getString(actionRequest, "src");
051
052 if (!src.startsWith("/") &&
053 !StringUtil.startsWith(src, "http:
054 !StringUtil.startsWith(src, "https:
055 !StringUtil.startsWith(src, "mhtml:
056
057 src = HttpUtil.getProtocol(actionRequest) + ":
058 }
059
060 boolean relative = ParamUtil.getBoolean(actionRequest, "relative");
061
062 boolean auth = ParamUtil.getBoolean(actionRequest, "auth");
063 String authType = ParamUtil.getString(actionRequest, "authType");
064 String formMethod = ParamUtil.getString(actionRequest, "formMethod");
065 String userName = ParamUtil.getString(actionRequest, "userName");
066 String userNameField = ParamUtil.getString(
067 actionRequest, "userNameField");
068 String password = ParamUtil.getString(actionRequest, "password");
069 String passwordField = ParamUtil.getString(
070 actionRequest, "passwordField");
071 String hiddenVariables = ParamUtil.getString(
072 actionRequest, "hiddenVariables");
073
074 String[] htmlAttributes = StringUtil.split(ParamUtil.getString(
075 actionRequest, "htmlAttributes"), StringPool.NEW_LINE);
076
077 String portletResource = ParamUtil.getString(
078 actionRequest, "portletResource");
079
080 PortletPreferences preferences =
081 PortletPreferencesFactoryUtil.getPortletSetup(
082 actionRequest, portletResource);
083
084 preferences.setValue("src", src);
085 preferences.setValue("relative", String.valueOf(relative));
086
087 preferences.setValue("auth", String.valueOf(auth));
088 preferences.setValue("auth-type", authType);
089 preferences.setValue("form-method", formMethod);
090 preferences.setValue("user-name", userName);
091 preferences.setValue("user-name-field", userNameField);
092 preferences.setValue("password", password);
093 preferences.setValue("password-field", passwordField);
094 preferences.setValue("hidden-variables", hiddenVariables);
095
096 for (String htmlAttribute : htmlAttributes) {
097 int pos = htmlAttribute.indexOf(CharPool.EQUAL);
098
099 if (pos == -1) {
100 continue;
101 }
102
103 String key = htmlAttribute.substring(0, pos);
104 String value = htmlAttribute.substring(
105 pos + 1, htmlAttribute.length());
106
107 preferences.setValue(key, value);
108 }
109
110 preferences.store();
111
112 SessionMessages.add(
113 actionRequest, portletConfig.getPortletName() + ".doConfigure");
114 }
115
116 public String render(
117 PortletConfig portletConfig, RenderRequest renderRequest,
118 RenderResponse renderResponse)
119 throws Exception {
120
121 return "/html/portlet/iframe/configuration.jsp";
122 }
123
124 }