001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.iframe.action;
016    
017    import com.liferay.portal.kernel.portlet.DefaultConfigurationAction;
018    import com.liferay.portal.kernel.util.CharPool;
019    import com.liferay.portal.kernel.util.HttpUtil;
020    import com.liferay.portal.kernel.util.StringUtil;
021    
022    import javax.portlet.ActionRequest;
023    import javax.portlet.ActionResponse;
024    import javax.portlet.PortletConfig;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class ConfigurationActionImpl extends DefaultConfigurationAction {
030    
031            @Override
032            public void processAction(
033                            PortletConfig portletConfig, ActionRequest actionRequest,
034                            ActionResponse actionResponse)
035                    throws Exception {
036    
037                    String src = getParameter(actionRequest, "src");
038    
039                    if (!src.startsWith("/") &&
040                            !StringUtil.startsWith(src, "http://") &&
041                            !StringUtil.startsWith(src, "https://") &&
042                            !StringUtil.startsWith(src, "mhtml://")) {
043    
044                            src = HttpUtil.getProtocol(actionRequest) + "://" + src;
045    
046                            setPreference(actionRequest, "src", src);
047                    }
048    
049                    String[] htmlAttributes = StringUtil.splitLines(
050                            getParameter(actionRequest, "htmlAttributes"));
051    
052                    for (String htmlAttribute : htmlAttributes) {
053                            int pos = htmlAttribute.indexOf(CharPool.EQUAL);
054    
055                            if (pos == -1) {
056                                    continue;
057                            }
058    
059                            String key = htmlAttribute.substring(0, pos);
060                            String value = htmlAttribute.substring(
061                                    pos + 1, htmlAttribute.length());
062    
063                            setPreference(actionRequest, key, value);
064                    }
065    
066                    super.processAction(portletConfig, actionRequest, actionResponse);
067            }
068    
069    }