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 boolean resizeAutomatically = ParamUtil.getBoolean(
074 actionRequest, "resizeAutomatically");
075 String heightMaximized = ParamUtil.getString(
076 actionRequest, "heightMaximized");
077 String heightNormal = ParamUtil.getString(
078 actionRequest, "heightNormal");
079 String width = ParamUtil.getString(actionRequest, "width");
080
081 String[] htmlAttributes = StringUtil.split(ParamUtil.getString(
082 actionRequest, "htmlAttributes"), StringPool.NEW_LINE);
083
084 String portletResource = ParamUtil.getString(
085 actionRequest, "portletResource");
086
087 PortletPreferences preferences =
088 PortletPreferencesFactoryUtil.getPortletSetup(
089 actionRequest, portletResource);
090
091 preferences.setValue("src", src);
092 preferences.setValue("relative", String.valueOf(relative));
093
094 preferences.setValue("auth", String.valueOf(auth));
095 preferences.setValue("auth-type", authType);
096 preferences.setValue("form-method", formMethod);
097 preferences.setValue("user-name", userName);
098 preferences.setValue("user-name-field", userNameField);
099 preferences.setValue("password", password);
100 preferences.setValue("password-field", passwordField);
101 preferences.setValue("hidden-variables", hiddenVariables);
102 preferences.setValue(
103 "resize-automatically", String.valueOf(resizeAutomatically));
104 preferences.setValue("height-maximized", heightMaximized);
105 preferences.setValue("height-normal", heightNormal);
106 preferences.setValue("width", width);
107
108 for (String htmlAttribute : htmlAttributes) {
109 int pos = htmlAttribute.indexOf(CharPool.EQUAL);
110
111 if (pos == -1) {
112 continue;
113 }
114
115 String key = htmlAttribute.substring(0, pos);
116 String value = htmlAttribute.substring(
117 pos + 1, htmlAttribute.length());
118
119 preferences.setValue(key, value);
120 }
121
122 preferences.store();
123
124 SessionMessages.add(
125 actionRequest, portletConfig.getPortletName() + ".doConfigure");
126 }
127
128 public String render(
129 PortletConfig portletConfig, RenderRequest renderRequest,
130 RenderResponse renderResponse)
131 throws Exception {
132
133 return "/html/portlet/iframe/configuration.jsp";
134 }
135
136 }