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;
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.deploy.auto.BaseAutoDeployListener;
020    import com.liferay.portal.kernel.deploy.auto.context.AutoDeploymentContext;
021    import com.liferay.portal.kernel.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    
024    import java.io.File;
025    
026    /**
027     * @author Ivica Cardic
028     * @author Brian Wing Shun Chan
029     */
030    public class LayoutTemplateAutoDeployListener extends BaseAutoDeployListener {
031    
032            public LayoutTemplateAutoDeployListener() {
033                    _autoDeployer = new LayoutTemplateAutoDeployer();
034            }
035    
036            @Override
037            public int deploy(AutoDeploymentContext autoDeploymentContext)
038                    throws AutoDeployException {
039    
040                    File file = autoDeploymentContext.getFile();
041    
042                    if (_log.isDebugEnabled()) {
043                            _log.debug("Invoking deploy for " + file.getPath());
044                    }
045    
046                    if (!isMatchingFile(file, "WEB-INF/liferay-layout-templates.xml")) {
047                            return AutoDeployer.CODE_NOT_APPLICABLE;
048                    }
049    
050                    if (_log.isInfoEnabled()) {
051                            _log.info("Copying layout templates for " + file.getPath());
052                    }
053    
054                    int code = _autoDeployer.autoDeploy(autoDeploymentContext);
055    
056                    if ((code == AutoDeployer.CODE_DEFAULT) && _log.isInfoEnabled()) {
057                            _log.info(
058                                    "Layout templates for " + file.getPath() +
059                                            " copied successfully. Deployment will start in a few " +
060                                                    "seconds.");
061                    }
062    
063                    return code;
064            }
065    
066            private static Log _log = LogFactoryUtil.getLog(
067                    LayoutTemplateAutoDeployListener.class);
068    
069            private AutoDeployer _autoDeployer;
070    
071    }