001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.ui.web.facelets.vendor; 018 019import javax.faces.view.facelets.Facelet; 020import javax.faces.view.facelets.FaceletCache; 021import javax.faces.view.facelets.FaceletCacheFactory; 022 023import org.nuxeo.runtime.api.Framework; 024 025import com.sun.faces.config.WebConfiguration; 026 027/** 028 * Overrides the default JSF facelet cache factory to customize cache behaviour. 029 * 030 * @since 6.0 031 */ 032public class NXFaceletCacheFactory extends FaceletCacheFactory { 033 034 public NXFaceletCacheFactory() { 035 } 036 037 @Override 038 public FaceletCache<Facelet> getFaceletCache() { 039 WebConfiguration webConfig = WebConfiguration.getInstance(); 040 long period; 041 if (Framework.isInitialized() && Framework.isDevModeSet()) { 042 // force refreshPeriod to "2" when dev mode is set 043 period = 2 * 1000; 044 } else { 045 String refreshPeriod = webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.FaceletsDefaultRefreshPeriod); 046 period = Long.parseLong(refreshPeriod) * 1000; 047 } 048 FaceletCache<Facelet> result = new DefaultFaceletCache(period); 049 return result; 050 } 051 052}