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