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