001/* 002 * (C) Copyright 2014 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.platform.ui.web.facelets.vendor; 020 021import javax.faces.view.facelets.Facelet; 022import javax.faces.view.facelets.FaceletCache; 023import javax.faces.view.facelets.FaceletCacheFactory; 024 025import org.nuxeo.runtime.api.Framework; 026 027import com.sun.faces.config.WebConfiguration; 028 029/** 030 * Overrides the default JSF facelet cache factory to customize cache behaviour. 031 * 032 * @since 6.0 033 */ 034public class NXFaceletCacheFactory extends FaceletCacheFactory { 035 036 public NXFaceletCacheFactory() { 037 } 038 039 @Override 040 public FaceletCache<Facelet> getFaceletCache() { 041 WebConfiguration webConfig = WebConfiguration.getInstance(); 042 long period; 043 if (Framework.isInitialized() && Framework.isDevModeSet()) { 044 // force refreshPeriod to "2" when dev mode is set 045 period = 2 * 1000; 046 } else { 047 String refreshPeriod = webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.FaceletsDefaultRefreshPeriod); 048 period = Long.parseLong(refreshPeriod) * 1000; 049 } 050 FaceletCache<Facelet> result = new DefaultFaceletCache(period); 051 return result; 052 } 053 054}