org.apache.commons.configuration
Class BasePropertiesConfiguration

java.lang.Object
  extended byorg.apache.commons.configuration.AbstractConfiguration
      extended byorg.apache.commons.configuration.BaseConfiguration
          extended byorg.apache.commons.configuration.BasePathConfiguration
              extended byorg.apache.commons.configuration.BasePropertiesConfiguration
All Implemented Interfaces:
BasePathLoader, Configuration
Direct Known Subclasses:
ClassPropertiesConfiguration, PropertiesConfiguration

public abstract class BasePropertiesConfiguration
extends BasePathConfiguration

loads the configuration from a properties file.

The properties file 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.excaped = Hi\, what'up?
 
      # properties can reference other properties
      base.prop = /base
      first.prop = ${base.prop}/first
      second.prop = ${first.prop}/second
 

Version:
$Id: BasePropertiesConfiguration.java,v 1.1.1.1 2003/12/23 15:09:05 epugh Exp $
Author:
Stefano Mazzocchi, Jon S. Stevens, Dave Bryson, Geir Magnusson Jr., Leon Messerschmidt, Kent Johnson, Daniel Rall, Ilkka Priha, Jason van Zyl, Martin Poeschl, Henning P. Schmiedehausen

Nested Class Summary
(package private)  class BasePropertiesConfiguration.PropertiesReader
          This class is used to read properties lines.
(package private)  class BasePropertiesConfiguration.PropertiesWriter
          This class is used to write properties lines.
 
Nested classes inherited from class org.apache.commons.configuration.AbstractConfiguration
AbstractConfiguration.Container, AbstractConfiguration.PropertiesTokenizer
 
Field Summary
protected static java.lang.String include
          This is the name of the property that can point to other properties file for including other properties files.
private  boolean includesAllowed
          Allow file inclusion or not
 
Fields inherited from class org.apache.commons.configuration.BasePathConfiguration
 
Fields inherited from class org.apache.commons.configuration.BaseConfiguration
 
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration
defaults, END_TOKEN, START_TOKEN
 
Constructor Summary
BasePropertiesConfiguration()
           
 
Method Summary
 java.lang.String getInclude()
          Gets the property value for including other properties files.
 boolean getIncludesAllowed()
          Reports the status of file inclusion.
protected abstract  java.io.InputStream getPropertyStream(java.lang.String resourceName)
          Implementations of this class must implement this method.
 void load(java.io.InputStream input)
          Load the properties from the given input stream.
 void load(java.io.InputStream input, java.lang.String enc)
          Load the properties from the given input stream and using the specified encoding.
 void save(java.lang.String filename)
          save properties to a file.
 void setInclude(java.lang.String inc)
          Sets the property value for including other properties files.
protected  void setIncludesAllowed(boolean includesAllowed)
          Controls whether additional files can be loaded by the include = statement or not.
 
Methods inherited from class org.apache.commons.configuration.BasePathConfiguration
getBasePath, setBasePath
 
Methods inherited from class org.apache.commons.configuration.BaseConfiguration
addPropertyDirect, clearProperty, containsKey, getKeys, getPropertyDirect, isEmpty
 
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration
addProperty, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolateHelper, processString, setProperty, subset, testBoolean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

includesAllowed

private boolean includesAllowed
Allow file inclusion or not


include

protected static java.lang.String include
This is the name of the property that can point to other properties file for including other properties files.

Constructor Detail

BasePropertiesConfiguration

public BasePropertiesConfiguration()
Method Detail

getPropertyStream

protected abstract java.io.InputStream getPropertyStream(java.lang.String resourceName)
                                                  throws java.io.IOException
Implementations of this class must implement this method.

Parameters:
resourceName - The Resource to load
Returns:
An Input Stream
Throws:
java.io.IOException - Error while loading the properties file

load

public void load(java.io.InputStream input)
          throws java.io.IOException
Load the properties from the given input stream.

Parameters:
input - An InputStream.
Throws:
java.io.IOException

load

public void load(java.io.InputStream input,
                 java.lang.String enc)
          throws java.io.IOException
Load the properties from the given input stream and using the specified encoding.

Parameters:
input - An InputStream.
enc - An encoding.
Throws:
java.io.IOException

save

public void save(java.lang.String filename)
          throws java.io.IOException
save properties to a file. properties with multiple values are saved comma seperated.

Parameters:
filename - name of the properties file
Throws:
java.io.IOException

getInclude

public java.lang.String getInclude()
Gets the property value for including other properties files. By default it is "include".

Returns:
A String.

setInclude

public void setInclude(java.lang.String inc)
Sets the property value for including other properties files. By default it is "include".

Parameters:
inc - A String.

setIncludesAllowed

protected void setIncludesAllowed(boolean includesAllowed)
Controls whether additional files can be loaded by the include = statement or not. Base rule is, that objects created by the empty C'tor can not have included files.

Parameters:
includesAllowed - includesAllowed True if Includes are allowed.

getIncludesAllowed

public boolean getIncludesAllowed()
Reports the status of file inclusion.

Returns:
True if include files are loaded.