001    /**
002     * Copyright (c) 2000-2010 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.portlet.DefaultFriendlyURLMapper;
020    import com.liferay.portal.kernel.util.FileUtil;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.util.bridges.wai.WAIPortlet;
023    
024    import java.io.File;
025    
026    import java.util.HashMap;
027    import java.util.Map;
028    import java.util.Properties;
029    
030    /**
031     * @author Jorge Ferrer
032     * @author Connor McKay
033     */
034    public class WAIAutoDeployer extends PortletAutoDeployer {
035    
036            protected WAIAutoDeployer() throws AutoDeployException {
037                    try {
038                            addRequiredJar(jars, "portals-bridges.jar");
039                    }
040                    catch (Exception e) {
041                            throw new AutoDeployException(e);
042                    }
043            }
044    
045            protected void copyXmls(
046                            File srcFile, String displayName, PluginPackage pluginPackage)
047                    throws Exception {
048    
049                    super.copyXmls(srcFile, displayName, pluginPackage);
050    
051                    // The default context.xml file for Tomcat causes portlets to be run
052                    // from the temp directory, which prevents some applications from saving
053                    // their settings. There is no easy way to prevent this file from being
054                    // copied, so it must be deleted afterwards.
055    
056                    FileUtil.delete(srcFile + "/META-INF/context.xml");
057    
058                    String portletName = displayName;
059    
060                    if (pluginPackage != null) {
061                            portletName = pluginPackage.getName();
062                    }
063    
064                    Map<String, String> filterMap = new HashMap<String, String>();
065    
066                    filterMap.put("portlet_name", displayName);
067                    filterMap.put("portlet_title", portletName);
068    
069                    if (pluginPackage != null) {
070                            Properties deploymentSettings =
071                                    pluginPackage.getDeploymentSettings();
072    
073                            filterMap.put(
074                                    "portlet_class",
075                                    deploymentSettings.getProperty(
076                                            "wai.portlet", WAIPortlet.class.getName()));
077    
078                            filterMap.put(
079                                    "friendly_url_mapper_class",
080                                    deploymentSettings.getProperty(
081                                            "wai.friendly.url.mapper",
082                                            DefaultFriendlyURLMapper.class.getName()));
083    
084                            filterMap.put(
085                                    "friendly_url_mapping",
086                                    deploymentSettings.getProperty(
087                                            "wai.friendly.url.mapping", "waiapp"));
088    
089                            filterMap.put(
090                                    "friendly_url_routes",
091                                    deploymentSettings.getProperty(
092                                            "wai.friendly.url.routes",
093                                            "com/liferay/util/bridges/wai/" +
094                                                    "wai-friendly-url-routes.xml"));
095                    }
096                    else {
097                            filterMap.put("portlet_class", WAIPortlet.class.getName());
098    
099                            filterMap.put(
100                                    "friendly_url_mapper_class",
101                                    DefaultFriendlyURLMapper.class.getName());
102    
103                            filterMap.put("friendly_url_mapping", "waiapp");
104    
105                            filterMap.put(
106                                    "friendly_url_routes",
107                                    "com/liferay/util/bridges/wai/wai-friendly-url-routes.xml");
108                    }
109    
110                    _setInitParams(filterMap, pluginPackage);
111    
112                    copyDependencyXml(
113                            "liferay-display.xml", srcFile + "/WEB-INF", filterMap);
114                    copyDependencyXml(
115                            "liferay-portlet.xml", srcFile + "/WEB-INF", filterMap);
116                    copyDependencyXml(
117                            "portlet.xml", srcFile + "/WEB-INF", filterMap);
118                    copyDependencyXml("iframe.jsp", srcFile + "/WEB-INF/jsp/liferay/wai");
119            }
120    
121            private void _setInitParams(
122                    Map<String, String> filterMap, PluginPackage pluginPackage) {
123    
124                    for (int i = 0; i < _INIT_PARAM_NAMES.length; i++) {
125                            String name = _INIT_PARAM_NAMES[i];
126    
127                            String value = null;
128    
129                            if (pluginPackage != null) {
130                                    Properties deploymentSettings =
131                                            pluginPackage.getDeploymentSettings();
132    
133                                    value = deploymentSettings.getProperty(name);
134                            }
135    
136                            if (Validator.isNull(value)) {
137                                    value = _INIT_PARAM_DEFAULT_VALUES[i];
138                            }
139    
140                            filterMap.put("init_param_name_" + i, name);
141                            filterMap.put("init_param_value_" + i, value);
142                    }
143            }
144    
145            private static String[] _INIT_PARAM_NAMES = new String[] {
146                    "wai.connector.iframe.height.default"
147            };
148    
149            private static String[] _INIT_PARAM_DEFAULT_VALUES = new String[] {
150                    "500"
151            };
152    
153    }