1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.deploy.auto;
24  
25  import com.liferay.portal.deploy.DeployUtil;
26  import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
27  import com.liferay.portal.kernel.plugin.PluginPackage;
28  import com.liferay.portal.kernel.util.Validator;
29  
30  import java.io.File;
31  
32  import java.util.HashMap;
33  import java.util.Map;
34  import java.util.Properties;
35  
36  /**
37   * <a href="WAIAutoDeployer.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Jorge Ferrer
40   *
41   */
42  public class WAIAutoDeployer extends PortletAutoDeployer {
43  
44      protected WAIAutoDeployer() throws AutoDeployException {
45          try {
46              jars.add(DeployUtil.getResourcePath("portals-bridges.jar"));
47          }
48          catch (Exception e) {
49              throw new AutoDeployException(e);
50          }
51      }
52  
53      protected void copyXmls(
54              File srcFile, String displayName, PluginPackage pluginPackage)
55          throws Exception {
56  
57          super.copyXmls(srcFile, displayName, pluginPackage);
58  
59          String portletName = displayName;
60  
61          if (pluginPackage != null) {
62              portletName = pluginPackage.getName();
63          }
64  
65          Map<String, String> filterMap = new HashMap<String, String>();
66  
67          filterMap.put("portlet_name", displayName);
68          filterMap.put("portlet_title", portletName);
69          filterMap.put("restore_current_view", "false");
70  
71          if (pluginPackage != null) {
72              Properties settings = pluginPackage.getDeploymentSettings();
73  
74              filterMap.put(
75                  "portlet_class",
76                  settings.getProperty(
77                      "wai.portlet", "com.liferay.util.bridges.wai.WAIPortlet"));
78  
79              filterMap.put(
80                  "friendly_url_mapper_class",
81                  settings.getProperty(
82                      "wai.friendly.url.mapper",
83                      "com.liferay.util.bridges.wai.WAIFriendlyURLMapper"));
84          }
85          else {
86              filterMap.put(
87                  "portlet_class", "com.liferay.util.bridges.wai.WAIPortlet");
88  
89              filterMap.put(
90                  "friendly_url_mapper_class",
91                  "com.liferay.util.bridges.wai.WAIFriendlyURLMapper");
92          }
93  
94          _setInitParams(filterMap, pluginPackage);
95  
96          copyDependencyXml(
97              "liferay-display.xml", srcFile + "/WEB-INF", filterMap);
98          copyDependencyXml(
99              "liferay-portlet.xml", srcFile + "/WEB-INF", filterMap);
100         copyDependencyXml(
101             "portlet.xml", srcFile + "/WEB-INF", filterMap);
102         copyDependencyXml(
103             "normal_window_state.jsp", srcFile + "/WEB-INF/jsp/liferay/wai");
104         copyDependencyXml("iframe.jsp", srcFile + "/WEB-INF/jsp/liferay/wai");
105 
106     }
107 
108     private void _setInitParams(
109         Map<String, String> filterMap, PluginPackage pluginPackage) {
110 
111         for (int i = 0; i < _INIT_PARAM_NAMES.length; i++) {
112             String name = _INIT_PARAM_NAMES[i];
113 
114             String value = null;
115 
116             if (pluginPackage != null) {
117                 pluginPackage.getDeploymentSettings().getProperty(name);
118             }
119 
120             if (Validator.isNull(value)) {
121                 value = _INIT_PARAM_DEFAULT_VALUES[i];
122             }
123 
124             filterMap.put("init_param_name_" + i, name);
125             filterMap.put("init_param_value_" + i, value);
126         }
127     }
128 
129     private static String[] _INIT_PARAM_NAMES = new String[] {
130         "wai.connector", "wai.connector.iframe.height.extra"
131     };
132 
133     private static String[] _INIT_PARAM_DEFAULT_VALUES = new String[] {
134         "iframe", "40"
135     };
136 
137 }