java.util

Class ResourceBundle

Known Direct Subclasses:
ListResourceBundle, MessageSourceResourceBundle, PropertyResourceBundle

public abstract class ResourceBundle
extends Object

Resource bundles contain locale-specific objects. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user's locale. In this way, you can write program code that is largely independent of the user's locale isolating most, if not all, of the locale-specific information in resource bundles.

This allows you to write programs that can:

Resource bundles belong to families whose members share a common base name, but whose names also have additional components that identify their locales. For example, the base name of a family of resource bundles might be "MyResources". The family should have a default resource bundle which simply has the same name as its family - "MyResources" - and will be used as the bundle of last resort if a specific locale is not supported. The family can then provide as many locale-specific members as needed, for example a German one named "MyResources_de".

Each resource bundle in a family contains the same items, but the items have been translated for the locale represented by that resource bundle. For example, both "MyResources" and "MyResources_de" may have a String that's used on a button for canceling operations. In "MyResources" the String may contain "Cancel" and in "MyResources_de" it may contain "Abbrechen".

If there are different resources for different countries, you can make specializations: for example, "MyResources_de_CH" contains objects for the German language (de) in Switzerland (CH). If you want to only modify some of the resources in the specialization, you can do so.

When your program needs a locale-specific object, it loads the ResourceBundle class using the getBundle method:

 ResourceBundle myResources =
      ResourceBundle.getBundle("MyResources", currentLocale);
 

Resource bundles contain key/value pairs. The keys uniquely identify a locale-specific object in the bundle. Here's an example of a ListResourceBundle that contains two key/value pairs:

 public class MyResources extends ListResourceBundle {
     protected Object[][] getContents() {
         return new Object[][] = {
         // LOCALIZE THIS
             {"OkKey", "OK"},
             {"CancelKey", "Cancel"},
         // END OF MATERIAL TO LOCALIZE
         };
     }
 }
 
Keys are always Strings. In this example, the keys are "OkKey" and "CancelKey". In the above example, the values are also Strings--"OK" and "Cancel"--but they don't have to be. The values can be any type of object.

You retrieve an object from resource bundle using the appropriate getter method. Because "OkKey" and "CancelKey" are both strings, you would use getString to retrieve them:

 button1 = new Button(myResources.getString("OkKey"));
 button2 = new Button(myResources.getString("CancelKey"));
 
The getter methods all require the key as an argument and return the object if found. If the object is not found, the getter method throws a MissingResourceException.

Besides getString, ResourceBundle also provides a method for getting string arrays, getStringArray, as well as a generic getObject method for any other type of object. When using getObject, you'll have to cast the result to the appropriate type. For example:

 int[] myIntegers = (int[]) myResources.getObject("intList");
 

The Java 2 platform provides two subclasses of ResourceBundle, ListResourceBundle and PropertyResourceBundle, that provide a fairly simple way to create resources. As you saw briefly in a previous example, ListResourceBundle manages its resource as a List of key/value pairs. PropertyResourceBundle uses a properties file to manage its resources.

If ListResourceBundle or PropertyResourceBundle do not suit your needs, you can write your own ResourceBundle subclass. Your subclasses must override two methods: handleGetObject and getKeys().

The following is a very simple example of a ResourceBundle subclass, MyResources, that manages two resources (for a larger number of resources you would probably use a Hashtable). Notice that you don't need to supply a value if a "parent-level" ResourceBundle handles the same key with the same value (as for the okKey below).

Example:

 // default (English language, United States)
 public class MyResources extends ResourceBundle {
     public Object handleGetObject(String key) {
         if (key.equals("okKey")) return "Ok";
         if (key.equals("cancelKey")) return "Cancel";
         return null;
     }
 }

 // German language
 public class MyResources_de extends MyResources {
     public Object handleGetObject(String key) {
         // don't need okKey, since parent level handles it.
         if (key.equals("cancelKey")) return "Abbrechen";
         return null;
     }
 }
 
