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