de.bea.domingo.i18n
Class Resources

java.lang.Object
  extended by de.bea.domingo.i18n.Resources

public final class Resources
extends java.lang.Object

A class to simplify extracting localized strings, icons and other common resources from a ResourceBundle.

Author:
Kurt Riede

Constructor Summary
Resources(java.lang.String theBaseName)
          Constructor that builds a manager in default locale.
Resources(java.lang.String theBaseName, java.lang.ClassLoader theClassLoader)
          Constructor that builds a manager in default locale using specified ClassLoader.
Resources(java.lang.String theBaseName, java.util.Locale theLocale)
          Constructor that builds a manager in specified locale.
Resources(java.lang.String theBaseName, java.util.Locale theLocale, java.lang.ClassLoader theClassLoader)
          Constructor that builds a manager in specified locale.
 
Method Summary
 java.lang.String format(java.lang.String key, java.lang.Object[] args)
          Retrieve a string from resource bundle and format it with specified arguments.
 boolean getBoolean(java.lang.String key)
          Retrieve a boolean from bundle.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Retrieve a boolean from bundle.
 java.util.ResourceBundle getBundle()
          Retrieve underlying ResourceBundle.
 byte getByte(java.lang.String key)
          Retrieve a byte from bundle.
 byte getByte(java.lang.String key, byte defaultValue)
          Retrieve a byte from bundle.
 char getChar(java.lang.String key)
          Retrieve a char from bundle.
 char getChar(java.lang.String key, char defaultValue)
          Retrieve a char from bundle.
 java.util.Date getDate(java.lang.String key)
          Retrieve a date from bundle.
 java.util.Date getDate(java.lang.String key, java.util.Date defaultValue)
          Retrieve a date from bundle.
 java.util.Date getDateTime(java.lang.String key)
          Retrieve a date + time from bundle.
 java.util.Date getDateTime(java.lang.String key, java.util.Date defaultValue)
          Retrieve a time from bundle.
 double getDouble(java.lang.String key)
          Retrieve a double from bundle.
 double getDouble(java.lang.String key, double defaultValue)
          Retrieve a double from bundle.
 float getFloat(java.lang.String key)
          Retrieve a float from bundle.
 float getFloat(java.lang.String key, float defaultValue)
          Retrieve a float from bundle.
 int getInteger(java.lang.String key)
          Retrieve a integer from bundle.
 int getInteger(java.lang.String key, int defaultValue)
          Retrieve a integer from bundle.
 long getLong(java.lang.String key)
          Retrieve a long from bundle.
 long getLong(java.lang.String key, long defaultValue)
          Retrieve a long from bundle.
 short getShort(java.lang.String key)
          Retrieve a short from bundle.
 short getShort(java.lang.String key, short defaultValue)
          Retrieve a short from bundle.
 java.lang.String getString(java.lang.String key)
          Retrieve a raw string from bundle.
 java.lang.String getString(java.lang.String key, java.lang.Object arg1)
          Retrieve a string from resource bundle and format it with specified arguments.
 java.lang.String getString(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2)
          Retrieve a string from resource bundle and format it with specified arguments.
 java.lang.String getString(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
          Retrieve a string from resource bundle and format it with specified arguments.
 java.lang.String getString(java.lang.String key, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
          Retrieve a string from resource bundle and format it with specified arguments.
 java.util.Date getTime(java.lang.String key)
          Retrieve a time from bundle.
 java.util.Date getTime(java.lang.String key, java.util.Date defaultValue)
          Retrieve a time from bundle.
 Resources withFailOnError(boolean failOnError)
          Whether an exception should be thrown in case of an unknown resource or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resources

public Resources(java.lang.String theBaseName)
Constructor that builds a manager in default locale.

Parameters:
theBaseName - the base name of ResourceBundle

Resources

public Resources(java.lang.String theBaseName,
                 java.lang.ClassLoader theClassLoader)
Constructor that builds a manager in default locale using specified ClassLoader.

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

Resources

public Resources(java.lang.String theBaseName,
                 java.util.Locale theLocale)
Constructor that builds a manager in specified locale.

Parameters:
theBaseName - the base name of ResourceBundle
theLocale - the Locale for resource bundle

Resources

public Resources(java.lang.String theBaseName,
                 java.util.Locale theLocale,
                 java.lang.ClassLoader theClassLoader)
Constructor that builds a manager in specified locale.

Parameters:
theBaseName - the base name of ResourceBundle
theLocale - the Locale for resource bundle
theClassLoader - the classLoader to load ResourceBundle from
Method Detail

withFailOnError

public Resources withFailOnError(boolean failOnError)
Whether an exception should be thrown in case of an unknown resource or not.

Parameters:
failOnError - true if an exception should be thrown in case of an unknown resource, else false
Returns:
the instance itself

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
                   throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getBoolean

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

Parameters:
key - the key of resource
Returns:
the resource boolean
Throws:
java.util.MissingResourceException - if a resource wasn't found

getByte

public byte getByte(java.lang.String key,
                    byte defaultValue)
             throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getByte

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

Parameters:
key - the key of resource
Returns:
the resource byte
Throws:
java.util.MissingResourceException - if a resource wasn't found

getChar

public char getChar(java.lang.String key,
                    char defaultValue)
             throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getChar

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

Parameters:
key - the key of resource
Returns:
the resource char
Throws:
java.util.MissingResourceException - if a resource wasn't found

getShort

public short getShort(java.lang.String key,
                      short defaultValue)
               throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getShort

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

Parameters:
key - the key of resource
Returns:
the resource short
Throws:
java.util.MissingResourceException - if a resource wasn't found

getInteger

public int getInteger(java.lang.String key,
                      int defaultValue)
               throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getInteger

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

Parameters:
key - the key of resource
Returns:
the resource integer
Throws:
java.util.MissingResourceException - if a resource wasn't found

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
             throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getLong

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

Parameters:
key - the key of resource
Returns:
the resource long
Throws:
java.util.MissingResourceException - if a resource wasn't found

getFloat

public float getFloat(java.lang.String key,
                      float defaultValue)
               throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getFloat

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

Parameters:
key - the key of resource
Returns:
the resource float
Throws:
java.util.MissingResourceException - if a resource wasn't found

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
                 throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getDouble

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

Parameters:
key - the key of resource
Returns:
the resource double
Throws:
java.util.MissingResourceException - if a resource wasn't found

getDate

public java.util.Date getDate(java.lang.String key,
                              java.util.Date defaultValue)
                       throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getDate

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

Parameters:
key - the key of resource
Returns:
the resource date
Throws:
java.util.MissingResourceException - if a resource wasn't found

getTime

public java.util.Date getTime(java.lang.String key,
                              java.util.Date defaultValue)
                       throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getTime

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

Parameters:
key - the key of resource
Returns:
the resource time
Throws:
java.util.MissingResourceException - if a resource wasn't found

getDateTime

public java.util.Date getDateTime(java.lang.String key,
                                  java.util.Date defaultValue)
                           throws java.util.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:
java.util.MissingResourceException - if a resource wasn't found

getDateTime

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

Parameters:
key - the key of resource
Returns:
the resource date + time
Throws:
java.util.MissingResourceException - if a resource wasn't found

getString

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

Parameters:
key - the key of resource
Returns:
the resource string
Throws:
java.util.MissingResourceException - if a resource wasn't found

getString

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

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

getString

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

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

getString

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

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

getString

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

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

format

public java.lang.String format(java.lang.String key,
                               java.lang.Object[] args)
                        throws java.util.MissingResourceException
Retrieve a string from resource bundle and format it with specified arguments.

Parameters:
key - the key for resource
args - an array of arguments
Returns:
the formatted string
Throws:
java.util.MissingResourceException - if withFailOnError(boolean) is true and the requested resource wasn't found
See Also:
withFailOnError(boolean)

getBundle

public java.util.ResourceBundle getBundle()
                                   throws java.util.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:
java.util.MissingResourceException - if an error occurs


Domingo Java-API