net.dpml.i18n
Class Resources

java.lang.Object
  extended bynet.dpml.i18n.Resources

public class Resources
extends Object

A class to simplify extracting localized strings, icons and other common resources from a ResourceBundle. Reworked to mirror behaviour of StringManager from Tomcat (format() to getString()).

Version:
1.0.0
Author:
Digital Product Meta Library

Constructor Summary
Resources(String baseName)
          Constructor that builds a manager in default locale.
Resources(String baseName, ClassLoader classLoader)
          Constructor that builds a manager in default locale using specified ClassLoader.
Resources(String baseName, Locale locale)
          Constructor that builds a manager in specified locale.
Resources(String baseName, Locale locale, ClassLoader classLoader)
          Constructor that builds a manager in specified locale.
 
Method Summary
 String format(String key, Object[] args)
          Retrieve a string from resource bundle and format it with specified args.
 boolean getBoolean(String key)
          Retrieve a boolean from bundle.
 boolean getBoolean(String key, boolean defaultValue)
          Retrieve a boolean from bundle.
 ResourceBundle getBundle()
          Retrieve underlying ResourceBundle.
 byte getByte(String key)
          Retrieve a byte from bundle.
 byte getByte(String key, byte defaultValue)
          Retrieve a byte from bundle.
 char getChar(String key)
          Retrieve a char from bundle.
 char getChar(String key, char defaultValue)
          Retrieve a char from bundle.
 Date getDate(String key)
          Retrieve a date from bundle.
 Date getDate(String key, Date defaultValue)
          Retrieve a date from bundle.
 Date getDateTime(String key)
          Retrieve a date + time from bundle.
 Date getDateTime(String key, Date defaultValue)
          Retrieve a time from bundle.
 double getDouble(String key)
          Retrieve a double from bundle.
 double getDouble(String key, double defaultValue)
          Retrieve a double from bundle.
 float getFloat(String key)
          Retrieve a float from bundle.
 float getFloat(String key, float defaultValue)
          Retrieve a float from bundle.
 int getInteger(String key)
          Retrieve a integer from bundle.
 int getInteger(String key, int defaultValue)
          Retrieve a integer from bundle.
 long getLong(String key)
          Retrieve a long from bundle.
 long getLong(String key, long defaultValue)
          Retrieve a long from bundle.
 short getShort(String key)
          Retrieve a short from bundle.
 short getShort(String key, short defaultValue)
          Retrieve a short from bundle.
 String getString(String key)
          Retrieve a raw string from bundle.
 String getString(String key, Object arg1)
          Retrieve a string from resource bundle and format it with specified args.
 String getString(String key, Object arg1, Object arg2)
          Retrieve a string from resource bundle and format it with specified args.
 String getString(String key, Object arg1, Object arg2, Object arg3)
          Retrieve a string from resource bundle and format it with specified args.
 String getString(String key, Object arg1, Object arg2, Object arg3, Object arg4)
          Retrieve a string from resource bundle and format it with specified args.
 String getString(String key, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5)
          Retrieve a string from resource bundle and format it with specified args.
 String getString(String key, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6)
          Retrieve a string from resource bundle and format it with specified args.
 String getString(String key, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7)
          Retrieve a string from resource bundle and format it with specified args.
 Date getTime(String key)
          Retrieve a time from bundle.
 Date getTime(String key, Date defaultValue)
          Retrieve a time from bundle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resources

public Resources(String baseName)
Constructor that builds a manager in default locale.

Parameters:
baseName - the base name of ResourceBundle

Resources

public Resources(String baseName,
                 ClassLoader classLoader)
Constructor that builds a manager in default locale using specified ClassLoader.

Parameters:
baseName - the base name of ResourceBundle
classLoader - the classLoader to load ResourceBundle from

Resources

public Resources(String baseName,
                 Locale locale)
Constructor that builds a manager in specified locale.

Parameters:
baseName - the base name of ResourceBundle
locale - the Locale for resource bundle

Resources

