001
014
015 package com.liferay.portlet.iframe.action;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
020 import com.liferay.portal.kernel.util.CharPool;
021 import com.liferay.portal.kernel.util.HttpUtil;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.kernel.util.StringUtil;
024 import com.liferay.portal.kernel.util.Validator;
025 import com.liferay.portlet.iframe.util.IFrameUtil;
026
027 import javax.portlet.ActionRequest;
028 import javax.portlet.ActionResponse;
029 import javax.portlet.PortletConfig;
030 import javax.portlet.PortletPreferences;
031 import javax.portlet.PortletRequest;
032 import javax.portlet.ReadOnlyException;
033
034
037 public class ConfigurationActionImpl extends DefaultConfigurationAction {
038
039 @Override
040 public void processAction(
041 PortletConfig portletConfig, ActionRequest actionRequest,
042 ActionResponse actionResponse)
043 throws Exception {
044
045 String src = getParameter(actionRequest, "src");
046
047 if (!src.startsWith("/") &&
048 !StringUtil.startsWith(src, "http:
049 !StringUtil.startsWith(src, "https:
050 !StringUtil.startsWith(src, "mhtml:
051
052 src = HttpUtil.getProtocol(actionRequest) + ":
053
054 setPreference(actionRequest, "src", src);
055 }
056
057 String[] htmlAttributes = StringUtil.splitLines(
058 getParameter(actionRequest, "htmlAttributes"));
059
060 for (String htmlAttribute : htmlAttributes) {
061 int pos = htmlAttribute.indexOf(CharPool.EQUAL);
062
063 if (pos == -1) {
064 continue;
065 }
066
067 String key = htmlAttribute.substring(0, pos);
068 String value = htmlAttribute.substring(pos + 1);
069
070 setPreference(actionRequest, key, value);
071 }
072
073 super.processAction(portletConfig, actionRequest, actionResponse);
074 }
075
076 @Override
077 protected void postProcess(
078 long companyId, PortletRequest portletRequest,
079 PortletPreferences portletPreferences)
080 throws PortalException, SystemException {
081
082 String formPassword = portletPreferences.getValue(
083 "formPassword", StringPool.BLANK);
084
085 if (Validator.isNotNull(formPassword) &&
086 formPassword.contains("@password@")) {
087
088 if (!IFrameUtil.isPasswordTokenEnabled(portletRequest)) {
089 formPassword = formPassword.replaceAll("@password@", "");
090
091 try {
092 portletPreferences.setValue("formPassword", formPassword);
093 }
094 catch (ReadOnlyException roe) {
095 throw new PortalException(roe);
096 }
097 }
098 }
099 }
100
101 }