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.log.Log;
27  import com.liferay.portal.kernel.log.LogFactoryUtil;
28  import com.liferay.portal.util.Portal;
29  
30  import java.io.File;
31  
32  /**
33   * <a href="PortletAutoDeployListener.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Ivica Cardic
36   * @author Brian Wing Shun Chan
37   * @author Jorge Ferrer
38   */
39  public class PortletAutoDeployListener extends BaseAutoDeployListener {
40  
41      public PortletAutoDeployListener() {
42          _deployer = new PortletAutoDeployer();
43      }
44  
45      public void deploy(File file) throws AutoDeployException {
46          if (_log.isDebugEnabled()) {
47              _log.debug("Invoking deploy for " + file.getPath());
48          }
49  
50          AutoDeployer deployer = null;
51  
52          if (isMatchingFile(
53                  file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD)) {
54  
55              deployer = _deployer;
56          }
57          else if (isMatchingFile(file, "index_mvc.jsp")) {
58              deployer = getMvcDeployer();
59          }
60          else if (isMatchingFile(file, "index.php")) {
61              deployer = getPhpDeployer();
62          }
63          else if (!isHookPlugin(file) &&
64                   !isMatchingFile(
65                      file, "WEB-INF/liferay-layout-templates.xml") &&
66                   !isThemePlugin(file) && !isWebPlugin(file)) {
67  
68              if (_log.isInfoEnabled()) {
69                  _log.info("Deploying package as a web application");
70              }
71  
72              deployer = getWaiDeployer();
73          }
74          else {
75              return;
76          }
77  
78          if (_log.isInfoEnabled()) {
79              _log.info("Copying portlets for " + file.getPath());
80          }
81  
82          if (_log.isDebugEnabled()) {
83              _log.debug("Using deployer " + deployer.getClass().getName());
84          }
85  
86          deployer.autoDeploy(file.getName());
87  
88          if (_log.isInfoEnabled()) {
89              _log.info(
90                  "Portlets for " + file.getPath() + " copied successfully. " +
91                      "Deployment will start in a few seconds.");
92          }
93      }
94  
95      protected AutoDeployer getMvcDeployer() {
96          if (_mvcDeployer == null) {
97              _mvcDeployer = new MVCPortletAutoDeployer();
98          }
99  
100         return _mvcDeployer;
101     }
102 
103     protected AutoDeployer getPhpDeployer() throws AutoDeployException {
104         if (_phpDeployer == null) {
105             _phpDeployer = new PHPPortletAutoDeployer();
106         }
107 
108         return _phpDeployer;
109     }
110 
111     protected AutoDeployer getWaiDeployer() throws AutoDeployException {
112         if (_waiDeployer == null) {
113             _waiDeployer = new WAIAutoDeployer();
114         }
115 
116         return _waiDeployer;
117     }
118 
119     private static Log _log =
120         LogFactoryUtil.getLog(PortletAutoDeployListener.class);
121 
122     private AutoDeployer _deployer;
123     private MVCPortletAutoDeployer _mvcDeployer;
124     private PHPPortletAutoDeployer _phpDeployer;
125     private WAIAutoDeployer _waiDeployer;
126 
127 }