1
19
20 package com.liferay.portlet.iframe.action;
21
22 import com.liferay.portal.kernel.portlet.ConfigurationAction;
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 implements ConfigurationAction {
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 password = ParamUtil.getString(actionRequest, "password");
73 String hiddenVariables = ParamUtil.getString(
74 actionRequest, "hiddenVariables");
75
76 String[] htmlAttributes = StringUtil.split(ParamUtil.getString(
77 actionRequest, "htmlAttributes"), "\n");
78
79 String portletResource = ParamUtil.getString(
80 actionRequest, "portletResource");
81
82 PortletPreferences prefs =
83 PortletPreferencesFactoryUtil.getPortletSetup(
84 actionRequest, portletResource);
85
86 prefs.setValue("src", src);
87 prefs.setValue("relative", String.valueOf(relative));
88
89 prefs.setValue("auth", String.valueOf(auth));
90 prefs.setValue("auth-type", authType);
91 prefs.setValue("form-method", formMethod);
92 prefs.setValue("user-name", userName);
93 prefs.setValue("password", password);
94 prefs.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 prefs.setValue(key, value);
105 }
106 }
107
108 prefs.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 }