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.ParamUtil;
28 import com.liferay.portal.kernel.util.StringUtil;
29 import com.liferay.portlet.PortletPreferencesFactoryUtil;
30 import com.liferay.util.Http;
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 = Http.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(
85 req, portletResource, true, true);
86
87 prefs.setValue("src", src);
88 prefs.setValue("relative", String.valueOf(relative));
89
90 prefs.setValue("auth", String.valueOf(auth));
91 prefs.setValue("auth-type", authType);
92 prefs.setValue("form-method", formMethod);
93 prefs.setValue("user-name", userName);
94 prefs.setValue("password", password);
95 prefs.setValue("hidden-variables", hiddenVariables);
96
97 for (int i = 0; i < htmlAttributes.length; i++) {
98 int pos = htmlAttributes[i].indexOf("=");
99
100 if (pos != -1) {
101 String key = htmlAttributes[i].substring(0, pos);
102 String value = htmlAttributes[i].substring(
103 pos + 1, htmlAttributes[i].length());
104
105 prefs.setValue(key, value);
106 }
107 }
108
109 prefs.store();
110
111 SessionMessages.add(req, config.getPortletName() + ".doConfigure");
112 }
113
114 public String render(
115 PortletConfig config, RenderRequest req, RenderResponse res)
116 throws Exception {
117
118 return "/html/portlet/iframe/configuration.jsp";
119 }
120
121 }