com.retek.commons.gui.util
Class RPropertyBundle

java.lang.Object
  extended bycom.retek.commons.gui.util.RPropertyBundle

public class RPropertyBundle
extends java.lang.Object

This class loads a property file consisting of a KEY = VALUE pairs, usually on each line of the file. RPropertyBundle places these keys and values in a HashMap for storage as Strings. The KEY may contain spaces, colons and semi-colons, but may NOT contain an "=" sign. It is the only prohibited part of the key.

The character "\" at the end of a line signifies line continuance allowing multiple lines to make up a single key-value pair. The "!" or "#" at the beginning of a line indicate a comment line and will be ignored, as will a blank line.

This class contains a set of methods to retrieve the information in the property file in different formats. It currently supports Boolean, Integer, Double, String and String[].

An absolute filename will automatically be used. If only a filename is supplied, this bundle looks first in the execution directory and then in the classpath to find the file. This class uses the PROPERTY_ENCODING variable of Utility to set the file encoding that will be used to read in the property file. The default value is UTF-16 format, the standard Unicode format on Windows platform.

Retek Inc. Copyright (c) 2002


Constructor Summary
RPropertyBundle()
          Creates and returns new empty RPropertyBundle object.
RPropertyBundle(java.lang.String filename)
          Creates and returns a new RPropertyBundle object.
RPropertyBundle(java.lang.String filename, java.lang.String encoding)
          Creates and returns a new RPropertyBundle object.
 
Method Summary
 void clear()
          Removes all key/value pairs from the property bundle.
 java.lang.Boolean getBoolean(java.lang.String key)
          Retrieves a property value for the given key as an Boolean object.
 char getChar(java.lang.String key)
          Retrieves a property value for the given key as an Boolean object.
 java.lang.Double getDouble(java.lang.String key)
          Retrieves a property value for the given key as an Double object.
 java.lang.Integer getInteger(java.lang.String key)
          Retrieves a property value for the given key as an Integer object.
 java.lang.String[] getKeys()
          Retrieves a string array of the entire key set of the bundle.
 java.lang.String getString(java.lang.String key)
          Retrieves a property value for the given key as a String object.
 java.lang.String[] getStringArray(java.lang.String key)
          Retrieves a property value for the given key as a String array.
 boolean isEmpty()
          Retrieves whether or not the property bundle is empty.
 void loadPropertyBundle(java.lang.String filename)
          Loads a file into the property resource bundle, parsing the KEY-VALUE information stored within the file and stores it internally.
 void loadPropertyBundle(java.lang.String filename, java.lang.String encoding)
          Loads a file into the property resource bundle, parsing the KEY-VALUE information stored within the file and storing it internally.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RPropertyBundle

public RPropertyBundle()
Creates and returns new empty RPropertyBundle object.


RPropertyBundle

public RPropertyBundle(java.lang.String filename)
                throws UiBundleException
Creates and returns a new RPropertyBundle object. It will create the bundle with a properties file with the matching filename.

Parameters:
filename - The file name of the property file to load.
Throws:
UiBundleException - Thrown if the method fails to load the property bundle file.

RPropertyBundle

public RPropertyBundle(java.lang.String filename,
                       java.lang.String encoding)
                throws UiBundleException
Creates and returns a new RPropertyBundle object. It will create the bundle with a properties file with the matching filename.

Parameters:
filename - The file name of the property file to load.
encoding - The character encoding to use when reading the property file.
Throws:
UiBundleException - Thrown if the method fails to load the property bundle file.
Method Detail

clear

public void clear()
Removes all key/value pairs from the property bundle.


isEmpty

public boolean isEmpty()
Retrieves whether or not the property bundle is empty.

Returns:
True if the property bundle is empty, false if it is not.

getKeys

public java.lang.String[] getKeys()
Retrieves a string array of the entire key set of the bundle.

Returns:
An string array of the entire key set of the bundle.

getChar

public char getChar(java.lang.String key)
Retrieves a property value for the given key as an Boolean object. This method will return a null value if the requested property does not exist or is not a valid boolean value.

Parameters:
key - The key to retrieve a property value for.
Returns:
The property value converted into a Boolean object.

getBoolean

public java.lang.Boolean getBoolean(java.lang.String key)
Retrieves a property value for the given key as an Boolean object. This method will return a null value if the requested property does not exist or is not a valid boolean value.

Parameters:
key - The key to retrieve a property value for.
Returns:
The property value converted into a Boolean object.

getInteger

public java.lang.Integer getInteger(java.lang.String key)
Retrieves a property value for the given key as an Integer object. This method will return a null object if the requested property does not exist or is not a valid integer.

Parameters:
key - The key to retrieve a property value for.
Returns:
The property value converted into an Integer object.

getDouble

public java.lang.Double getDouble(java.lang.String key)
Retrieves a property value for the given key as an Double object. This method will return a null object if the requested property does not exist or is not a valid double.

Parameters:
key - The key to retrieve a property value for.
Returns:
The property value converted into an Double object.

getString

public java.lang.String getString(java.lang.String key)
Retrieves a property value for the given key as a String object. This method returns the original key if a value was not found. Since the key is a String, this is the only get() method that returns the key in such a manner.

Parameters:
key - The key to retrieve a property value for.
Returns:
The property value converted into a String object.

getStringArray

public java.lang.String[] getStringArray(java.lang.String key)
Retrieves a property value for the given key as a String array. This method returns a null array if the value was not found. If a value is found, it will be parsed on commas (',') to determine the breaks in the string.

Parameters:
key - The key to retrieve a property value for.
Returns:
The property value converted into a String array.

loadPropertyBundle

public void loadPropertyBundle(java.lang.String filename)
                        throws UiBundleException
Loads a file into the property resource bundle, parsing the KEY-VALUE information stored within the file and stores it internally.

Note that this method does not clear the bundle before loading the file. This allows for loading multiple files into the same property bundle.

Parameters:
filename - The file name of the property file to load.
Throws:
UiBundleException - Thrown if the fileName is not a valid file, a file IO error occurs, or the data in the file is not properly formatted.

loadPropertyBundle

public void loadPropertyBundle(java.lang.String filename,
                               java.lang.String encoding)
                        throws UiBundleException
Loads a file into the property resource bundle, parsing the KEY-VALUE information stored within the file and storing it internally.

Note that this method does not clear the bundle before loading the file. This allows for loading multiple files into the same property bundle.

Notes that this method checks for at least 3 bytes of information exists in the file so that it doesn't attempt to read empty Unicode files where the first two bytes indicate only the encoding.

Parameters:
filename - The file name of the property file to load.
encoding - The character encoding to use when reading the file.
Throws:
UiBundleException - Thrown if the fileName is not a valid file, a file IO error occurs, or the data in the file is not properly formatted.


Copyright © 2004 Retek Inc. All Rights Reserved. - Generated at Fri, 10/22/2004 07:28