001    /**
002     * Copyright (c) 2000-2012 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            @Override
035            protected void deploy(File file) throws AutoDeployException {
036                    if (_log.isDebugEnabled()) {
037                            _log.debug("Invoking deploy for " + file.getPath());
038                    }
039    
040                    ExplodedTomcatDeployer deployer = null;
041    
042                    File docBaseDir = getDocBaseDir(file, "index.php");
043    
044                    if (docBaseDir != null) {
045                            deployer = getPhpDeployer();
046                    }
047                    else {
048                            docBaseDir = getDocBaseDir(
049                                    file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD);
050    
051                            if (docBaseDir != null) {
052                                    deployer = _deployer;
053                            }
054                            else {
055                                    return;
056                            }
057                    }
058    
059                    if (_log.isInfoEnabled()) {
060                            _log.info("Modifying portlets for " + file.getPath());
061                    }
062    
063                    deployer.explodedTomcatDeploy(file, docBaseDir, null);
064    
065                    if (_log.isInfoEnabled()) {
066                            _log.info(
067                                    "Portlets for " + file.getPath() + " modified successfully");
068                    }
069    
070                    copyContextFile(file);
071            }
072    
073            protected ExplodedTomcatDeployer getPhpDeployer()
074                    throws AutoDeployException {
075    
076                    if (_phpDeployer == null) {
077                            _phpDeployer = new PHPPortletExplodedTomcatDeployer();
078                    }
079    
080                    return _phpDeployer;
081            }
082    
083            private static Log _log = LogFactoryUtil.getLog(
084                    PortletExplodedTomcatListener.class);
085    
086            private ExplodedTomcatDeployer _deployer;
087            private PHPPortletExplodedTomcatDeployer _phpDeployer;
088    
089    }