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