001    /**
002     * Copyright (c) 2000-2010 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;
016    
017    import com.liferay.portal.kernel.deploy.auto.AutoDeployException;
018    import com.liferay.portal.kernel.deploy.auto.BaseAutoDeployListener;
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 Ivica Cardic
027     * @author Brian Wing Shun Chan
028     * @author Jorge Ferrer
029     */
030    public class PortletAutoDeployListener extends BaseAutoDeployListener {
031    
032            public PortletAutoDeployListener() {
033                    _deployer = new PortletAutoDeployer();
034            }
035    
036            public void deploy(File file) throws AutoDeployException {
037                    if (_log.isDebugEnabled()) {
038                            _log.debug("Invoking deploy for " + file.getPath());
039                    }
040    
041                    AutoDeployer deployer = null;
042    
043                    if (isMatchingFile(
044                                    file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD)) {
045    
046                            deployer = _deployer;
047                    }
048                    else if (isMatchingFile(file, "index_mvc.jsp")) {
049                            deployer = getMvcDeployer();
050                    }
051                    else if (isMatchingFile(file, "index.php")) {
052                            deployer = getPhpDeployer();
053                    }
054                    else if (!isExtPlugin(file) && !isHookPlugin(file) &&
055                                     !isMatchingFile(
056                                            file, "WEB-INF/liferay-layout-templates.xml") &&
057                                     !isThemePlugin(file) && !isWebPlugin(file) &&
058                                     file.getName().endsWith(".war")) {
059    
060                            if (_log.isInfoEnabled()) {
061                                    _log.info("Deploying package as a web application");
062                            }
063    
064                            deployer = getWaiDeployer();
065                    }
066                    else {
067                            return;
068                    }
069    
070                    if (_log.isInfoEnabled()) {
071                            _log.info("Copying portlets for " + file.getPath());
072                    }
073    
074                    if (_log.isDebugEnabled()) {
075                            _log.debug("Using deployer " + deployer.getClass().getName());
076                    }
077    
078                    deployer.autoDeploy(file.getName());
079    
080                    if (_log.isInfoEnabled()) {
081                            _log.info(
082                                    "Portlets for " + file.getPath() + " copied successfully. " +
083                                            "Deployment will start in a few seconds.");
084                    }
085            }
086    
087            protected AutoDeployer getMvcDeployer() {
088                    if (_mvcDeployer == null) {
089                            _mvcDeployer = new MVCPortletAutoDeployer();
090                    }
091    
092                    return _mvcDeployer;
093            }
094    
095            protected AutoDeployer getPhpDeployer() throws AutoDeployException {
096                    if (_phpDeployer == null) {
097                            _phpDeployer = new PHPPortletAutoDeployer();
098                    }
099    
100                    return _phpDeployer;
101            }
102    
103            protected AutoDeployer getWaiDeployer() throws AutoDeployException {
104                    if (_waiDeployer == null) {
105                            _waiDeployer = new WAIAutoDeployer();
106                    }
107    
108                    return _waiDeployer;
109            }
110    
111            private static Log _log = LogFactoryUtil.getLog(
112                    PortletAutoDeployListener.class);
113    
114            private AutoDeployer _deployer;
115            private MVCPortletAutoDeployer _mvcDeployer;
116            private PHPPortletAutoDeployer _phpDeployer;
117            private WAIAutoDeployer _waiDeployer;
118    
119    }