Hashtable | +--org.apache.commons.collections.ExtendedProperties
String | Base path of the configuration file used to create this ExtendedProperties object. |
static String | |
String | The file connected to this repository (holding comments and such). |
String | File separator. |
static String | This is the name of the property that can point to other properties file for including other properties files. |
boolean | Has this configuration been intialized. |
ArrayList | These are the keys in the order they listed in the configuration file. |
static String |
Creates an empty extended properties object. |
ExtendedProperties(String file) Creates and loads the extended properties from the specified file. |
ExtendedProperties(String file, String defaultFile) Creates and loads the extended properties from the specified file. |
void | addProperty(String key, Object token) Add a property to the configuration. |
void | clearProperty(String key) Clear a property in the configuration. |
void | combine(ExtendedProperties props) Combines an existing Hashtable with this Hashtable. |
static ExtendedProperties | convertProperties(Properties props) Convert a standard properties class into a configuration class. |
void | display() Display the configuration for debugging purposes to System.out. |
boolean | getBoolean(String key) Get a boolean associated with the given configuration key. |
boolean | getBoolean(String key, boolean defaultValue) Get a boolean associated with the given configuration key. |
Boolean | getBoolean(String key, Boolean defaultValue) Get a boolean associated with the given configuration key. |
byte | getByte(String key) Get a byte associated with the given configuration key. |
byte | getByte(String key, byte defaultValue) Get a byte associated with the given configuration key. |
Byte | getByte(String key, Byte defaultValue) Get a byte associated with the given configuration key. |
double | getDouble(String key) Get a double associated with the given configuration key. |
double | getDouble(String key, double defaultValue) Get a double associated with the given configuration key. |
Double | getDouble(String key, Double defaultValue) Get a double associated with the given configuration key. |
float | getFloat(String key) Get a float associated with the given configuration key. |
float | getFloat(String key, float defaultValue) Get a float associated with the given configuration key. |
Float | getFloat(String key, Float defaultValue) Get a float associated with the given configuration key. |
String | Gets the property value for including other properties files. |
int | getInt(String name) The purpose of this method is to get the configuration resource with the given name as an integer. |
int | getInt(String name, int def) The purpose of this method is to get the configuration resource with the given name as an integer, or a default value. |
int | getInteger(String key) Get a int associated with the given configuration key. |
int | getInteger(String key, int defaultValue) Get a int associated with the given configuration key. |
Integer | getInteger(String key, Integer defaultValue) Get a int associated with the given configuration key. |
Iterator | getKeys() Get the list of the keys contained in the configuration repository. |
Iterator | getKeys(String prefix) Get the list of the keys contained in the configuration repository that match the specified prefix. |
long | getLong(String key) Get a long associated with the given configuration key. |
long | getLong(String key, long defaultValue) Get a long associated with the given configuration key. |
Long | getLong(String key, Long defaultValue) Get a long associated with the given configuration key. |
Properties | getProperties(String key) Get a list of properties associated with the given configuration key. |
Properties | getProperties(String key, Properties defaults) Get a list of properties associated with the given configuration key. |
Object | getProperty(String key) Gets a property from the configuration. |
short | getShort(String key) Get a short associated with the given configuration key. |
short | getShort(String key, short defaultValue) Get a short associated with the given configuration key. |
Short | getShort(String key, Short defaultValue) Get a short associated with the given configuration key. |
String | getString(String key) Get a string associated with the given configuration key. |
String | getString(String key, String defaultValue) Get a string associated with the given configuration key. |
String[] | getStringArray(String key) Get an array of strings associated with the given configuration key. |
Vector | getVector(String key) Get a Vector of strings associated with the given configuration key. |
Vector | getVector(String key, Vector defaultValue) Get a Vector of strings associated with the given configuration key. |
String | interpolate(String base) Interpolate key names to handle ${key} stuff |
String | interpolateHelper(String base, List priorVariables) Recursive handler for multiple levels of interpolation. |
boolean | Indicate to client code whether property resources have been initialized or not. |
void | load(InputStream input) Load the properties from the given input stream. |
synchronized void | load(InputStream input, String enc) Load the properties from the given input stream and using the specified encoding. |
synchronized void | save(OutputStream output, String header) Save the properties to the given output stream. |
void | setInclude(String inc) Sets the property value for including other properties files. |
void | setProperty(String key, Object value) Set a property, this will replace any previously set values. |
subset(String prefix) Create an ExtendedProperties object that is a subset of this one. | |
String | testBoolean(String value) Test whether the string represent by value maps to a boolean value or not. |
protected String basePath
protected static final String END_TOKEN
protected String file
protected String fileSeparator
protected static String include
protected boolean isInitialized
protected ArrayList keysAsListed
protected static final String START_TOKEN
public ExtendedProperties()
public ExtendedProperties(String file, String defaultFile)
- if a file error occurspublic ExtendedProperties(String file)
- if a file error occurspublic void addProperty(String key, Object token)
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"]
public void clearProperty(String key)
public void combine(ExtendedProperties props)
public static ExtendedProperties convertProperties(Properties props)
public void display()
public boolean getBoolean(String key, boolean defaultValue)
- is thrown if the key maps to an
object that is not a Boolean.public Boolean getBoolean(String key, Boolean defaultValue)
- is thrown if the key maps to an
object that is not a Boolean.public boolean getBoolean(String key)
- is thrown if the key doesn't
map to an existing object.
- is thrown if the key maps to an
object that is not a Boolean.public byte getByte(String key, byte defaultValue)
- is thrown if the key maps to an
object that is not a Byte.
- is thrown if the value mapped
by the key has not a valid number format.public Byte getByte(String key, Byte defaultValue)
- is thrown if the key maps to an
object that is not a Byte.
- is thrown if the value mapped
by the key has not a valid number format.public byte getByte(String key)
- is thrown if the key doesn't
map to an existing object.
- is thrown if the key maps to an
object that is not a Byte.
- is thrown if the value mapped
by the key has not a valid number format.public double getDouble(String key, double defaultValue)
- is thrown if the key maps to an
object that is not a Double.
- is thrown if the value mapped
by the key has not a valid number format.public Double getDouble(String key, Double defaultValue)
- is thrown if the key maps to an
object that is not a Double.
- is thrown if the value mapped
by the key has not a valid number format.public double getDouble(String key)
- is thrown if the key doesn't
map to an existing object.
- is thrown if the key maps to an
object that is not a Double.
- is thrown if the value mapped
by the key has not a valid number format.public float getFloat(String key, float defaultValue)
- is thrown if the key maps to an
object that is not a Float.
- is thrown if the value mapped
by the key has not a valid number format.public Float getFloat(String key, Float defaultValue)
- is thrown if the key maps to an
object that is not a Float.
- is thrown if the value mapped
by the key has not a valid number format.public float getFloat(String key)
- is thrown if the key doesn't
map to an existing object.
- is thrown if the key maps to an
object that is not a Float.
- is thrown if the value mapped
by the key has not a valid number format.public String getInclude()
public int getInt(String name, int def)
public int getInt(String name)
public int getInteger(String key, int defaultValue)
- is thrown if the key maps to an
object that is not a Integer.
- is thrown if the value mapped
by the key has not a valid number format.public Integer getInteger(String key, Integer defaultValue)
- is thrown if the key maps to an
object that is not a Integer.
- is thrown if the value mapped
by the key has not a valid number format.public int getInteger(String key)
- is thrown if the key doesn't
map to an existing object.
- is thrown if the key maps to an
object that is not a Integer.
- is thrown if the value mapped
by the key has not a valid number format.public Iterator getKeys()
public Iterator getKeys(String prefix)
public long getLong(String key, long defaultValue)
- is thrown if the key maps to an
object that is not a Long.
- is thrown if the value mapped
by the key has not a valid number format.public Long getLong(String key, Long defaultValue)
- is thrown if the key maps to an
object that is not a Long.
- is thrown if the value mapped
by the key has not a valid number format.public long getLong(String key)
- is thrown if the key doesn't
map to an existing object.
- is thrown if the key maps to an
object that is not a Long.
- is thrown if the value mapped
by the key has not a valid number format.public Properties getProperties(String key, Properties defaults)
- is thrown if the key maps to an
object that is not a String/Vector.
- if one of the tokens is
malformed (does not contain an equals sign).public Properties getProperties(String key)
- is thrown if the key maps to an
object that is not a String/Vector.
- if one of the tokens is
malformed (does not contain an equals sign).public Object getProperty(String key)
public short getShort(String key, short defaultValue)
- is thrown if the key maps to an
object that is not a Short.
- is thrown if the value mapped
by the key has not a valid number format.public Short getShort(String key, Short defaultValue)
- is thrown if the key maps to an
object that is not a Short.
- is thrown if the value mapped
by the key has not a valid number format.public short getShort(String key)
- is thrown if the key doesn't
map to an existing object.
- is thrown if the key maps to an
object that is not a Short.
- is thrown if the value mapped
by the key has not a valid number format.public String getString(String key, String defaultValue)
- is thrown if the key maps to an
object that is not a String.public String getString(String key)
- is thrown if the key maps to an
object that is not a String.public String[] getStringArray(String key)
- is thrown if the key maps to an
object that is not a String/Vector.public Vector getVector(String key, Vector defaultValue)
- is thrown if the key maps to an
object that is not a Vector.public Vector getVector(String key)
- is thrown if the key maps to an
object that is not a Vector.protected String interpolate(String base)
protected String interpolateHelper(String base, List priorVariables)
public boolean isInitialized()
public synchronized void load(InputStream input, String enc)
- if an IO error occurspublic void load(InputStream input)
- if an IO error occurspublic synchronized void save(OutputStream output, String header)
- if an IO error occurspublic void setInclude(String inc)
public void setProperty(String key, Object value)
public ExtendedProperties subset(String prefix)
public String testBoolean(String value)
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.
PropertiesConfiguration
class in Commons-Configuration as soon as it is released. The Extended Properties syntax is explained here:-
Each property has the syntax
-
The key may use any character but the equal sign '='.
- value may be separated on different lines if a backslash
is placed at the end of the line that continues below.
-
If value is a list of strings, each token is separated
by a comma ','.
-
Commas in each token are escaped placing a backslash right before
the comma.
-
Backslashes are escaped by using two consecutive backslashes i.e. \\
-
If a key is used more than once, the values are appended
like if they were on the same line separated with commas.
-
Blank lines and lines starting with character '#' are skipped.
-
If a property is named "include" (or whatever is defined by
setInclude() and getInclude() and the value of that property is
the full path to a file on disk, that file will be included into
the ConfigurationsRepository. You can also pull in files relative
to the parent configuration file. So if you have something
like the following:
include = additional.properties
Then "additional.properties" is expected to be in the same
directory as the parent configuration file.
Duplicate name values will be replaced, so be careful.
Here is an example of a valid extended properties file: 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!key = value