1 17 package org.alfresco.web.app; 18 19 import java.util.Enumeration ; 20 import java.util.Locale ; 21 import java.util.MissingResourceException ; 22 import java.util.ResourceBundle ; 23 24 import org.alfresco.error.AlfrescoRuntimeException; 25 import org.apache.log4j.Logger; 26 import org.apache.log4j.Priority; 27 28 34 public final class ResourceBundleWrapper extends ResourceBundle 35 { 36 private static Logger logger = Logger.getLogger(ResourceBundleWrapper.class); 37 38 private ResourceBundle delegate; 39 40 45 private ResourceBundleWrapper(ResourceBundle bundle) 46 { 47 this.delegate = bundle; 48 } 49 50 53 public Enumeration <String > getKeys() 54 { 55 return this.delegate.getKeys(); 56 } 57 58 61 protected Object handleGetObject(String key) 62 { 63 try 64 { 65 return this.delegate.getObject(key); 66 } 67 catch (MissingResourceException err) 68 { 69 if (logger.isEnabledFor(Priority.WARN)) 70 logger.warn("Failed to find I18N message string key: " + key); 71 72 return "$$" + key + "$$"; 73 } 74 } 75 76 84 public static ResourceBundle getResourceBundle(String name, Locale locale) 85 { 86 ResourceBundle bundle = ResourceBundle.getBundle(name, locale); 87 if (bundle == null) 88 { 89 throw new AlfrescoRuntimeException("Unable to load Alfresco messages bundle: " + name); 90 } 91 92 return new ResourceBundleWrapper(bundle); 94 } 95 } 96 | Popular Tags |