001    /**
002     * Copyright (c) 2000-present 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.portal.deploy.auto;
016    
017    import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
018    import com.liferay.portal.kernel.plugin.PluginPackage;
019    import com.liferay.portal.kernel.util.StringBundler;
020    
021    import java.io.File;
022    
023    import java.util.HashMap;
024    import java.util.Map;
025    
026    /**
027     * @author Jorge Ferrer
028     */
029    public class PHPPortletAutoDeployer extends PortletAutoDeployer {
030    
031            public PHPPortletAutoDeployer() throws AutoDeployException {
032                    try {
033                            String[] phpJars = {"resin.jar", "script-10.jar"};
034    
035                            for (int i = 0; i < phpJars.length; i++) {
036                                    String phpJar = phpJars[i];
037    
038                                    jars.add(downloadJar(phpJar));
039                            }
040    
041                            addRequiredJar(jars, "portals-bridges.jar");
042                    }
043                    catch (Exception e) {
044                            throw new AutoDeployException(e);
045                    }
046            }
047    
048            @Override
049            public void copyXmls(
050                            File srcFile, String displayName, PluginPackage pluginPackage)
051                    throws Exception {
052    
053                    super.copyXmls(srcFile, displayName, pluginPackage);
054    
055                    Map<String, String> filterMap = new HashMap<>();
056    
057                    String pluginName = displayName;
058    
059                    if (pluginPackage != null) {
060                            pluginName = pluginPackage.getName();
061                    }
062    
063                    filterMap.put(
064                            "portlet_class", "com.liferay.util.bridges.php.PHPPortlet");
065                    filterMap.put("portlet_name", pluginName);
066                    filterMap.put("portlet_title", pluginName);
067                    filterMap.put("restore_current_view", "false");
068                    filterMap.put("friendly_url_mapper_class", "");
069                    filterMap.put("friendly_url_mapping", "");
070                    filterMap.put("friendly_url_routes", "");
071                    filterMap.put("init_param_name_0", "view-uri");
072                    filterMap.put("init_param_value_0", "/index.php");
073                    filterMap.put("init_param_name_1", "add-portlet-params");
074                    filterMap.put("init_param_value_1", "true");
075    
076                    copyDependencyXml(
077                            "liferay-display.xml", srcFile + "/WEB-INF", filterMap);
078                    copyDependencyXml(
079                            "liferay-portlet.xml", srcFile + "/WEB-INF", filterMap);
080                    copyDependencyXml("portlet.xml", srcFile + "/WEB-INF", filterMap);
081            }
082    
083            @Override
084            public String getExtraContent(
085                            double webXmlVersion, File srcFile, String displayName)
086                    throws Exception {
087    
088                    StringBundler sb = new StringBundler(2);
089    
090                    String extraFiltersContent = super.getExtraFiltersContent(
091                            webXmlVersion, srcFile);
092    
093                    sb.append(extraFiltersContent);
094    
095                    // Ignore filters
096    
097                    sb.append(getIgnoreFiltersContent(srcFile));
098    
099                    return sb.toString();
100            }
101    
102    }