001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.deploy.auto.exploded.tomcat;
016    
017    import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.util.Portal;
021    
022    import java.io.File;
023    
024    /**
025     * @author Olaf Fricke
026     * @author Brian Wing Shun Chan
027     */
028    public class PortletExplodedTomcatListener extends BaseExplodedTomcatListener {
029    
030            public PortletExplodedTomcatListener() {
031                    _deployer = new PortletExplodedTomcatDeployer();
032            }
033    
034            public void deploy(File file) throws AutoDeployException {
035                    if (_log.isDebugEnabled()) {
036                            _log.debug("Invoking deploy for " + file.getPath());
037                    }
038    
039                    ExplodedTomcatDeployer deployer = null;
040    
041                    File docBaseDir = getDocBaseDir(file, "index.php");
042    
043                    if (docBaseDir != null) {
044                            deployer = getPhpDeployer();
045                    }
046                    else {
047                            docBaseDir = getDocBaseDir(
048                                    file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD);
049    
050                            if (docBaseDir != null) {
051                                    deployer = _deployer;
052                            }
053                            else {
054                                    return;
055                            }
056                    }
057    
058                    if (_log.isInfoEnabled()) {
059                            _log.info("Modifying portlets for " + file.getPath());
060                    }
061    
062                    deployer.explodedTomcatDeploy(file, docBaseDir, null);
063    
064                    if (_log.isInfoEnabled()) {
065                            _log.info(
066                                    "Portlets for " + file.getPath() + " modified successfully");
067                    }
068    
069                    copyContextFile(file);
070            }
071    
072            protected ExplodedTomcatDeployer getPhpDeployer()
073                    throws AutoDeployException {
074    
075                    if (_phpDeployer == null) {
076                            _phpDeployer = new PHPPortletExplodedTomcatDeployer();
077                    }
078    
079                    return _phpDeployer;
080            }
081    
082            private static Log _log = LogFactoryUtil.getLog(
083                    PortletExplodedTomcatListener.class);
084    
085            private ExplodedTomcatDeployer _deployer;
086            private PHPPortletExplodedTomcatDeployer _phpDeployer;
087    
088    }