1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.deploy.auto.BaseAutoDeployListener;
27  import com.liferay.portal.kernel.log.Log;
28  import com.liferay.portal.kernel.log.LogFactoryUtil;
29  import com.liferay.portal.util.Portal;
30  
31  import java.io.File;
32  
33  /**
34   * <a href="PortletAutoDeployListener.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Ivica Cardic
37   * @author Brian Wing Shun Chan
38   * @author Jorge Ferrer
39   */
40  public class PortletAutoDeployListener extends BaseAutoDeployListener {
41  
42      public PortletAutoDeployListener() {
43          _deployer = new PortletAutoDeployer();
44      }
45  
46      public void deploy(File file) throws AutoDeployException {
47          if (_log.isDebugEnabled()) {
48              _log.debug("Invoking deploy for " + file.getPath());
49          }
50  
51          AutoDeployer deployer = null;
52  
53          if (isMatchingFile(
54                  file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD)) {
55  
56              deployer = _deployer;
57          }
58          else if (isMatchingFile(file, "index_mvc.jsp")) {
59              deployer = getMvcDeployer();
60          }
61          else if (isMatchingFile(file, "index.php")) {
62              deployer = getPhpDeployer();
63          }
64          else if (!isExtPlugin(file) && !isHookPlugin(file) &&
65                   !isMatchingFile(
66                      file, "WEB-INF/liferay-layout-templates.xml") &&
67                   !isThemePlugin(file) && !isWebPlugin(file) &&
68                   file.getName().endsWith(".war")) {
69  
70              if (_log.isInfoEnabled()) {
71                  _log.info("Deploying package as a web application");
72              }
73  
74              deployer = getWaiDeployer();
75          }
76          else {
77              return;
78          }
79  
80          if (_log.isInfoEnabled()) {
81              _log.info("Copying portlets for " + file.getPath());
82          }
83  
84          if (_log.isDebugEnabled()) {
85              _log.debug("Using deployer " + deployer.getClass().getName());
86          }
87  
88          deployer.autoDeploy(file.getName());
89  
90          if (_log.isInfoEnabled()) {
91              _log.info(
92                  "Portlets for " + file.getPath() + " copied successfully. " +
93                      "Deployment will start in a few seconds.");
94          }
95      }
96  
97      protected AutoDeployer getMvcDeployer() {
98          if (_mvcDeployer == null) {
99              _mvcDeployer = new MVCPortletAutoDeployer();
100         }
101 
102         return _mvcDeployer;
103     }
104 
105     protected AutoDeployer getPhpDeployer() throws AutoDeployException {
106         if (_phpDeployer == null) {
107             _phpDeployer = new PHPPortletAutoDeployer();
108         }
109 
110         return _phpDeployer;
111     }
112 
113     protected AutoDeployer getWaiDeployer() throws AutoDeployException {
114         if (_waiDeployer == null) {
115             _waiDeployer = new WAIAutoDeployer();
116         }
117 
118         return _waiDeployer;
119     }
120 
121     private static Log _log =
122         LogFactoryUtil.getLog(PortletAutoDeployListener.class);
123 
124     private AutoDeployer _deployer;
125     private MVCPortletAutoDeployer _mvcDeployer;
126     private PHPPortletAutoDeployer _phpDeployer;
127     private WAIAutoDeployer _waiDeployer;
128 
129 }