1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.tools.deploy;
16  
17  import com.liferay.portal.kernel.plugin.PluginPackage;
18  import com.liferay.portal.kernel.util.ServerDetector;
19  import com.liferay.portal.kernel.util.StringBundler;
20  import com.liferay.portal.util.InitUtil;
21  
22  import java.io.File;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * <a href="HookDeployer.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class HookDeployer extends BaseDeployer {
33  
34      public static void main(String[] args) {
35          InitUtil.initWithSpring();
36  
37          List<String> wars = new ArrayList<String>();
38          List<String> jars = new ArrayList<String>();
39  
40          for (String arg : args) {
41              if (arg.endsWith(".war")) {
42                  wars.add(arg);
43              }
44              else if (arg.endsWith(".jar")) {
45                  jars.add(arg);
46              }
47          }
48  
49          new HookDeployer(wars, jars);
50      }
51  
52      public HookDeployer() {
53      }
54  
55      public HookDeployer(List<String> wars, List<String> jars) {
56          super(wars, jars);
57      }
58  
59      public void copyXmls(
60              File srcFile, String displayName, PluginPackage pluginPackage)
61          throws Exception {
62  
63          super.copyXmls(srcFile, displayName, pluginPackage);
64  
65          if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
66              copyDependencyXml("context.xml", srcFile + "/META-INF");
67          }
68      }
69  
70      public String getExtraContent(
71              double webXmlVersion, File srcFile, String displayName)
72          throws Exception {
73  
74          StringBundler sb = new StringBundler(6);
75  
76          String extraContent = super.getExtraContent(
77              webXmlVersion, srcFile, displayName);
78  
79          sb.append(extraContent);
80  
81          // HookContextListener
82  
83          sb.append("<listener>");
84          sb.append("<listener-class>");
85          sb.append("com.liferay.portal.kernel.servlet.HookContextListener");
86          sb.append("</listener-class>");
87          sb.append("</listener>");
88  
89          return sb.toString();
90      }
91  
92  }