public Resources(String baseName,
                 Locale locale,
                 ClassLoader classLoader)
Constructor that builds a manager in specified locale.

Parameters:
baseName - the base name of ResourceBundle
locale - the Locale for resource bundle
classLoader - the classLoader to load ResourceBundle from
Method Detail

getBoolean

public boolean getBoolean(String key,
                          boolean defaultValue)
                   throws MissingResourceException
Retrieve a boolean from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource boolean
Throws:
MissingResourceException - if the requested key is unknown

getBoolean

public boolean getBoolean(String key)
                   throws MissingResourceException
Retrieve a boolean from bundle.

Parameters:
key - the key of resource
Returns:
the resource boolean
Throws:
MissingResourceException - if the requested key is unknown

getByte

public byte getByte(String key,
                    byte defaultValue)
             throws MissingResourceException
Retrieve a byte from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource byte
Throws:
MissingResourceException - if the requested key is unknown

getByte

public byte getByte(String key)
             throws MissingResourceException
Retrieve a byte from bundle.

Parameters:
key - the key of resource
Returns:
the resource byte
Throws:
MissingResourceException - if the requested key is unknown

getChar

public char getChar(String key,
                    char defaultValue)
             throws MissingResourceException
Retrieve a char from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource char
Throws:
MissingResourceException - if the requested key is unknown

getChar

public char getChar(String key)
             throws MissingResourceException
Retrieve a char from bundle.

Parameters:
key - the key of resource
Returns:
the resource char
Throws:
MissingResourceException - if the requested key is unknown

getShort

public short getShort(String key,
                      short defaultValue)
               throws MissingResourceException
Retrieve a short from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource short
Throws:
MissingResourceException - if the requested key is unknown

getShort

public short getShort(String key)
               throws MissingResourceException
Retrieve a short from bundle.

Parameters:
key - the key of resource
Returns:
the resource short
Throws:
MissingResourceException - if the requested key is unknown

getInteger

public int getInteger(String key,
                      int defaultValue)
               throws MissingResourceException
Retrieve a integer from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource integer
Throws:
MissingResourceException - if the requested key is unknown

getInteger

public int getInteger(String key)
               throws MissingResourceException
Retrieve a integer from bundle.

Parameters:
key - the key of resource
Returns:
the resource integer
Throws:
MissingResourceException - if the requested key is unknown

getLong

public long getLong(String key,
                    long defaultValue)
             throws MissingResourceException
Retrieve a long from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource long
Throws:
MissingResourceException - if the requested key is unknown

getLong

public long getLong(String key)
             throws MissingResourceException
Retrieve a long from bundle.

Parameters:
key - the key of resource
Returns:
the resource long
Throws:
MissingResourceException - if the requested key is unknown

getFloat

public float getFloat(String key,
                      float defaultValue)
               throws MissingResourceException
Retrieve a float from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource float
Throws:
MissingResourceException - if the requested key is unknown

getFloat

public float getFloat(String key)
               throws MissingResourceException
Retrieve a float from bundle.

Parameters:
key - the key of resource
Returns:
the resource float
Throws:
MissingResourceException - if the requested key is unknown

getDouble

public double getDouble(String key,
                        double defaultValue)
                 throws MissingResourceException
Retrieve a double from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource double
Throws:
MissingResourceException - if the requested key is unknown

getDouble

public double getDouble(String key)
                 throws MissingResourceException
Retrieve a double from bundle.

Parameters:
key - the key of resource
Returns:
the resource double
Throws:
MissingResourceException - if the requested key is unknown

getDate

public Date getDate(String key,
                    Date defaultValue)
             throws MissingResourceException
Retrieve a date from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource date
Throws:
MissingResourceException - if the requested key is unknown

getDate

public Date getDate(String key)
             throws MissingResourceException
Retrieve a date from bundle.

Parameters:
key - the key of resource
Returns:
the resource date
Throws:
MissingResourceException - if the requested key is unknown

getTime

