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.exploded.tomcat;
16  
17  import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
18  import com.liferay.portal.kernel.log.Log;
19  import com.liferay.portal.kernel.log.LogFactoryUtil;
20  import com.liferay.portal.kernel.util.ServerDetector;
21  import com.liferay.portal.util.Portal;
22  
23  import java.io.File;
24  
25  /**
26   * <a href="PortletExplodedTomcatListener.java.html"><b><i>View Source</i></b>
27   * </a>
28   *
29   * @author Olaf Fricke
30   * @author Brian Wing Shun Chan
31   */
32  public class PortletExplodedTomcatListener extends BaseExplodedTomcatListener {
33  
34      public PortletExplodedTomcatListener() {
35          _deployer = new PortletExplodedTomcatDeployer();
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          ExplodedTomcatDeployer deployer = null;
44  
45          File docBaseDir = getDocBaseDir(file, "index.php");
46  
47          if (docBaseDir != null) {
48              deployer = getPhpDeployer();
49          }
50          else {
51              docBaseDir = getDocBaseDir(
52                  file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD);
53  
54              if (docBaseDir != null) {
55                  deployer = _deployer;
56              }
57              else {
58                  return;
59              }
60          }
61  
62          if (_log.isInfoEnabled()) {
63              _log.info("Modifying portlets for " + file.getPath());
64          }
65  
66          deployer.explodedTomcatDeploy(file, docBaseDir, null);
67  
68          if (_log.isInfoEnabled()) {
69              _log.info(
70                  "Portlets for " + file.getPath() + " modified successfully");
71          }
72  
73          if (ServerDetector.isTomcat() && !ServerDetector.isGlassfish()) {
74              copyContextFile(file);
75          }
76      }
77  
78      protected ExplodedTomcatDeployer getPhpDeployer()
79          throws AutoDeployException {
80  
81          if (_phpDeployer == null) {
82              _phpDeployer = new PHPPortletExplodedTomcatDeployer();
83          }
84  
85          return _phpDeployer;
86      }
87  
88      private static Log _log = LogFactoryUtil.getLog(
89          PortletExplodedTomcatListener.class);
90  
91      private ExplodedTomcatDeployer _deployer;
92      private PHPPortletExplodedTomcatDeployer _phpDeployer;
93  
94  }