001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }