001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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(pos + 1);
061    
062                            setPreference(actionRequest, key, value);
063                    }
064    
065                    super.processAction(portletConfig, actionRequest, actionResponse);
066            }
067    
068    }