java.lang.Object | |||
↳ | java.util.Dictionary<K, V> | ||
↳ | java.util.Hashtable<K, V> | ||
↳ | org.apache.commons.collections.ExtendedProperties |
This class extends normal Java properties by adding the possibility to use the same key many times concatenating the value strings instead of overwriting them.
Please consider using the PropertiesConfiguration
class in
Commons-Configuration as soon as it is released.
The Extended Properties syntax is explained here:
key = value
Here is an example of a valid extended properties file:
# lines starting with # are comments # This is the simplest property key = value # A long property may be separated on multiple lines longvalue = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa # This is a property with many tokens tokens_on_a_line = first token, second token # This sequence generates exactly the same result tokens_on_multiple_lines = first token tokens_on_multiple_lines = second token # commas may be escaped in tokens commas.escaped = Hi\, what'up?
NOTE: this class has not been written for performance nor low memory usage. In fact, it's way slower than it could be and generates too much memory garbage. But since performance is not an issue during intialization (and there is not much time to improve it), I wrote it this way. If you don't like it, go ahead and tune it up!
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | END_TOKEN | ||||||||||
String | START_TOKEN |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
basePath | Base path of the configuration file used to create this ExtendedProperties object. | ||||||||||
file | The file connected to this repository (holding comments and such). | ||||||||||
fileSeparator | File separator. | ||||||||||
include | This is the name of the property that can point to other properties file for including other properties files. | ||||||||||
isInitialized | Has this configuration been intialized. | ||||||||||
keysAsListed | These are the keys in the order they listed in the configuration file. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates an empty extended properties object.
| |||||||||||
Creates and loads the extended properties from the specified file.
| |||||||||||
Creates and loads the extended properties from the specified file.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Add a property to the configuration.
| |||||||||||
Clear a property in the configuration.
| |||||||||||
Combines an existing Hashtable with this Hashtable.
| |||||||||||
Convert a standard properties class into a configuration class.
| |||||||||||
Display the configuration for debugging purposes to System.out.
| |||||||||||
Get a boolean associated with the given configuration key.
| |||||||||||
Get a boolean associated with the given configuration key.
| |||||||||||
Get a boolean associated with the given configuration key.
| |||||||||||
Get a byte associated with the given configuration key.
| |||||||||||
Get a byte associated with the given configuration key.
| |||||||||||
Get a byte associated with the given configuration key.
| |||||||||||
Get a double associated with the given configuration key.
| |||||||||||
Get a double associated with the given configuration key.
| |||||||||||
Get a double associated with the given configuration key.
| |||||||||||
Get a float associated with the given configuration key.
| |||||||||||
Get a float associated with the given configuration key.
| |||||||||||
Get a float associated with the given configuration key.
| |||||||||||
Gets the property value for including other properties files.
| |||||||||||
The purpose of this method is to get the configuration resource
with the given name as an integer, or a default value.
| |||||||||||
The purpose of this method is to get the configuration resource
with the given name as an integer.
| |||||||||||
Get a int associated with the given configuration key.
| |||||||||||
Get a int associated with the given configuration key.
| |||||||||||
Get a int associated with the given configuration key.
| |||||||||||
Get the list of the keys contained in the configuration
repository.
| |||||||||||
Get the list of the keys contained in the configuration
repository that match the specified prefix.
| |||||||||||
Get a List of strings associated with the given configuration key.
| |||||||||||
Get a List of strings associated with the given configuration key.
| |||||||||||
Get a long associated with the given configuration key.
| |||||||||||
Get a long associated with the given configuration key.
| |||||||||||
Get a long associated with the given configuration key.
| |||||||||||
Get a list of properties associated with the given
configuration key.
| |||||||||||
Get a list of properties associated with the given
configuration key.
| |||||||||||
Gets a property from the configuration.
| |||||||||||
Get a short associated with the given configuration key.
| |||||||||||
Get a short associated with the given configuration key.
| |||||||||||
Get a short associated with the given configuration key.
| |||||||||||
Get a string associated with the given configuration key.
| |||||||||||
Get a string associated with the given configuration key.
| |||||||||||
Get an array of strings associated with the given configuration
key.
| |||||||||||
Get a Vector of strings associated with the given configuration
key.
| |||||||||||
Get a Vector of strings associated with the given configuration key.
| |||||||||||
Indicate to client code whether property
resources have been initialized or not.
| |||||||||||
Load the properties from the given input stream.
| |||||||||||
Load the properties from the given input stream
and using the specified encoding.
| |||||||||||
Save the properties to the given output stream.
| |||||||||||
Sets the property value for including other properties files.
| |||||||||||
Set a property, this will replace any previously
set values.
| |||||||||||
Create an ExtendedProperties object that is a subset
of this one.
| |||||||||||
Test whether the string represent by value maps to a boolean
value or not.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Interpolate key names to handle ${key} stuff
| |||||||||||
Recursive handler for multiple levels of interpolation.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.util.Hashtable
| |||||||||||
From class
java.util.Dictionary
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.util.Map
|
Base path of the configuration file used to create this ExtendedProperties object.
This is the name of the property that can point to other properties file for including other properties files.
Has this configuration been intialized.
These are the keys in the order they listed in the configuration file. This is useful when you wish to perform operations with configuration information in a particular order.
Creates an empty extended properties object.
Creates and loads the extended properties from the specified file.
file | the filename to load |
---|
IOException | if a file error occurs |
---|
Creates and loads the extended properties from the specified file.
file | the filename to load |
---|---|
defaultFile | a second filename to load default values from |
IOException | if a file error occurs |
---|
Add a property to the configuration. If it already
exists then the value stated here will be added
to the configuration entry. For example, if
resource.loader = file
is already present in the configuration and you
addProperty("resource.loader", "classpath")
Then you will end up with a Vector like the
following:
["file", "classpath"]
key | the key to add |
---|---|
value | the value to add |
Clear a property in the configuration.
key | the property key to remove along with corresponding value |
---|
Combines an existing Hashtable with this Hashtable.
Warning: It will overwrite previous entries without warning.
props | the properties to combine |
---|
Convert a standard properties class into a configuration class.
NOTE: From Commons Collections 3.2 this method will pick up any default parent Properties of the specified input object.
props | the properties object to convert |
---|
Display the configuration for debugging purposes to System.out.
Get a boolean associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Boolean. |
---|
Get a boolean associated with the given configuration key.
key | The configuration key. |
---|
NoSuchElementException | is thrown if the key doesn't map to an existing object. |
---|---|
ClassCastException | is thrown if the key maps to an object that is not a Boolean. |
Get a boolean associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Boolean. |
---|
Get a byte associated with the given configuration key.
key | The configuration key. |
---|
NoSuchElementException | is thrown if the key doesn't map to an existing object. |
---|---|
ClassCastException | is thrown if the key maps to an object that is not a Byte. |
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a byte associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Byte. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a byte associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Byte. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a double associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Double. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a double associated with the given configuration key.
key | The configuration key. |
---|
NoSuchElementException | is thrown if the key doesn't map to an existing object. |
---|---|
ClassCastException | is thrown if the key maps to an object that is not a Double. |
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a double associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Double. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a float associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Float. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a float associated with the given configuration key.
key | The configuration key. |
---|
NoSuchElementException | is thrown if the key doesn't map to an existing object. |
---|---|
ClassCastException | is thrown if the key maps to an object that is not a Float. |
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a float associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Float. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Gets the property value for including other properties files. By default it is "include".
The purpose of this method is to get the configuration resource with the given name as an integer, or a default value.
name | The resource name |
---|---|
def | The default value of the resource. |
The purpose of this method is to get the configuration resource with the given name as an integer.
name | The resource name. |
---|
Get a int associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Integer. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a int associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Integer. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a int associated with the given configuration key.
key | The configuration key. |
---|
NoSuchElementException | is thrown if the key doesn't map to an existing object. |
---|---|
ClassCastException | is thrown if the key maps to an object that is not a Integer. |
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get the list of the keys contained in the configuration repository.
Get the list of the keys contained in the configuration repository that match the specified prefix.
prefix | the prefix to match |
---|
Get a List of strings associated with the given configuration key.
The list is a copy of the internal data of this object, and as such you may alter it freely.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a List. |
---|
Get a List of strings associated with the given configuration key.
The list is a copy of the internal data of this object, and as such you may alter it freely.
key | The configuration key. |
---|
ClassCastException | is thrown if the key maps to an object that is not a List. |
---|
Get a long associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Long. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a long associated with the given configuration key.
key | The configuration key. |
---|
NoSuchElementException | is thrown if the key doesn't map to an existing object. |
---|---|
ClassCastException | is thrown if the key maps to an object that is not a Long. |
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a long associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Long. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a list of properties associated with the given configuration key.
key | The configuration key. |
---|
ClassCastException | is thrown if the key maps to an object that is not a String/List. |
---|---|
IllegalArgumentException | if one of the tokens is malformed (does not contain an equals sign). |
Get a list of properties associated with the given configuration key.
key | The configuration key. |
---|
ClassCastException | is thrown if the key maps to an object that is not a String/List. |
---|---|
IllegalArgumentException | if one of the tokens is malformed (does not contain an equals sign). |
Gets a property from the configuration.
key | property to retrieve |
---|
Get a short associated with the given configuration key.
key | The configuration key. |
---|
NoSuchElementException | is thrown if the key doesn't map to an existing object. |
---|---|
ClassCastException | is thrown if the key maps to an object that is not a Short. |
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a short associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Short. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a short associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Short. |
---|---|
NumberFormatException | is thrown if the value mapped by the key has not a valid number format. |
Get a string associated with the given configuration key.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a String. |
---|
Get a string associated with the given configuration key.
key | The configuration key. |
---|
ClassCastException | is thrown if the key maps to an object that is not a String. |
---|
Get an array of strings associated with the given configuration key.
key | The configuration key. |
---|
ClassCastException | is thrown if the key maps to an object that is not a String/List. |
---|
Get a Vector of strings associated with the given configuration key.
key | The configuration key. |
---|
ClassCastException | is thrown if the key maps to an object that is not a Vector. |
---|
Get a Vector of strings associated with the given configuration key.
The list is a copy of the internal data of this object, and as such you may alter it freely.
key | The configuration key. |
---|---|
defaultValue | The default value. |
ClassCastException | is thrown if the key maps to an object that is not a Vector. |
---|
Indicate to client code whether property resources have been initialized or not.
Load the properties from the given input stream.
input | the InputStream to load from |
---|
IOException | if an IO error occurs |
---|
Load the properties from the given input stream and using the specified encoding.
input | the InputStream to load from |
---|---|
enc | the encoding to use |
IOException | if an IO error occurs |
---|
Save the properties to the given output stream.
The stream is not closed, but it is flushed.
output | an OutputStream, may be null |
---|---|
header | a textual comment to act as a file header |
IOException | if an IO error occurs |
---|
Sets the property value for including other properties files. By default it is "include".
inc | A String. |
---|
Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key,value).
key | the key to set |
---|---|
value | the value to set |
Create an ExtendedProperties object that is a subset of this one. Take into account duplicate keys by using the setProperty() in ExtendedProperties.
prefix | the prefix to get a subset for |
---|
Test whether the string represent by value maps to a boolean
value or not. We will allow true
, on
,
and yes
for a true
boolean value, and
false
, off
, and no
for
false
boolean values. Case of value to test for
boolean status is ignored.
value | the value to test for boolean state |
---|
true
or false
if the supplied
text maps to a boolean value, or null
otherwise.
Interpolate key names to handle ${key} stuff
base | string to interpolate |
---|
Recursive handler for multiple levels of interpolation. When called the first time, priorVariables should be null.
base | string with the ${key} variables |
---|---|
priorVariables | serves two purposes: to allow checking for loops, and creating a meaningful exception message should a loop occur. It's 0'th element will be set to the value of base from the first call. All subsequent interpolated variables are added afterward. |