001/* 002 * (C) Copyright 2012 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.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.webapp.seam.messages; 018 019import java.io.IOException; 020import java.io.Serializable; 021import java.util.Locale; 022import java.util.ResourceBundle; 023 024import org.jboss.seam.Component; 025import org.jboss.seam.ScopeType; 026import org.jboss.seam.annotations.AutoCreate; 027import org.jboss.seam.annotations.Name; 028import org.jboss.seam.annotations.Scope; 029import org.jboss.seam.annotations.intercept.BypassInterceptors; 030import org.nuxeo.runtime.api.Framework; 031import org.nuxeo.runtime.reload.ReloadService; 032 033/** 034 * Resource bundle controller for Seam. 035 * <p> 036 * Handles hot reload of resources when in dev mode, relying on the {@link ReloadService#flush()} method to be called 037 * when needing to flush messages. 038 * 039 * @since 5.6 040 */ 041@Name("nxHotReloadResourceBundleControl") 042@BypassInterceptors 043@Scope(ScopeType.SESSION) 044@AutoCreate 045public class HotReloadResourceBundleControl extends ResourceBundle.Control implements Serializable { 046 047 private static final long serialVersionUID = 1L; 048 049 protected long timeToLive = ResourceBundle.Control.TTL_NO_EXPIRATION_CONTROL; 050 051 public static HotReloadResourceBundleControl instance() { 052 return (HotReloadResourceBundleControl) Component.getInstance(HotReloadResourceBundleControl.class, true); 053 } 054 055 @Override 056 public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) 057 throws IllegalAccessException, InstantiationException, IOException { 058 // force reload if debug mode is set 059 return super.newBundle(baseName, locale, format, loader, Framework.isDevModeSet()); 060 } 061 062}