com.ice.util
Class FormatResourceBundle

java.lang.Object
  |
  +--java.util.ResourceBundle
        |
        +--com.ice.util.FormatResourceBundle

public class FormatResourceBundle
extends java.util.ResourceBundle


Field Summary
 
Fields inherited from class java.util.ResourceBundle
parent
 
Constructor Summary
FormatResourceBundle(java.util.ResourceBundle bundle)
          Construct a new FormatResourceBundle by encapsulating another ResourceBundle object which is the actual bundle.
 
Method Summary
static void addAlias(java.lang.String alias, java.lang.String baseName)
          Add a resource name alias.
static FormatResourceBundle getFormatBundle(java.lang.String baseName)
          Get a FormatResourceBundle.
static FormatResourceBundle getFormatBundle(java.lang.String baseName, java.util.Locale locale)
          Get a FormatResourceBundle.
 java.lang.String getFormatString(java.lang.String key, java.lang.Object[] args)
          Get a string from the resource bundle, and return the formatted version of the string using args.
 java.util.Enumeration getKeys()
          Return an enumeration of the resource keys.
 java.lang.String getString(java.lang.String key, java.lang.String defValue)
          This method simply extends the ResourceBundle's getString() with a method that allows a default value to be specified.
protected  java.lang.Object handleGetObject(java.lang.String key)
          Return an object identified by its key.
static void unCache(java.lang.String alias, java.lang.String baseName)
          This class method allows you to remove a bundle from the cache.
 
Methods inherited from class java.util.ResourceBundle
getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatResourceBundle

public FormatResourceBundle(java.util.ResourceBundle bundle)
Construct a new FormatResourceBundle by encapsulating another ResourceBundle object which is the actual bundle.

Parameters:
bundle - The resource bundle that we are encapsulating.
Method Detail

addAlias

public static void addAlias(java.lang.String alias,
                            java.lang.String baseName)
Add a resource name alias. This allows you to use shorter names for your resource bundles. For example:
 FormatResourceBundle.addAlias( "ui", "com.ice.mail.resources.ui" );
 ...
 FormatResourceBundle fmtBndl =
    FormatResourceBundle.getFormatBundle( "ui" );
 ...
 FormatResourceBundle.getFormatBundle( "ui" ).getString( "menuName" );
 
The alias will only work with the getFormatBundle() class methods in this class, and will not work with the other ResourceBundle getBundle() class methods.

Parameters:
alias - The alias by which you will refer to this resource bundle.
baseName - The actual resource name used to get the bundle.

unCache

public static void unCache(java.lang.String alias,
                           java.lang.String baseName)
This class method allows you to remove a bundle from the cache. This allows the bundle to be GC-ed.

Parameters:
baseName - The resource bundle's name or alias.

getFormatBundle

public static FormatResourceBundle getFormatBundle(java.lang.String baseName)
Get a FormatResourceBundle. This method actually calls ResourceBundle.getBundle(). However, first, the method substitutes any aliases added by the programmer, and second, the method wraps the retrieved ResourceBundle within a FormatResourceBundle adding the getFormatString() method to those already provided by ResourceBundle().

Parameters:
baseName - The name, or alias, of the bundle to get.
Returns:
The cached or a new FormatResource.

getFormatBundle

public static FormatResourceBundle getFormatBundle(java.lang.String baseName,
                                                   java.util.Locale locale)
Get a FormatResourceBundle. This method is identical to getFormatBundle( String baseName ), except that it takes an additional locale parameter.

Parameters:
baseName - The name, or alias, of the bundle to get.
locale - The locale to use in locating the bundle.
Returns:
The cached or a new FormatResource.

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defValue)
This method simply extends the ResourceBundle's getString() with a method that allows a default value to be specified.

Parameters:
key - The key of the string resource to format.
defValue - The default value used if key not found.
Returns:
The resource string.

getFormatString

public java.lang.String getFormatString(java.lang.String key,
                                        java.lang.Object[] args)
Get a string from the resource bundle, and return the formatted version of the string using args. This method gets the resource string identified by key, then passes the string to the MessageFormat.format() as the format string, and passes args as the format arguments.

Parameters:
key - The key of the string resource to format.
args - The arguments to use to format the string.
Returns:
The formatted string.

getKeys

public java.util.Enumeration getKeys()
Return an enumeration of the resource keys. This method simply calls the same method of the resource bundle we are encapsulating.

Specified by:
getKeys in class java.util.ResourceBundle
Returns:
An enumeration of the resource keys.

handleGetObject

protected java.lang.Object handleGetObject(java.lang.String key)
Return an object identified by its key. This method simply calls the same method of the resource bundle we are encapsulating.

Specified by:
handleGetObject in class java.util.ResourceBundle
Parameters:
key - The key of the object to return.
Returns:
The object identified by the key.


Copyright © 1997-2003, Timothy G. Endres, All Rights Reserved.