001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Anahide Tchertchian
018 */
019package org.nuxeo.ecm.web.resources.wro.servlet;
020
021import org.apache.commons.logging.Log;
022import org.apache.commons.logging.LogFactory;
023import org.nuxeo.ecm.web.resources.wro.factory.NuxeoWroManagerFactory;
024import org.nuxeo.runtime.api.Framework;
025
026import ro.isdc.wro.config.jmx.WroConfiguration;
027import ro.isdc.wro.http.WroServletContextListener;
028import ro.isdc.wro.manager.factory.WroManagerFactory;
029
030/**
031 * Servlet context listener initiating wro debug mode on runtime dev mode, and hooking up the specific
032 * {@link NuxeoWroManagerFactory}.
033 *
034 * @since 7.3
035 */
036public class NuxeoWroServletContextListener extends WroServletContextListener {
037
038    private static final Log log = LogFactory.getLog(NuxeoWroServletContextListener.class);
039
040    public NuxeoWroServletContextListener() {
041        super();
042    }
043
044    @Override
045    protected String getListenerName() {
046        return "bundle";
047    }
048
049    @Override
050    protected WroManagerFactory newManagerFactory() {
051        return new NuxeoWroManagerFactory();
052    }
053
054    @Override
055    protected WroConfiguration newConfiguration() {
056        WroConfiguration conf = new WroConfiguration();
057        conf.setIgnoreMissingResources(false);
058        if (Framework.isDevModeSet()) {
059            if (log.isDebugEnabled()) {
060                log.debug("Set wro debug configuration");
061            }
062            conf.setDebug(true);
063            conf.setMinimizeEnabled(false);
064            conf.setCacheUpdatePeriod(2);
065            conf.setModelUpdatePeriod(2);
066        } else {
067            conf.setDebug(false);
068        }
069        return conf;
070    }
071
072}