001    /**
002     * Copyright (c) 2000-2013 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.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    }