You do not have to restrict yourself to using a single family of ResourceBundles. For example, you could have a set of bundles for exception messages, ExceptionResources (ExceptionResources_fr, ExceptionResources_de, ...), and one for widgets, WidgetResource (WidgetResources_fr, WidgetResources_de, ...); breaking up the resources however you like.
Since:
JDK1.1
See Also:
ListResourceBundle, PropertyResourceBundle, MissingResourceException

Field Summary

protected ResourceBundle
parent
The parent bundle of this bundle.

Constructor Summary

ResourceBundle()
Sole constructor.

Method Summary

static ResourceBundle
getBundle(String baseName)
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
static ResourceBundle
getBundle(String baseName, Locale locale)
Gets a resource bundle using the specified base name and locale, and the caller's class loader.
static ResourceBundle
getBundle(String baseName, Locale locale, ClassLoader loader)
Gets a resource bundle using the specified base name, locale, and class loader.
abstract Enumeration
getKeys()
Returns an enumeration of the keys.
Locale
getLocale()
Returns the locale of this resource bundle.
Object
getObject(String key)
Gets an object for the given key from this resource bundle or one of its parents.
String
getString(String key)
Gets a string for the given key from this resource bundle or one of its parents.
String[]
getStringArray(String key)
Gets a string array for the given key from this resource bundle or one of its parents.
protected abstract Object
handleGetObject(String key)
Gets an object for the given key from this resource bundle.
protected void
setParent(ResourceBundle parent)
Sets the parent bundle of this bundle.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

parent

protected ResourceBundle parent
The parent bundle of this bundle. The parent bundle is searched by getObject when this bundle does not contain a particular resource.

Constructor Details

ResourceBundle

public ResourceBundle()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
Usages and Demos :

