org.zilonis.tool.ext.aerith.util
Class Bundles

java.lang.Object
  extended by org.zilonis.tool.ext.aerith.util.Bundles

public class Bundles
extends java.lang.Object

Convenience class permitting easy loading of localized resources of various sorts. Extends the functionality of the default Java resource support, and interacts better with class loaders in a multiple-loader system.

Example usage:

 package com.mycom;
 public class Foo {
   // Search for tag Foo_theMessage in /com/mycom/Bundle.properties:
   private static String theMessage = NbBundle.getMessage (Foo.class, "Foo_theMessage");
   // Might also look in /com/mycom/Bundle_de.properties, etc.
 }
 


Method Summary
static java.util.ResourceBundle getBundle(java.lang.Class clazz)
          Get a resource bundle in the same package as the provided class, with the default locale/branding and the class' own classloader.
static java.util.ResourceBundle getBundle(java.lang.String baseName)
          Get a resource bundle with the default class loader and locale/branding.
static java.util.ResourceBundle getBundle(java.lang.String baseName, java.util.Locale locale)
          Get a resource bundle with the default class loader and branding.
static java.util.ResourceBundle getBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader loader)
          Get a resource bundle the hard way.
static java.lang.String getMessage(java.lang.Class clazz, java.lang.String resName)
          Finds a localized and/or branded string in a bundle.
static java.lang.String getMessage(java.lang.Class clazz, java.lang.String resName, java.lang.Object... params)
          Finds a localized and/or branded string in a bundle and formats the message by passing requested parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBundle

public static final java.util.ResourceBundle getBundle(java.lang.String baseName)
                                                throws java.util.MissingResourceException
Get a resource bundle with the default class loader and locale/branding. Caution: getBundle(Class) is generally safer when used from a module as this method relies on the module's classloader to currently be part of the system classloader. The IDE does add enabled modules to this classloader, however calls to this variant of the method made in

getBundle

public static java.util.ResourceBundle getBundle(java.lang.Class clazz)
                                          throws java.util.MissingResourceException
Get a resource bundle in the same package as the provided class, with the default locale/branding and the class' own classloader. This is the usual style of invocation.

Parameters:
clazz - the class to take the package name from
Returns:
the resource bundle
Throws:
java.util.MissingResourceException - if the bundle does not exist

getBundle

public static final java.util.ResourceBundle getBundle(java.lang.String baseName,
                                                       java.util.Locale locale)
                                                throws java.util.MissingResourceException
Get a resource bundle with the default class loader and branding.

Parameters:
baseName - bundle basename
locale - the locale to use (but still uses default branding)
Returns:
the resource bundle
Throws:
java.util.MissingResourceException - if the bundle does not exist

getBundle

public static final java.util.ResourceBundle getBundle(java.lang.String baseName,
                                                       java.util.Locale locale,
                                                       java.lang.ClassLoader loader)
                                                throws java.util.MissingResourceException
Get a resource bundle the hard way.

Parameters:
baseName - bundle basename
locale - the locale to use (but still uses default branding)
loader - the class loader to use
Returns:
the resource bundle
Throws:
java.util.MissingResourceException - if the bundle does not exist

getMessage

public static java.lang.String getMessage(java.lang.Class clazz,
                                          java.lang.String resName)
                                   throws java.util.MissingResourceException
Finds a localized and/or branded string in a bundle.

Parameters:
clazz - the class to use to locate the bundle
resName - name of the resource to look for
Returns:
the string associated with the resource
Throws:
java.util.MissingResourceException - if either the bundle or the string cannot be found

getMessage

public static java.lang.String getMessage(java.lang.Class clazz,
                                          java.lang.String resName,
                                          java.lang.Object... params)
                                   throws java.util.MissingResourceException
Finds a localized and/or branded string in a bundle and formats the message by passing requested parameters.

Parameters:
clazz - the class to use to locate the bundle
resName - name of the resource to look for
params - array of parameters to use for formatting the message
Returns:
the string associated with the resource
Throws:
java.util.MissingResourceException - if either the bundle or the string cannot be found
See Also:
MessageFormat.format(String,Object[])