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