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 static org.jboss.seam.annotations.Install.APPLICATION; 020 021import java.util.MissingResourceException; 022import java.util.ResourceBundle; 023 024import org.jboss.seam.ScopeType; 025import org.jboss.seam.annotations.Install; 026import org.jboss.seam.annotations.Name; 027import org.jboss.seam.annotations.Scope; 028import org.jboss.seam.annotations.intercept.BypassInterceptors; 029import org.jboss.seam.core.Locale; 030import org.jboss.seam.core.ResourceLoader; 031import org.jboss.seam.log.LogProvider; 032import org.jboss.seam.log.Logging; 033 034/** 035 * Overriden to add a control over reload of bundle for hot reload 036 * 037 * @since 5.6 038 */ 039@Scope(ScopeType.STATELESS) 040@BypassInterceptors 041@Name("org.jboss.seam.core.resourceLoader") 042// XXX: since debug mode cannot be set by using nuxeo debug/dev mode, make 043// sure this component is deployed even in production => debug = false 044@Install(precedence = APPLICATION, debug = false) 045public class HotReloadResourceLoader extends ResourceLoader { 046 047 private static final LogProvider log = Logging.getLogProvider(HotReloadResourceLoader.class); 048 049 @Override 050 public ResourceBundle loadBundle(String bundleName) { 051 try { 052 ResourceBundle.Control control = HotReloadResourceBundleControl.instance(); 053 ResourceBundle bundle = ResourceBundle.getBundle(bundleName, Locale.instance(), 054 Thread.currentThread().getContextClassLoader(), control); 055 log.debug("loaded resource bundle: " + bundleName); 056 return bundle; 057 } catch (MissingResourceException mre) { 058 log.debug("resource bundle missing: " + bundleName); 059 return null; 060 } 061 } 062}