public Date getTime(String key,
                    Date defaultValue)
             throws MissingResourceException
Retrieve a time from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource time
Throws:
MissingResourceException - if the requested key is unknown

getTime

public Date getTime(String key)
             throws MissingResourceException
Retrieve a time from bundle.

Parameters:
key - the key of resource
Returns:
the resource time
Throws:
MissingResourceException - if the requested key is unknown

getDateTime

public Date getDateTime(String key,
                        Date defaultValue)
                 throws MissingResourceException
Retrieve a time from bundle.

Parameters:
key - the key of resource
defaultValue - the default value if key is missing
Returns:
the resource time
Throws:
MissingResourceException - if the requested key is unknown

getDateTime

public Date getDateTime(String key)
                 throws MissingResourceException
Retrieve a date + time from bundle.

Parameters:
key - the key of resource
Returns:
the resource date + time
Throws:
MissingResourceException - if the requested key is unknown

getString

public String getString(String key)
                 throws MissingResourceException
Retrieve a raw string from bundle.

Parameters:
key - the key of resource
Returns:
the resource string
Throws:
MissingResourceException - if the requested key is unknown

getString

public String getString(String key,
                        Object arg1)
Retrieve a string from resource bundle and format it with specified args.

Parameters:
key - the key for resource
arg1 - an arg
Returns:
the formatted string

getString

public String getString(String key,
                        Object arg1,
                        Object arg2)
Retrieve a string from resource bundle and format it with specified args.

Parameters:
key - the key for resource
arg1 - an arg
arg2 - an arg
Returns:
the formatted string

getString

public String getString(String key,
                        Object arg1,
                        Object arg2,
                        Object arg3)
Retrieve a string from resource bundle and format it with specified args.

Parameters:
key - the key for resource
arg1 - an arg
arg2 - an arg
arg3 - an arg
Returns:
the formatted string

getString

public String getString(String key,
                        Object arg1,
                        Object arg2,
                        Object arg3,
                        Object arg4)
Retrieve a string from resource bundle and format it with specified args.

Parameters:
key - the key for resource
arg1 - an arg
arg2 - an arg
arg3 - an arg
arg4 - an arg
Returns:
the formatted string

getString

public String getString(String key,
                        Object arg1,
                        Object arg2,
                        Object arg3,
                        Object arg4,
                        Object arg5)
Retrieve a string from resource bundle and format it with specified args.

Parameters:
key - the key for resource
arg1 - an arg
arg2 - an arg
arg3 - an arg
arg4 - an arg
arg5 - an arg
Returns:
the formatted string

getString

public String getString(String key,
                        Object arg1,
                        Object arg2,
                        Object arg3,
                        Object arg4,
                        Object arg5,
                        Object arg6)
Retrieve a string from resource bundle and format it with specified args.

Parameters:
key - the key for resource
arg1 - an arg
arg2 - an arg
arg3 - an arg
arg4 - an arg
arg5 - an arg
arg6 - an arg
Returns:
the formatted string

getString

public String getString(String key,
                        Object arg1,
                        Object arg2,
                        Object arg3,
                        Object arg4,
                        Object arg5,
                        Object arg6,
                        Object arg7)
Retrieve a string from resource bundle and format it with specified args.

Parameters:
key - the key for resource
arg1 - an arg
arg2 - an arg
arg3 - an arg
arg4 - an arg
arg5 - an arg
arg6 - an arg
arg7 - an arg
Returns:
the formatted string

format

public String format(String key,
                     Object[] args)
Retrieve a string from resource bundle and format it with specified args.

Parameters:
key - the key for resource
args - an array of args
Returns:
the formatted string

getBundle

public final ResourceBundle getBundle()
                               throws MissingResourceException
Retrieve underlying ResourceBundle. If bundle has not been loaded it will be loaded by this method. Access is given in case other resources need to be extracted that this Manager does not provide simplified access to.

Returns:
the ResourceBundle
Throws:
MissingResourceException - if an error occurs