1
22
23 package com.liferay.portlet.iframe.action;
24
25 import com.liferay.portal.kernel.portlet.ConfigurationAction;
26 import com.liferay.portal.kernel.util.Constants;
27 import com.liferay.portal.kernel.util.HttpUtil;
28 import com.liferay.portal.kernel.util.ParamUtil;
29 import com.liferay.portal.kernel.util.StringUtil;
30 import com.liferay.portlet.PortletPreferencesFactoryUtil;
31 import com.liferay.util.servlet.SessionMessages;
32
33 import javax.portlet.ActionRequest;
34 import javax.portlet.ActionResponse;
35 import javax.portlet.PortletConfig;
36 import javax.portlet.PortletPreferences;
37 import javax.portlet.RenderRequest;
38 import javax.portlet.RenderResponse;
39
40
46 public class ConfigurationActionImpl implements ConfigurationAction {
47
48 public void processAction(
49 PortletConfig config, ActionRequest req, ActionResponse res)
50 throws Exception {
51
52 String cmd = ParamUtil.getString(req, Constants.CMD);
53
54 if (!cmd.equals(Constants.UPDATE)) {
55 return;
56 }
57
58 String src = ParamUtil.getString(req, "src");
59
60 if (!src.startsWith("/") &&
61 !StringUtil.startsWith(src, "http://") &&
62 !StringUtil.startsWith(src, "https://") &&
63 !StringUtil.startsWith(src, "mhtml://")) {
64
65 src = HttpUtil.getProtocol(req) + "://" + src;
66 }
67
68 boolean relative = ParamUtil.getBoolean(req, "relative");
69
70 boolean auth = ParamUtil.getBoolean(req, "auth");
71 String authType = ParamUtil.getString(req, "authType");
72 String formMethod = ParamUtil.getString(req, "formMethod");
73 String userName = ParamUtil.getString(req, "userName");
74 String password = ParamUtil.getString(req, "password");
75 String hiddenVariables = ParamUtil.getString(req, "hiddenVariables");
76
77 String[] htmlAttributes = StringUtil.split(ParamUtil.getString(
78 req, "htmlAttributes"), "\n");
79
80 String portletResource = ParamUtil.getString(
81 req, "portletResource");
82
83 PortletPreferences prefs =
84 PortletPreferencesFactoryUtil.getPortletSetup(req, 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(req, config.getPortletName() + ".doConfigure");
111 }
112
113 public String render(
114 PortletConfig config, RenderRequest req, RenderResponse res)
115 throws Exception {
116
117 return "/html/portlet/iframe/configuration.jsp";
118 }
119
120 }