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  public class WAIAutoDeployer extends PortletAutoDeployer {
42  
43      protected WAIAutoDeployer() throws AutoDeployException {
44          try {
45              jars.add(DeployUtil.getResourcePath("portals-bridges.jar"));
46          }
47          catch (Exception e) {
48              throw new AutoDeployException(e);
49          }
50      }
51  
52      protected void copyXmls(
53              File srcFile, String displayName, PluginPackage pluginPackage)
54          throws Exception {
55  
56          super.copyXmls(srcFile, displayName, pluginPackage);
57  
58          String portletName = displayName;
59  
60          if (pluginPackage != null) {
61              portletName = pluginPackage.getName();
62          }
63  
64          Map<String, String> filterMap = new HashMap<String, String>();
65  
66          filterMap.put("portlet_name", displayName);
67          filterMap.put("portlet_title", portletName);
68          filterMap.put("restore_current_view", "false");
69  
70          if (pluginPackage != null) {
71              Properties settings = pluginPackage.getDeploymentSettings();
72  
73              filterMap.put(
74                  "portlet_class",
75                  settings.getProperty(
76                      "wai.portlet", "com.liferay.util.bridges.wai.WAIPortlet"));
77  
78              filterMap.put(
79                  "friendly_url_mapper_class",
80                  settings.getProperty(
81                      "wai.friendly.url.mapper",
82                      "com.liferay.util.bridges.wai.WAIFriendlyURLMapper"));
83          }
84          else {
85              filterMap.put(
86                  "portlet_class", "com.liferay.util.bridges.wai.WAIPortlet");
87  
88              filterMap.put(
89                  "friendly_url_mapper_class",
90                  "com.liferay.util.bridges.wai.WAIFriendlyURLMapper");
91          }
92  
93          _setInitParams(filterMap, pluginPackage);
94  
95          copyDependencyXml(
96              "liferay-display.xml", srcFile + "/WEB-INF", filterMap);
97          copyDependencyXml(
98              "liferay-portlet.xml", srcFile + "/WEB-INF", filterMap);
99          copyDependencyXml(
100             "portlet.xml", srcFile + "/WEB-INF", filterMap);
101         copyDependencyXml(
102             "normal_window_state.jsp", srcFile + "/WEB-INF/jsp/liferay/wai");
103         copyDependencyXml("iframe.jsp", srcFile + "/WEB-INF/jsp/liferay/wai");
104 
105     }
106 
107     private void _setInitParams(
108         Map<String, String> filterMap, PluginPackage pluginPackage) {
109 
110         for (int i = 0; i < _INIT_PARAM_NAMES.length; i++) {
111             String name = _INIT_PARAM_NAMES[i];
112 
113             String value = null;
114 
115             if (pluginPackage != null) {
116                 pluginPackage.getDeploymentSettings().getProperty(name);
117             }
118 
119             if (Validator.isNull(value)) {
120                 value = _INIT_PARAM_DEFAULT_VALUES[i];
121             }
122 
123             filterMap.put("init_param_name_" + i, name);
124             filterMap.put("init_param_value_" + i, value);
125         }
126     }
127 
128     private static String[] _INIT_PARAM_NAMES = new String[] {
129         "wai.connector", "wai.connector.iframe.height.extra"
130     };
131 
132     private static String[] _INIT_PARAM_DEFAULT_VALUES = new String[] {
133         "iframe", "40"
134     };
135 
136 }