001    /**
002     * Copyright (c) 2000-2013 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.deploy.auto.AutoDeployer;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.util.Portal;
022    
023    import java.io.File;
024    
025    /**
026     * @author Olaf Fricke
027     * @author Brian Wing Shun Chan
028     */
029    public class PortletExplodedTomcatListener extends BaseExplodedTomcatListener {
030    
031            public PortletExplodedTomcatListener() {
032                    _deployer = new PortletExplodedTomcatDeployer();
033            }
034    
035            @Override
036            protected int deploy(File file) throws AutoDeployException {
037                    if (_log.isDebugEnabled()) {
038                            _log.debug("Invoking deploy for " + file.getPath());
039                    }
040    
041                    ExplodedTomcatDeployer deployer = null;
042    
043                    File docBaseDir = getDocBaseDir(file, "index.php");
044    
045                    if (docBaseDir != null) {
046                            deployer = getPhpDeployer();
047                    }
048                    else {
049                            docBaseDir = getDocBaseDir(
050                                    file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD);
051    
052                            if (docBaseDir != null) {
053                                    deployer = _deployer;
054                            }
055                            else {
056                                    return AutoDeployer.CODE_NOT_APPLICABLE;
057                            }
058                    }
059    
060                    if (_log.isInfoEnabled()) {
061                            _log.info("Modifying portlets for " + file.getPath());
062                    }
063    
064                    deployer.explodedTomcatDeploy(file, docBaseDir, null);
065    
066                    if (_log.isInfoEnabled()) {
067                            _log.info(
068                                    "Portlets for " + file.getPath() + " modified successfully");
069                    }
070    
071                    copyContextFile(file);
072    
073                    return AutoDeployer.CODE_DEFAULT;
074            }
075    
076            protected ExplodedTomcatDeployer getPhpDeployer()
077                    throws AutoDeployException {
078    
079                    if (_phpDeployer == null) {
080                            _phpDeployer = new PHPPortletExplodedTomcatDeployer();
081                    }
082    
083                    return _phpDeployer;
084            }
085    
086            private static Log _log = LogFactoryUtil.getLog(
087                    PortletExplodedTomcatListener.class);
088    
089            private ExplodedTomcatDeployer _deployer;
090            private PHPPortletExplodedTomcatDeployer _phpDeployer;
091    
092    }