Home » commons-beanutils-1.8.3-src » org.apache.commons » collections » [javadoc | source]
org.apache.commons.collections
public class: ExtendedProperties [javadoc | source]
java.lang.Object
   java.util.Dictionary
      java.util.Hashtable
         org.apache.commons.collections.ExtendedProperties

All Implemented Interfaces:
    Map, Serializable, Cloneable

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:

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!

Nested Class Summary:
static class  ExtendedProperties.PropertiesReader  This class is used to read properties lines. These lines do not terminate with new-line chars but rather when there is no backslash sign a the end of the line. This is used to concatenate multiple lines for readability. 
static class  ExtendedProperties.PropertiesTokenizer  This class divides into tokens a property value. Token separator is "," but commas into the property value are escaped using the backslash in front. 
Field Summary
protected  String file    The file connected to this repository (holding comments and such).
    serial:
 
protected  String basePath    Base path of the configuration file used to create this ExtendedProperties object. 
protected  String fileSeparator    File separator. 
protected  boolean isInitialized    Has this configuration been intialized. 
protected static  String include    This is the name of the property that can point to other properties file for including other properties files. 
protected  ArrayList keysAsListed    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. 
protected static final  String START_TOKEN     
protected static final  String END_TOKEN     
Constructor:
 public ExtendedProperties() 
 public ExtendedProperties(String file) throws IOException 
    Creates and loads the extended properties from the specified file.
    Parameters:
    file - the filename to load
    Throws:
    IOException - if a file error occurs
 public ExtendedProperties(String file,
    String defaultFile) throws IOException 
    Creates and loads the extended properties from the specified file.
    Parameters:
    file - the filename to load
    defaultFile - a second filename to load default values from
    Throws:
    IOException - if a file error occurs
Method from org.apache.commons.collections.ExtendedProperties Summary:
addProperty,   clearProperty,   combine,   convertProperties,   display,   getBoolean,   getBoolean,   getBoolean,   getByte,   getByte,   getByte,   getDouble,   getDouble,   getDouble,   getFloat,   getFloat,   getFloat,   getInclude,   getInt,   getInt,   getInteger,   getInteger,   getInteger,   getKeys,   getKeys,   getList,   getList,   getLong,   getLong,   getLong,   getProperties,   getProperties,   getProperty,   getShort,   getShort,   getShort,   getString,   getString,   getStringArray,   getVector,   getVector,   interpolate,   interpolateHelper,   isInitialized,   load,   load,   save,   setInclude,   setProperty,   subset,   testBoolean
Methods from java.util.Hashtable:
access$100,   access$200,   access$210,   access$400,   access$500,   access$508,   clear,   clone,   contains,   containsKey,   containsValue,   elements,   entrySet,   equals,   get,   hashCode,   isEmpty,   keySet,   keys,   put,   putAll,   rehash,   remove,   size,   toString,   values
Methods from java.util.Dictionary:
elements,   get,   isEmpty,   keys,   put,   remove,   size
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.collections.ExtendedProperties Detail:
 public  void addProperty(String key,
    Object value) 
    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"]
 public  void clearProperty(String key) 
    Clear a property in the configuration.
 public  void combine(ExtendedProperties props) 
    Combines an existing Hashtable with this Hashtable.

    Warning: It will overwrite previous entries without warning.

 public static ExtendedProperties convertProperties(Properties props) 
    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.

 public  void display() 
    Display the configuration for debugging purposes to System.out.
 public boolean getBoolean(String key) 
    Get a boolean associated with the given configuration key.
 public boolean getBoolean(String key,
    boolean defaultValue) 
    Get a boolean associated with the given configuration key.
 public Boolean getBoolean(String key,
    Boolean defaultValue) 
    Get a boolean associated with the given configuration key.
 public byte getByte(String key) 
    Get a byte associated with the given configuration key.
 public byte getByte(String key,
    byte defaultValue) 
    Get a byte associated with the given configuration key.
 public Byte getByte(String key,
    Byte defaultValue) 
    Get a byte associated with the given configuration key.
 public double getDouble(String key) 
    Get a double associated with the given configuration key.
 public double getDouble(String key,
    double defaultValue) 
    Get a double associated with the given configuration key.
 public Double getDouble(String key,
    Double defaultValue) 
    Get a double associated with the given configuration key.
 public float getFloat(String key) 
    Get a float associated with the given configuration key.
 public float getFloat(String key,
    float defaultValue) 
    Get a float associated with the given configuration key.
 public Float getFloat(String key,
    Float defaultValue) 
    Get a float associated with the given configuration key.
 public String getInclude() 
    Gets the property value for including other properties files. By default it is "include".
 public int getInt(String name) 
    The purpose of this method is to get the configuration resource with the given name as an integer.
 public 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.
 public int getInteger(String key) 
    Get a int associated with the given configuration key.
 public int getInteger(String key,
    int defaultValue) 
    Get a int associated with the given configuration key.
 public Integer getInteger(String key,
    Integer defaultValue) 
    Get a int associated with the given configuration key.
 public Iterator getKeys() 
    Get the list of the keys contained in the configuration repository.
 public Iterator getKeys(String prefix) 
    Get the list of the keys contained in the configuration repository that match the specified prefix.
 public List getList(String key) 
    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.

 public List getList(String key,
    List defaultValue) 
    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.

 public long getLong(String key) 
    Get a long associated with the given configuration key.
 public long getLong(String key,
    long defaultValue) 
    Get a long associated with the given configuration key.
 public Long getLong(String key,
    Long defaultValue) 
    Get a long associated with the given configuration key.
 public Properties getProperties(String key) 
    Get a list of properties associated with the given configuration key.
 public Properties getProperties(String key,
    Properties defaults) 
    Get a list of properties associated with the given configuration key.
 public Object getProperty(String key) 
    Gets a property from the configuration.
 public short getShort(String key) 
    Get a short associated with the given configuration key.
 public short getShort(String key,
    short defaultValue) 
    Get a short associated with the given configuration key.
 public Short getShort(String key,
    Short defaultValue) 
    Get a short associated with the given configuration key.
 public String getString(String key) 
    Get a string associated with the given configuration key.
 public String getString(String key,
    String defaultValue) 
    Get a string associated with the given configuration key.
 public String[] getStringArray(String key) 
    Get an array of strings associated with the given configuration key.
 public Vector getVector(String key) 
    Get a Vector of strings associated with the given configuration key.
 public Vector getVector(String key,
    Vector defaultValue) 
    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.

 protected String interpolate(String base) 
    Interpolate key names to handle ${key} stuff
 protected String interpolateHelper(String base,
    List priorVariables) 
    Recursive handler for multiple levels of interpolation. When called the first time, priorVariables should be null.
 public boolean isInitialized() 
    Indicate to client code whether property resources have been initialized or not.
 public  void load(InputStream input) throws IOException 
    Load the properties from the given input stream.
 public synchronized  void load(InputStream input,
    String enc) throws IOException 
    Load the properties from the given input stream and using the specified encoding.
 public synchronized  void save(OutputStream output,
    String header) throws IOException 
    Save the properties to the given output stream.

    The stream is not closed, but it is flushed.

 public  void setInclude(String inc) 
    Sets the property value for including other properties files. By default it is "include".
 public  void setProperty(String key,
    Object value) 
    Set a property, this will replace any previously set values. Set values is implicitly a call to clearProperty(key), addProperty(key,value).
 public ExtendedProperties subset(String prefix) 
    Create an ExtendedProperties object that is a subset of this one. Take into account duplicate keys by using the setProperty() in ExtendedProperties.
 public String testBoolean(String value) 
    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.