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 Gregory Amerson
027     */
028    public class HookExplodedTomcatListener extends BaseExplodedTomcatListener {
029    
030            public HookExplodedTomcatListener() {
031                    _deployer = new HookExplodedTomcatDeployer();
032            }
033    
034            @Override
035            protected int deploy(File file) throws AutoDeployException {
036                    if (_log.isDebugEnabled()) {
037                            _log.debug("Invoking deploy for " + file.getPath());
038                    }
039    
040                    File docBaseDir = getDocBaseDir(
041                            file, "WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_STANDARD);
042    
043                    if (docBaseDir != null) {
044                            return AutoDeployer.CODE_NOT_APPLICABLE;
045                    }
046    
047                    docBaseDir = getDocBaseDir(file, "WEB-INF/liferay-hook.xml");
048    
049                    if (docBaseDir == null) {
050                            return AutoDeployer.CODE_NOT_APPLICABLE;
051                    }
052    
053                    if (_log.isInfoEnabled()) {
054                            _log.info("Modifying hook for " + file.getPath());
055                    }
056    
057                    _deployer.explodedTomcatDeploy(file, docBaseDir, null);
058    
059                    if (_log.isInfoEnabled()) {
060                            _log.info("Hook for " + file.getPath() + " modified successfully");
061                    }
062    
063                    copyContextFile(file);
064    
065                    return AutoDeployer.CODE_DEFAULT;
066            }
067    
068            private static Log _log = LogFactoryUtil.getLog(
069                    HookExplodedTomcatListener.class);
070    
071            private ExplodedTomcatDeployer _deployer;
072    
073    }