001    /**
002     * Copyright (c) 2000-present 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.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 ThreadSafeAutoDeployer(
034                            new LayoutTemplateAutoDeployer());
035            }
036    
037            @Override
038            public int 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                    if (!isLayoutTemplatePlugin(file)) {
048                            return AutoDeployer.CODE_NOT_APPLICABLE;
049                    }
050    
051                    if (_log.isInfoEnabled()) {
052                            _log.info("Copying layout templates for " + file.getPath());
053                    }
054    
055                    int code = _autoDeployer.autoDeploy(autoDeploymentContext);
056    
057                    if ((code == AutoDeployer.CODE_DEFAULT) && _log.isInfoEnabled()) {
058                            _log.info(
059                                    "Layout templates for " + file.getPath() +
060                                            " copied successfully. Deployment will start in a few " +
061                                                    "seconds.");
062                    }
063    
064                    return code;
065            }
066    
067            private static final Log _log = LogFactoryUtil.getLog(
068                    LayoutTemplateAutoDeployListener.class);
069    
070            private final AutoDeployer _autoDeployer;
071    
072    }