com.x1seven.hydrogen.i18n
Class I18nUtil

java.lang.Object
  extended by com.x1seven.hydrogen.i18n.I18nUtil

public class I18nUtil
extends java.lang.Object

Helper for working with Java ResourceBundles, and for applying value substitution to Strings retrieved from a bundle. An I18nUtil object is created for a named bundle, and optionally a locale. It provides an overloaded getString() method that can be used to retrieve Strings from the bundle, optionally supplying substitution values to be inserted into the message using the standard MessageFormat API.

Since:
1.0.0
Version:
1.8
Author:
Brendon Matheson

Field Summary
static java.lang.String DEFAULT_RESOURCE_BUNDLE_NAME
          This is the ResourceBundle name to use if none is specified.
 
Constructor Summary
I18nUtil(java.lang.Class clazz)
          Creates a new I18nUtil object for the default resource bundle name within the same package as the supplied class.
I18nUtil(java.lang.Class clazz, java.lang.ClassLoader classLoader)
          Creates a new I18nUtil object for the default resource bundle name within the same package as the supplied class, and using the supplied ClassLoader.
I18nUtil(java.lang.Class clazz, java.lang.String resourceBundleName)
          Creates a new I18nUtil object for the supplied bundle name and in the same package as the supplied class.
I18nUtil(java.lang.Package pkg)
          Creates a new I18nUtil object with the default bundle name and in the same package as the supplied class.
I18nUtil(java.lang.Package pkg, java.lang.String resourceBundleName)
          Creates a new I18nUtil object with for the supplied bundle name and in the supplied package.
I18nUtil(java.lang.String bundleName)
          Creates a new I18nUtil object for the named ResourceBundle.
I18nUtil(java.lang.String bundleName, java.lang.ClassLoader classLoader)
          Creates a new I18nUtil object for the named ResourceBundle and the supplied ClassLoader.
I18nUtil(java.lang.String bundleName, java.util.Locale locale)
          Creates a new I18nUtil object for the named ResourceBundle and supplied Locale.
 