View More Examples of ResourceBundle()
   1:     
   2:     private static final ResourceBundle EMPTY_RESOURCE_BUNDLE = new ResourceBundle()
   3:     {
   4:         public Object handleGetObject (final String key)
   5:         {

View Full Code Here
   1:           return(
   2:               new ResourceBundle()
   3:               {
   4:                   public Locale
   5:                   getLocale()

View Full Code Here

Method Details

getBundle

public static final ResourceBundle getBundle(String baseName)
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader. Calling this method is equivalent to calling
getBundle(baseName, Locale.getDefault(), this.getClass().getClassLoader()),
except that getClassLoader() is run with the security privileges of ResourceBundle. See getBundle for a complete description of the search and instantiation strategy.
Parameters:
baseName - the base name of the resource bundle, a fully qualified class name
Returns:
a resource bundle for the given base name and the default locale
Throws:
NullPointerException - if baseName is null
MissingResourceException - if no resource bundle for the specified base name can be found
Usages and Demos :

View More Examples of getBundle(String baseName)
   1: 
   2:   protected static ResourceBundle resources =
   3:         ...
   4:       ResourceBundle.getBundle("MyResources");
   5: 
   6:   public static void main(String[] args) {
   7:     ImageIcon flagIcon = (ImageIcon)(resources.getObject(

View Full Code Here
   1:     
   2:     private static java.util.ResourceBundle bundle =
   3:     
   4:     public PrincipalsRenderer() {
   5:     }

View Full Code Here
   1: import javax.xml.registry.*; 
   2: import java.util.ResourceBundle;
   3: import java.io.*;
   4:         ...
   5: 
   6:         ResourceBundle registryBundle =
   7:         ...
   8:            ResourceBundle.getBundle("com.sun.cb.CoffeeRegistry");

View Full Code Here
   1: 
   2: import java.util.ResourceBundle;
   3: import javax.xml.registry.*; 
   4:         ...
   5: 
   6:         ResourceBundle registryBundle =
   7:         ...
   8:            ResourceBundle.getBundle("com.sun.cb.CoffeeRegistry");

View Full Code Here
   1: 
   2:     private static java.util.ResourceBundle bundle =
   3:     

View Full Code Here

getBundle

public static final ResourceBundle getBundle(String baseName,
                                             Locale locale)
Gets a resource bundle using the specified base name and locale, and the caller's class loader. Calling this method is equivalent to calling
getBundle(baseName, locale, this.getClass().getClassLoader()),
except that getClassLoader() is run with the security privileges of ResourceBundle. See getBundle for a complete description of the search and instantiation strategy.
Parameters:
baseName - the base name of the resource bundle, a fully qualified class name
locale - the locale for which a resource bundle is desired
Returns:
a resource bundle for the given base name and locale
Throws:
NullPointerException - if baseName or locale is null
MissingResourceException - if no resource bundle for the specified base name can be found
Usages and Demos :

View More Examples of getBundle(String baseName,Locale locale)
   1: import java.util.ResourceBundle;
   2: import java.util.Locale;
   3:         ...
   4: 
   5:    ResourceBundle myResources =
   6:         ...
   7:        ResourceBundle.getBundle("MyResources", currLocale);
   8:    System.out.println("<<<***------------------------------***>>>");

View Full Code Here
   1:       Locale currentLocale;
   2:       ResourceBundle messages;
   3: 
   4:         ...
   5:       messages =
   6:         ResourceBundle.getBundle("MessagesBundle",currentLocale);
   7: 
   8:       System.out.println(messages.getString("greetings"));
   9:       System.out.println(messages.getString("inquiry"));

View Full Code Here
   1: 
   2:       ResourceBundle messages = 
   3:         ...
   4:          ResourceBundle.getBundle("MessageBundle",currentLocale);
   5: 
   6:       Object[] messageArguments = {
   7:          messages.getString("planet"),

View Full Code Here
   1:     {
   2:         ResourceBundle rb =
   3:         ...
   4:             ResourceBundle.getBundle("LocalStrings",request.getLocale());
   5:         response.setContentType("text/html");
   6:         PrintWriter out = response.getWriter();

View Full Code Here
   1: 
   2:       ResourceBundle labels = 
   3:         ...
   4:          ResourceBundle.getBundle("LabelsBundle",currentLocale);
   5:       String value  = labels.getString(key);
   6:         ...
   7: 
   8:       ResourceBundle labels = 
   9:         ...
  10:          ResourceBundle.getBundle("LabelsBundle",currentLocale);

View Full Code Here

getBundle

public static ResourceBundle getBundle(String baseName,
                                       Locale locale,
                                       ClassLoader loader)
Gets a resource bundle using the specified base name, locale, and class loader.

Conceptually, getBundle uses the following strategy for locating and instantiating resource bundles:

getBundle uses the base name, the specified locale, and the default locale (obtained from Locale.getDefault) to generate a sequence of candidate bundle names. If the specified locale's language, country, and variant are all empty strings, then the base name is the only candidate bundle name. Otherwise, the following sequence is generated from the attribute values of the specified locale (language1, country1, and variant1) and of the default locale (language2, country2, and variant2):

  • baseName + "_" + language1 + "_" + country1 + "_" + variant1
  • baseName + "_" + language1 + "_" + country1
  • baseName + "_" + language1
  • baseName + "_" + language2 + "_" + country2 + "_" + variant2
  • baseName + "_" + language2 + "_" + country2
  • baseName + "_" + language2
  • baseName

Candidate bundle names where the final component is an empty string are omitted. For example, if country1 is an empty string, the second candidate bundle name is omitted.

getBundle then iterates over the candidate bundle names to find the first one for which it can instantiate an actual resource bundle. For each candidate bundle name, it attempts to create a resource bundle:

  • First, it attempts to load a class using the candidate bundle name. If such a class can be found and loaded using the specified class loader, is assignment compatible with ResourceBundle, is accessible from ResourceBundle, and can be instantiated, getBundle creates a new instance of this class and uses it as the result resource bundle.
  • Otherwise, getBundle attempts to locate a property resource file. It generates a path name from the candidate bundle name by replacing all "." characters with "/" and appending the string ".properties". It attempts to find a "resource" with this name using ClassLoader.getResource. (Note that a "resource" in the sense of getResource has nothing to do with the contents of a resource bundle, it is just a container of data, such as a file.) If it finds a "resource", it attempts to create a new PropertyResourceBundle instance from its contents. If successful, this instance becomes the result resource bundle.

If no result resource bundle has been found, a MissingResourceException is thrown.

Once a result resource bundle has been found, its parent chain is instantiated. getBundle iterates over the candidate bundle names that can be obtained by successively removing variant, country, and language (each time with the preceding "_") from the bundle name of the result resource bundle. As above, candidate bundle names where the final component is an empty string are omitted. With each of the candidate bundle names it attempts to instantiate a resource bundle, as described above. Whenever it succeeds, it calls the previously instantiated resource bundle's setParent method with the new resource bundle, unless the previously instantiated resource bundle already has a non-null parent.

Implementations of getBundle may cache instantiated resource bundles and return the same resource bundle instance multiple times. They may also vary the sequence in which resource bundles are instantiated as long as the selection of the result resource bundle and its parent chain are compatible with the description above.

The baseName argument should be a fully qualified class name. However, for compatibility with earlier versions, Sun's Java 2 runtime environments do not verify this, and so it is possible to access PropertyResourceBundles by specifying a path name (using "/") instead of a fully qualified class name (using ".").

Example: The following class and property files are provided: MyResources.class, MyResources_fr_CH.properties, MyResources_fr_CH.class, MyResources_fr.properties, MyResources_en.properties, MyResources_es_ES.class. The contents of all files are valid (that is, public non-abstract subclasses of ResourceBundle for the ".class" files, syntactically correct ".properties" files). The default locale is Locale("en", "GB").

Calling getBundle with the shown locale argument values instantiates resource bundles from the following sources:

  • Locale("fr", "CH"): result MyResources_fr_CH.class, parent MyResources_fr.properties, parent MyResources.class
  • Locale("fr", "FR"): result MyResources_fr.properties, parent MyResources.class
  • Locale("de", "DE"): result MyResources_en.properties, parent MyResources.class
  • Locale("en", "US"): result MyResources_en.properties, parent MyResources.class
  • Locale("es", "ES"): result MyResources_es_ES.class, parent MyResources.class
The file MyResources_fr_CH.properties is never used because it is hidden by MyResources_fr_CH.class.

Parameters:
baseName - the base name of the resource bundle, a fully qualified class name
locale - the locale for which a resource bundle is desired
loader - the class loader from which to load the resource bundle
Returns:
a resource bundle for the given base name and locale
Throws:
NullPointerException - if baseName, locale, or loader is null
MissingResourceException - if no resource bundle for the specified base name can be found
Since:
1.2
Usages and Demos :

View More Examples of getBundle(String baseName,Locale locale,ClassLoader loader)
   1: 
   2:       public static ResourceBundle loadBundle(String bundleName) {
   3:         return loadBundle(bundleName, I18NHelper.class.getClassLoader());
   4:         ...
   5: 
   6:       public static ResourceBundle loadBundle(String bundleName, ClassLoader loader) {
   7:         ...
   8:               ResourceBundle messages = (ResourceBundle)bundles.get(bundleName);
   9: 
  10:         ...
  11:         {
  12:                   messages = ResourceBundle.getBundle(bundleName, locale, loader);

View Full Code Here
   1: 
   2:     private ResourceBundle getBundle( Locale locale )
   3:     {
   4:         ...
   5:         return ResourceBundle.getBundle( "surefire-report", locale, this.getClass().getClassLoader() );
   6:     }
   7: 
   8:     public boolean canGenerateReport()

View Full Code Here
   1: 
   2:     protected ResourceBundle bundle;
   3:     protected Locale locale;
   4:         ...
   5:     protected void init(final String bundleName, final Locale locale, final Class clazz) {
   6:         bundle = (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction() {
   7:             public Object run() {
   8:         ...
   9:                 try {
  10:                     return ResourceBundle.getBundle(bundleName, locale, loader);
  11:                 } catch (MissingResourceException e) {

View Full Code Here
   1: 
   2:     public ResourceBundle getResourceBundle(String name, Locale locale) {
   3:         ClassLoader cl = Thread.currentThread().getContextClassLoader();
   4:         ...
   5: 
   6:     public ResourceBundle getResourceBundle(String name, Locale locale,
   7:             ClassLoader cl) {
   8:         ...
   9:         if (!isPersistedResource(name))
  10:             return ResourceBundle.getBundle(name, locale, cl);
  11:         String id = name + "_" + locale.getLanguage();
  12:         ...
  13:                     return null;
  14:                 return (ResourceBundle) obj;

View Full Code Here
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: 
   4:         ...
   5:     {
   6:         ResourceBundle appBundle;
   7:         ...
   8:         ResourceBundle defBundle;
   9:         String summary;
  10:         ...
  11:             {
  12:                 return ResourceBundle.getBundle(bundleName, locale, Thread.currentThread().getContextClassLoader());

View Full Code Here

getKeys

public abstract Enumeration getKeys()
Returns an enumeration of the keys.
Usages and Demos :

View More Examples of getKeys()
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: import java.util.Set;
   4:         ...
   5: 
   6:     private final ResourceBundle    m_bundle;
   7:     private final Set<String>       m_existingKeys;
   8:         ...
   9:     public ResourceBundleIconProvider(String bundleBaseName) {
  10:         m_bundle = ResourceBundle.getBundle(bundleBaseName);
  11:         ...
  12:         m_existingKeys = KongaSetUtils.asSet(m_bundle.getKeys());

View Full Code Here
   1: 
   2: import java.util.ResourceBundle;
   3: import java.util.Enumeration;
   4:         ...
   5: 
   6:     private ResourceBundle _bundle;
   7: 
   8:         ...
   9:     ResourceBundleNode(ResourceBundle resourceBundle) {
  10:         _bundle = resourceBundle;
  11:         ...
  12:     public Enumeration getKeys() {
  13:         return _bundle != null ? _bundle.getKeys() : null;

View Full Code Here
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: import java.util.Set;
   4:         ...
   5: 
   6:     private final ResourceBundle            m_bundle;
   7:     private final Set<String>               m_existingKeys;
   8:         ...
   9:                                          StringWithMnemonicFactory mnemonicFactory) {
  10:         m_bundle = ResourceBundle.getBundle(bundleName);
  11:         ...
  12:         m_existingKeys = KongaSetUtils.asSet(m_bundle.getKeys());

View Full Code Here
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: import java.util.StringTokenizer;
   4:         ...
   5: 
   6: public class MultiPropertyResourceBundle extends ResourceBundle {
   7: 
   8:         ...
   9:     private ResourceBundle bundle;
  10: 
  11:         ...
  12:     public Enumeration getKeys() {
  13:         return bundle.getKeys();

View Full Code Here
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: 
   4:         ...
   5: 
   6: public class ApplicationResources extends ResourceBundle {
   7: 
   8:         ...
   9: 
  10:     private ResourceBundle _delegate;
  11: 
  12:         ...
  13:     public Enumeration getKeys () {
  14:         return _delegate.getKeys();

View Full Code Here

getLocale

public Locale getLocale()
Returns the locale of this resource bundle. This method can be used after a call to getBundle() to determine whether the resource bundle returned really corresponds to the requested locale or is a fallback.
Returns:
the locale of this resource bundle
Usages and Demos :

View More Examples of getLocale()
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: 
   4:         ...
   5: 
   6:     private static ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME);
   7: 
   8:         ...
   9:     public static Locale getLocale() {
  10:         return resourceBundle.getLocale();
  11:     }

View Full Code Here
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: import java.util.StringTokenizer;
   4:         ...
   5: 
   6: public class MultiPropertyResourceBundle extends ResourceBundle {
   7: 
   8:         ...
   9:     private ResourceBundle bundle;
  10: 
  11:         ...
  12:     public Locale getLocale() {
  13:         return bundle.getLocale();

View Full Code Here
   1: 
   2:   public ResourceBundle getResourceBundle(Locale locale)
   3:   {
   4:         ...
   5: 
   6:   static class PortletResourceBundle extends ResourceBundle 
   7:   {
   8:         ...
   9:     private Map<String, Object> _defaultMap;
  10:     private ResourceBundle _parent;
  11: 
  12:         ...
  13:     {
  14:       return _parent == null ? _locale : _parent.getLocale();

View Full Code Here
   1: import jp.ujihara.java.util.MissingResourceException;
   2: import jp.ujihara.java.util.ResourceBundle;
   3: 
   4:         ...
   5: 
   6:   public static ComponentOrientation getOrientation(ResourceBundle bdl)
   7:   {
   8:         ...
   9:       {
  10:         r = getOrientation(bdl.getLocale());
  11:         if (r != null)

View Full Code Here
   1: import java.util.Map;
   2: import java.util.ResourceBundle;
   3: import javax.faces.component.UIComponent;
   4:         ...
   5:     StringBuffer b =  new StringBuffer(200) ;
   6:     ResourceBundle res = getApplicationResourceBundle(context.getExternalContext());
   7:     String formName = ((UISimpleForm) uiInput.getParent()).getFormName() ;
   8:         ...
   9:     String name = uiInput.getName() ;
  10:     renderJavascript(b, uiInput.getName(), formName, res.getLocale().getLanguage());
  11:     Calendar cal = uiInput.getCalendar();
  12:         ...
  13:   
  14:   private String[] buildMonthArray(ResourceBundle res){

View Full Code Here

getObject

public final Object getObject(String key)
Gets an object for the given key from this resource bundle or one of its parents. This method first tries to obtain the object from this resource bundle using handleGetObject. If not successful, and the parent resource bundle is not null, it calls the parent's getObject method. If still not successful, it throws a MissingResourceException.
Parameters:
key - the key for the desired object
Returns:
the object for the given key
Throws:
NullPointerException - if key is null
MissingResourceException - if no object for the given key can be found
Usages and Demos :

View More Examples of getObject(String key)
   1: 
   2: public class MergedBundle extends ResourceBundle
   3: {
   4:         ...
   5:     private final ResourceBundle _mainBundle, _parentBundle;
   6: 
   7:         ...
   8:     public MergedBundle (ResourceBundle mainBundle, 
   9:         ResourceBundle parentBundle)
  10:         ...
  11:         {
  12:             return _mainBundle.getObject(key);

View Full Code Here
   1: 
   2: import java.util.ResourceBundle;
   3: 
   4:         ...
   5:     final ResourceBundleFactory resourceBundleFactory = getResourceBundleFactory();
   6:     final ResourceBundle bundle;
   7:     if (resourceIdentifier == null)
   8:         ...
   9:     }
  10:     return bundle.getObject(String.valueOf(key));
  11:   }

View Full Code Here
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: import javax.swing.UIDefaults;
   4:         ...
   5:     {
   6:       final ResourceBundle bundle = ResourceBundle.getBundle(RESOURCES_BASE_NAME);
   7: 
   8:         ...
   9:         {
  10:           defaults.put(keyName, bundle.getObject(keyName));
  11:         }

View Full Code Here
   1: import java.util.MissingResourceException;
   2: import java.util.ResourceBundle;
   3: 
   4:         ...
   5: 
   6: public class ApplicationResources extends ResourceBundle {
   7: 
   8:         ...
   9: 
  10:     private ResourceBundle _delegate;
  11: 
  12:         ...
  13:             throws MissingResourceException {
  14:         return _delegate.getObject(key);

View Full Code Here
   1: import java.awt.event.ActionEvent;
   2: import java.util.ResourceBundle;
   3: 
   4:         ...
   5: 
   6:     private static final ResourceBundle RESOURCES = TextDocumentPage.getResources();
   7: 
   8:         ...
   9:         String name = RESOURCES.getString(nameKey);
  10:         Icon icon = (iconKey == null) ? null : (Icon) RESOURCES.getObject(iconKey);
  11:         a.putValue(Action.NAME, name);

View Full Code Here

getString

public final String getString(String key)
Gets a string for the given key from this resource bundle or one of its parents. Calling this method is equivalent to calling
(String) getObject(key).
Parameters:
key - the key for the desired string
Returns:
the string for the given key
Throws:
NullPointerException - if key is null
MissingResourceException - if no object for the given key can be found
ClassCastException - if the object found for the given key is not a string
Usages and Demos :

View More Examples of getString(String key)
   1: 
   2: import java.util.ResourceBundle;
   3: import java.util.Enumeration;
   4:         ...
   5: 
   6:     private ResourceBundle _bundle;
   7: 
   8:         ...
   9:     ResourceBundleNode(ResourceBundle resourceBundle) {
  10:         _bundle = resourceBundle;
  11:         ...
  12:     public boolean containsKey(String key) {
  13:         return _bundle != null && _bundle.getString(key) != null;

View Full Code Here
   1:         try {
   2:             ResourceBundle m = ResourceBundle.getBundle(RESOURCE, locale);
   3:         ...
   4:             return m.getString("" + number);
   5:         } catch (Exception e) {
   6:             return "UNKNOWN";
   7:         }

View Full Code Here
   1: import java.text.MessageFormat;
   2: import java.util.ResourceBundle;
   3: import java.util.logging.Level;
   4:         ...
   5:     private static String localize(Logger logger, String message) {
   6:         ResourceBundle bundle = logger.getResourceBundle();
   7:         ...
   8:         return bundle != null ? bundle.getString(message) : message;
   9:     }

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.ResourceBundle;
   3: 
   4:         ...
   5: 
   6:   private ResourceBundle          aregRb;
   7: 
   8:         ...
   9: 
  10:     aregRb = ResourceBundle.getBundle( "com.verisignlabs.pimmit.text.CliAreg" );
  11:     defaultRegistry = new Areg1Registry();
  12:         ...
  13:   {
  14:     opt.addLongOptionRequiredArg( "cn",           aregRb.getString("--cn") );

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.ResourceBundle;
   3: 
   4:         ...
   5: 
   6:   private ResourceBundle          eregRb;
   7: 
   8:         ...
   9: 
  10:     eregRb = ResourceBundle.getBundle( "com.verisignlabs.pimmit.text.CliEreg" );
  11:     defaultRegistry = new Ereg1Registry();
  12:         ...
  13:   {
  14:     opt.addLongOptionRequiredArg( "cn",           eregRb.getString("--cn") );

View Full Code Here

getStringArray

public final String[] getStringArray(String key)
Gets a string array for the given key from this resource bundle or one of its parents. Calling this method is equivalent to calling
(String[]) getObject(key).
Parameters:
key - the key for the desired string array
Returns:
the string array for the given key
Throws:
NullPointerException - if key is null
MissingResourceException - if no object for the given key can be found
ClassCastException - if the object found for the given key is not a string array
Usages and Demos :

View More Examples of getStringArray(String key)
   1: import jp.ujihara.java.util.MissingResourceException;
   2: import jp.ujihara.java.util.ResourceBundle;
   3: 
   4:         ...
   5: 
   6:   private String[] formatsForKey(ResourceBundle res, String key) 
   7:   {
   8:         ...
   9:   {
  10:     ResourceBundle res
  11:       = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale,
  12:         ...
  13: 
  14:     ampms = res.getStringArray("ampms");

View Full Code Here

handleGetObject

protected abstract Object handleGetObject(String key)
Gets an object for the given key from this resource bundle. Returns null if this resource bundle does not contain an object for the given key.
Parameters:
key - the key for the desired object
Returns:
the object for the given key, or null
Throws:
NullPointerException - if key is null

setParent

protected void setParent(ResourceBundle parent)
Sets the parent bundle of this bundle. The parent bundle is searched by getObject when this bundle does not contain a particular resource.
Parameters:
parent - this bundle's parent bundle.