1
19
20 package com.liferay.portlet.iframe.action;
21
22 import com.liferay.portal.kernel.portlet.BaseConfigurationAction;
23 import com.liferay.portal.kernel.servlet.SessionMessages;
24 import com.liferay.portal.kernel.util.Constants;
25 import com.liferay.portal.kernel.util.HttpUtil;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.kernel.util.StringUtil;
28 import com.liferay.portlet.PortletPreferencesFactoryUtil;
29
30 import javax.portlet.ActionRequest;
31 import javax.portlet.ActionResponse;
32 import javax.portlet.PortletConfig;
33 import javax.portlet.PortletPreferences;
34 import javax.portlet.RenderRequest;
35 import javax.portlet.RenderResponse;
36
37
43 public class ConfigurationActionImpl extends BaseConfigurationAction {
44
45 public void processAction(
46 PortletConfig portletConfig, ActionRequest actionRequest,
47 ActionResponse actionResponse)
48 throws Exception {
49
50 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
51
52 if (!cmd.equals(Constants.UPDATE)) {
53 return;
54 }
55
56 String src = ParamUtil.getString(actionRequest, "src");
57
58 if (!src.startsWith("/") &&
59 !StringUtil.startsWith(src, "http://") &&
60 !StringUtil.startsWith(src, "https://") &&
61 !StringUtil.startsWith(src, "mhtml://")) {
62
63 src = HttpUtil.getProtocol(actionRequest) + "://" + src;
64 }
65
66 boolean relative = ParamUtil.getBoolean(actionRequest, "relative");
67
68 boolean auth = ParamUtil.getBoolean(actionRequest, "auth");
69 String authType = ParamUtil.getString(actionRequest, "authType");
70 String formMethod = ParamUtil.getString(actionRequest, "formMethod");
71 String userName = ParamUtil.getString(actionRequest, "userName");
72 String userNameField = ParamUtil.getString(
73 actionRequest, "userNameField");
74 String password = ParamUtil.getString(actionRequest, "password");
75 String passwordField = ParamUtil.getString(
76 actionRequest, "passwordField");
77 String hiddenVariables = ParamUtil.getString(
78 actionRequest, "hiddenVariables");
79
80 String[] htmlAttributes = StringUtil.split(ParamUtil.getString(
81 actionRequest, "htmlAttributes"), "\n");
82
83 String portletResource = ParamUtil.getString(
84 actionRequest, "portletResource");
85
86 PortletPreferences preferences =
87 PortletPreferencesFactoryUtil.getPortletSetup(
88 actionRequest, portletResource);
89
90 preferences.setValue("src", src);
91 preferences.setValue("relative", String.valueOf(relative));
92
93 preferences.setValue("auth", String.valueOf(auth));
94 preferences.setValue("auth-type", authType);
95 preferences.setValue("form-method", formMethod);
96 preferences.setValue("user-name", userName);
97 preferences.setValue("user-name-field", userNameField);
98 preferences.setValue("password", password);
99 preferences.setValue("password-field", passwordField);
100 preferences.setValue("hidden-variables", hiddenVariables);
101
102 for (int i = 0; i < htmlAttributes.length; i++) {
103 int pos = htmlAttributes[i].indexOf("=");
104
105 if (pos != -1) {
106 String key = htmlAttributes[i].substring(0, pos);
107 String value = htmlAttributes[i].substring(
108 pos + 1, htmlAttributes[i].length());
109
110 preferences.setValue(key, value);
111 }
112 }
113
114 preferences.store();
115
116 SessionMessages.add(
117 actionRequest, portletConfig.getPortletName() + ".doConfigure");
118 }
119
120 public String render(
121 PortletConfig portletConfig, RenderRequest renderRequest,
122 RenderResponse renderResponse)
123 throws Exception {
124
125 return "/html/portlet/iframe/configuration.jsp";
126 }
127
128 }