ptolemy.util
Class OrderedResourceBundle

java.lang.Object
  extended by ptolemy.util.OrderedResourceBundle

public class OrderedResourceBundle
extends java.lang.Object

Manage the resources for a locale using a set of static strings from a property file. See java.util.ResourceBundle for more information.

Unlike other types of resource bundle, OrderedResourceBundle is not usually subclassed. Instead, the properties files containing the resource data are supplied. OrderedResourceBundle.getBundle will automatically look for the appropriate properties file and create an OrderedResourceBundle that refers to it. See java.util.ResourceBundle.getBundle() for a complete description of the search and instantiation strategy.

Since:
Ptolemy II 8.0
Version:
$Id: OrderedResourceBundle.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Matthew Brooke

Field Summary
private static java.lang.String FWD_SLASH
           
private static java.lang.String keyValueSeparators
           
private  java.util.LinkedHashMap orderedMap
           
private static java.lang.String PROPS_EXT
           
private static java.lang.String strictKeyValueSeparators
           
private static java.lang.String UNDERSCORE
           
private static java.lang.String whiteSpaceChars
           
 
Constructor Summary
OrderedResourceBundle(java.io.InputStream stream)
          Construct an OrderedResourceBundle.
 
Method Summary
private  boolean continueLine(java.lang.String line)
           
static OrderedResourceBundle getBundle(java.lang.String baseName)
          Get a resource bundle using the specified base name and the default locale.
 java.util.Iterator getKeys()
          Get an Iterator over the Set of keys, allowing retrieval of the keys in the original order as listed in the properties file.
private  java.util.LinkedHashMap getPropsAsOrderedMap(java.io.BufferedReader propsReader)
          Get the properties as an ordered map.
private static java.lang.String getPropsFileNamePlusLocale(java.lang.String baseName)
           
 java.lang.String getString(java.lang.String key)
          Get a string for the given key from this resource bundle.
private  java.lang.String unescape(java.lang.String line)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FWD_SLASH

private static final java.lang.String FWD_SLASH
See Also:
Constant Field Values

UNDERSCORE

private static final java.lang.String UNDERSCORE
See Also:
Constant Field Values

PROPS_EXT

private static final java.lang.String PROPS_EXT
See Also:
Constant Field Values

whiteSpaceChars

private static final java.lang.String whiteSpaceChars
See Also:
Constant Field Values

keyValueSeparators

private static final java.lang.String keyValueSeparators
See Also:
Constant Field Values

strictKeyValueSeparators

private static final java.lang.String strictKeyValueSeparators
See Also:
Constant Field Values

orderedMap

private java.util.LinkedHashMap orderedMap
Constructor Detail

OrderedResourceBundle

public OrderedResourceBundle(java.io.InputStream stream)
                      throws java.io.IOException,
                             java.lang.NullPointerException
Construct an OrderedResourceBundle.

Parameters:
stream - InputStream for reading the java properties file from which this object will take its values. The stream is closed by this constructor.
Throws:
java.io.IOException - if there is a problem reading the InputStream
java.lang.NullPointerException - if the InputStream is null
Method Detail

getBundle

public static OrderedResourceBundle getBundle(java.lang.String baseName)
                                       throws java.io.IOException,
                                              java.util.MissingResourceException,
                                              java.lang.NullPointerException
Get a resource bundle using the specified base name and the default locale. The returned bundle has its entries in the same order as those in the original properties file, so a call to getKeys() will return an Iterator that allows retrieval of the keys in the original order. See javadoc for java.util.ResourceBundle for a complete description of the search and instantiation strategy.

Parameters:
baseName - String denoting the name of the properties file that will be read to populate this ResourceBundle.

Example 1: if the baseName is MyPropsFile, and the default Locale is en_US, a properties file named: MyPropsFile_en_US.properties will be sought on the classpath.

Example 2: if the baseName is org.mydomain.pkg.MyPropsFile, and the default Locale is en_US, a properties file named: org/mydomain/pkg/MyPropsFile_en_US.properties will be sought on the classpath.

NOTE: valid comment chars are # and !

valid delimiters are (space) : =
Returns:
OrderedResourceBundle - a ResourceBundle with its entries in the same order as those in the original properties file
Throws:
java.io.IOException - if there is a problem reading the file
java.util.MissingResourceException - if the file cannot be found
java.lang.NullPointerException - if baseName is null

getString

public java.lang.String getString(java.lang.String key)
Get a string for the given key from this resource bundle.

Parameters:
key - the key for the desired string
Returns:
the string for the given key, or null if: a null value is actually mapped to this key, key not found, or key is null

getKeys

public java.util.Iterator getKeys()
Get an Iterator over the Set of keys, allowing retrieval of the keys in the original order as listed in the properties file.

Returns:
Iterator

getPropsAsOrderedMap

private java.util.LinkedHashMap getPropsAsOrderedMap(java.io.BufferedReader propsReader)
                                              throws java.io.IOException
Get the properties as an ordered map.

Parameters:
propsReader - The reader that contains the properties. This method closes propsReader upon completion
Returns:
The properties.
Throws:
java.io.IOException

unescape

private java.lang.String unescape(java.lang.String line)

continueLine

private boolean continueLine(java.lang.String line)

getPropsFileNamePlusLocale

private static java.lang.String getPropsFileNamePlusLocale(java.lang.String baseName)
                                                    throws java.util.MissingResourceException,
                                                           java.lang.NullPointerException
Throws:
java.util.MissingResourceException
java.lang.NullPointerException