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