org.radeox.util.i18n
Class ResourceManager

java.lang.Object
  extended by org.radeox.util.i18n.ResourceManager

public class ResourceManager
extends java.lang.Object

A Resource Manager implementation to aid the use of locales. It works similar to what the bundle tag in jstl fmt taglibs does but adapted for use withing a threaded java environment.


Constructor Summary
ResourceManager()
           
 
Method Summary
static ResourceManager forceGet()
          Thread re-use makes your life hard.
static ResourceManager get()
          Get a new thread-local instance of the ResourceManager If you are having problems with bundles beeing the same for different threads and locales, try forceGet()
static java.util.ResourceBundle getBundle(java.lang.String baseName)
          Get ResourceBundle using the base name provided.
static java.util.Locale getLocale(java.lang.String baseName)
          Get the locale of the loaded bundle.
 java.util.ResourceBundle getResourceBundle(java.lang.String baseName)
          Get the bundle that is active for this thread.
static java.lang.String getString(java.lang.String baseName, java.lang.String key)
           
 void setLocale(java.util.Locale locale, java.util.Enumeration fallback)
          Set the locale and potential fallbacks for this thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceManager

public ResourceManager()
Method Detail

forceGet

public static ResourceManager forceGet()
Thread re-use makes your life hard. If you suspect leakage of locale and bundles into other threads, using forceGet() may be a good choice.

Returns:
a new instance of the ResourceManager

get

public static ResourceManager get()
Get a new thread-local instance of the ResourceManager If you are having problems with bundles beeing the same for different threads and locales, try forceGet()

Returns:
the thread-local ResourceManager

getBundle

public static java.util.ResourceBundle getBundle(java.lang.String baseName)
Get ResourceBundle using the base name provided. The bundle is located using previously given locale settings.

Parameters:
baseName - the bundle base name
Returns:
the bundle

getLocale

public static java.util.Locale getLocale(java.lang.String baseName)
Get the locale of the loaded bundle. This is the actual locale of the bundle, not the locale requested.

Parameters:
baseName - the bundle base name
Returns:
the locale of the bundle

getString

public static java.lang.String getString(java.lang.String baseName,
                                         java.lang.String key)

setLocale

public void setLocale(java.util.Locale locale,
                      java.util.Enumeration fallback)
Set the locale and potential fallbacks for this thread.

Parameters:
locale - the requested locale
fallback - a set of fallback locales, i.e. request.getLocales()

getResourceBundle

public java.util.ResourceBundle getResourceBundle(java.lang.String baseName)
Get the bundle that is active for this thread. This is done by loading either the specified locale based resource bundle and, if that fails, by looping through the fallback locales to locate a usable bundle.

Returns:
the resource bundle