Method Summary
 java.lang.Object[] buildObjectArray(java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2)
          Helper method to build an Object array containing three objects.
 java.lang.Object[] buildObjectArray(java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
          Helper method to build an Object array containing four objects.
 java.lang.Object[] buildObjectArray(java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
          Helper method to build an Object array containing five objects.
 java.lang.String getBundleName()
          Returns the name of the ResourceBundle that this I18nUtil object has been set to use.
 java.lang.ClassLoader getClassLoader()
          Returns the ClassLoader that this I18nUtil object is using to retrieve resources.
 java.util.Locale getLocale()
          Returns the locale that this I18nUtil object has been set to use.
 java.lang.String getString(java.lang.String key)
          Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle.
 java.lang.String getString(java.lang.String key, java.lang.Object arg0)
          Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.
 java.lang.String getString(java.lang.String key, java.lang.Object[] args)
          Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.
 java.lang.String getString(java.lang.String key, java.lang.Object arg0, java.lang.Object arg1)
          Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.
 java.lang.String getString(java.lang.String key, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2)
          Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.
 java.lang.String getString(java.lang.String key, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
          Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.
 java.lang.String getString(java.lang.String key, java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
          Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.
 void setBundleName(java.lang.String bundleName)
          Sets the name of the ResourceBundle that this I18nUtil object should use.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Sets the ClassLoader that this I18nUtil object will use to retrieve resources.
 void setLocale(java.util.Locale locale)
          Sets the locale that this I18nUtil object should use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_RESOURCE_BUNDLE_NAME

public static final java.lang.String DEFAULT_RESOURCE_BUNDLE_NAME
This is the ResourceBundle name to use if none is specified.

See Also:
Constant Field Values
Constructor Detail

I18nUtil

public I18nUtil(java.lang.Class clazz)
Creates a new I18nUtil object for the default resource bundle name within the same package as the supplied class. Note that using this constructor is equivalient to calling I18nUtil(clazz.getPackage()).

Parameters:
clazz - the class whose package should be used to retrieve the ResourceBundle.
Since:
1.0.0

I18nUtil

public I18nUtil(java.lang.Class clazz,
                java.lang.ClassLoader classLoader)
Creates a new I18nUtil object for the default resource bundle name within the same package as the supplied class, and using the supplied ClassLoader.

Parameters:
clazz - the class whose package should be used to retrieve the ResourceBundle.
classLoader - the ClassLoader to use when retrieving the ResourceBundle.
Since:
1.0.1

I18nUtil

public I18nUtil(java.lang.Class clazz,
                java.lang.String resourceBundleName)
Creates a new I18nUtil object for the supplied bundle name and in the same package as the supplied class. Note that using this constructor is equivalent to calling I18nUtil(clazz.getPackage(), resourceBundleName);

Parameters:
clazz - the class whose package should be used to retrieve the ResourceBundle.
resourceBundleName - the name of the ResourceBundle to look for within the supplied class's package.
Since:
1.0.0

I18nUtil

public I18nUtil(java.lang.Package pkg)
Creates a new I18nUtil object with the default bundle name and in the same package as the supplied class.

Parameters:
pkg - the package from which the ResourceBundle should be retrieved.
Since:
1.0.0

I18nUtil

public I18nUtil(java.lang.Package pkg,
                java.lang.String resourceBundleName)
Creates a new I18nUtil object with for the supplied bundle name and in the supplied package.

Parameters:
pkg - the package from which the ResourceBundle should be retrieved.
resourceBundleName - the name of the ResourceBundle to look for within the supplied package.
Since:
1.0.1

I18nUtil

public I18nUtil(java.lang.String bundleName)
Creates a new I18nUtil object for the named ResourceBundle.

Parameters:
bundleName - the name of the ResourceBundle that the I18nUtil should work with.
Since:
1.0.0

I18nUtil

public I18nUtil(java.lang.String bundleName,
                java.lang.ClassLoader classLoader)
Creates a new I18nUtil object for the named ResourceBundle and the supplied ClassLoader.

Parameters:
bundleName - the name of the ResourceBundle that the I18nUtil should work with.
classLoader - the ClassLoader to use when retrieving the ResourceBundle.
Since:
1.0.1

I18nUtil

public I18nUtil(java.lang.String bundleName,
                java.util.Locale locale)
Creates a new I18nUtil object for the named ResourceBundle and supplied Locale.

Parameters:
bundleName - the name of the ResourceBundle that the I18nUtil should work with.
locale - the locale that the I18nUtil should use when retrieving resources from the ResourceBundle.
Since:
1.0.0
Method Detail

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the ClassLoader that this I18nUtil object is using to retrieve resources.

Since:
1.0.1

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Sets the ClassLoader that this I18nUtil object will use to retrieve resources.

Since:
1.0.1

getLocale

public java.util.Locale getLocale()
Returns the locale that this I18nUtil object has been set to use. If no Locale has been supplied to the I18nUtil object, then this method will return null.

Since:
1.0.0

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale that this I18nUtil object should use. Setting locale to null causes the I18nUtil object to use the default locale.

Parameters:
locale - The locale for this I18nUtil to use when retrieving resources.
Since:
1.0.0

getBundleName

public java.lang.String getBundleName()
Returns the name of the ResourceBundle that this I18nUtil object has been set to use.

Since:
1.0.1

setBundleName

public void setBundleName(java.lang.String bundleName)
Sets the name of the ResourceBundle that this I18nUtil object should use.

Parameters:
bundleName - The name of the ResourceBundle that this I18nUtil object should use.
Since:
1.0.0

getString

public java.lang.String getString(java.lang.String key)
Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle.

Parameters:
key - The key into the ResourceBundle for the desired String.
Returns:
The string retrieved from the ResourceBundle
Since:
1.0.0

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object arg0)
Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.

Parameters:
key - The key into the ResourceBundle for the desired String.
arg0 - The replacement value to substitute into position 0
Returns:
The string retrieved from the ResourceBundle with the supplied replacement value substituted in.
Since:
1.0.0

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1)
Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.

Parameters:
key - The key into the ResourceBundle for the desired String.
arg0 - The replacement value to substitute into position 0
arg1 - The replacement value to substitute into position 1
Returns:
The string retrieved from the ResourceBundle with the supplied replacement values substituted in.
Since:
1.0.0

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2)
Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.

Parameters:
key - The key into the ResourceBundle for the desired String.
arg0 - The replacement value to substitute into position 0
arg1 - The replacement value to substitute into position 1
arg2 - The replacement value to substitute into position 2
Returns:
The string retrieved from the ResourceBundle with the supplied replacement values substituted in.
Since:
1.0.0

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2,
                                  java.lang.Object arg3)
Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.

