1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.deploy.auto;
16  
17  import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
18  import com.liferay.portal.kernel.deploy.auto.BaseAutoDeployListener;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.util.Portal;
22  
23  import java.io.File;
24  
25  /**
26   * <a href="PortletAutoDeployListener.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Ivica Cardic
29   * @author Brian Wing Shun Chan
30   * @author Jorge Ferrer
31   */
32  public class PortletAutoDeployListener extends BaseAutoDeployListener {
33  
34      public PortletAutoDeployListener() {
35          _deployer = new PortletAutoDeployer();
36      }
37  
38      public void deploy(File file) throws AutoDeployException {
39          if (_log.isDebugEnabled()) {
40              _log.debug("Invoking deploy for " + file.getPath());
41          }
42  
43          AutoDeployer deployer = null;
44  
45          if (isMatchingFile(
46                  file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD)) {
47  
48              deployer = _deployer;
49          }
50          else if (isMatchingFile(file, "index_mvc.jsp")) {
51              deployer = getMvcDeployer();
52          }
53          else if (isMatchingFile(file, "index.php")) {
54              deployer = getPhpDeployer();
55          }
56          else if (!isExtPlugin(file) && !isHookPlugin(file) &&
57                   !isMatchingFile(
58                      file, "WEB-INF/liferay-layout-templates.xml") &&
59                   !isThemePlugin(file) && !isWebPlugin(file) &&
60                   file.getName().endsWith(".war")) {
61  
62              if (_log.isInfoEnabled()) {
63                  _log.info("Deploying package as a web application");
64              }
65  
66              deployer = getWaiDeployer();
67          }
68          else {
69              return;
70          }
71  
72          if (_log.isInfoEnabled()) {
73              _log.info("Copying portlets for " + file.getPath());
74          }
75  
76          if (_log.isDebugEnabled()) {
77              _log.debug("Using deployer " + deployer.getClass().getName());
78          }
79  
80          deployer.autoDeploy(file.getName());
81  
82          if (_log.isInfoEnabled()) {
83              _log.info(
84                  "Portlets for " + file.getPath() + " copied successfully. " +
85                      "Deployment will start in a few seconds.");
86          }
87      }
88  
89      protected AutoDeployer getMvcDeployer() {
90          if (_mvcDeployer == null) {
91              _mvcDeployer = new MVCPortletAutoDeployer();
92          }
93  
94          return _mvcDeployer;
95      }
96  
97      protected AutoDeployer getPhpDeployer() throws AutoDeployException {
98          if (_phpDeployer == null) {
99              _phpDeployer = new PHPPortletAutoDeployer();
100         }
101 
102         return _phpDeployer;
103     }
104 
105     protected AutoDeployer getWaiDeployer() throws AutoDeployException {
106         if (_waiDeployer == null) {
107             _waiDeployer = new WAIAutoDeployer();
108         }
109 
110         return _waiDeployer;
111     }
112 
113     private static Log _log = LogFactoryUtil.getLog(
114         PortletAutoDeployListener.class);
115 
116     private AutoDeployer _deployer;
117     private MVCPortletAutoDeployer _mvcDeployer;
118     private PHPPortletAutoDeployer _phpDeployer;
119     private WAIAutoDeployer _waiDeployer;
120 
121 }