Parameters:
key - The key into the ResourceBundle for the desired String.
arg0 - The replacement value to substitute into position 0
arg1 - The replacement value to substitute into position 1
arg2 - The replacement value to substitute into position 1
arg3 - The replacement value to substitute into position 3
Returns:
The string retrieved from the ResourceBundle with the supplied replacement values substituted in.
Since:
1.0.0

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object arg0,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2,
                                  java.lang.Object arg3,
                                  java.lang.Object arg4)
Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.

Parameters:
key - The key into the ResourceBundle for the desired String.
arg0 - The replacement value to substitute into position 0
arg1 - The replacement value to substitute into position 1
arg2 - The replacement value to substitute into position 1
arg3 - The replacement value to substitute into position 3
arg4 - The replacement value to substitute into position 4
Returns:
The string retrieved from the ResourceBundle with the supplied replacement values substituted in.
Since:
1.0.0

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.Object[] args)
Retrieves the string identified by the supplied key from this I18nUtil's ResourceBundle with the supplied values substituted in.

Parameters:
key - The key into the ResourceBundle for the desired String.
args - The replacement values to substitute into the String retrieved from the ResourceBundle.
Returns:
The string retrieved from the ResourceBundle with the supplied replacement values substituted in.
Since:
1.0.0

buildObjectArray

public java.lang.Object[] buildObjectArray(java.lang.Object arg0,
                                           java.lang.Object arg1,
                                           java.lang.Object arg2)
Helper method to build an Object array containing three objects.

Parameters:
arg0 - The object that is to be put into an Object array at index 0.
arg1 - The object that is to be put into an Object array at index 1.
arg2 - The object that is to be put into an Object array at index 2.
Returns:
An Object array of extent 3 containing the supplied Objects.
Since:
1.0.0

buildObjectArray

public java.lang.Object[] buildObjectArray(java.lang.Object arg0,
                                           java.lang.Object arg1,
                                           java.lang.Object arg2,
                                           java.lang.Object arg3)
Helper method to build an Object array containing four objects.

Parameters:
arg0 - The object that is to be put into an Object array at index 0.
arg1 - The object that is to be put into an Object array at index 1.
arg2 - The object that is to be put into an Object array at index 2.
arg3 - The object that is to be put into an Object array at index 3.
Returns:
An Object array of extent 4 containing the supplied Objects.
Since:
1.0.0

buildObjectArray

public java.lang.Object[] buildObjectArray(java.lang.Object arg0,
                                           java.lang.Object arg1,
                                           java.lang.Object arg2,
                                           java.lang.Object arg3,
                                           java.lang.Object arg4)
Helper method to build an Object array containing five objects.

Parameters:
arg0 - The object that is to be put into an Object array at index 0.
arg1 - The object that is to be put into an Object array at index 1.
arg2 - The object that is to be put into an Object array at index 2.
arg3 - The object that is to be put into an Object array at index 3.
arg4 - The object that is to be put into an Object array at index 4.
Returns:
An Object array of extent 5 containing the supplied Objects.
Since:
1.0.0