org.apache.commons.configuration

Class XMLPropertiesConfiguration

public class XMLPropertiesConfiguration extends PropertiesConfiguration

This configuration implements the XML properties format introduced in Java 5.0, see http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html. An XML properties file looks like this:
 <?xml version="1.0"?>
 <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
 <properties>
   <comment>Description of the property list</comment>
   <entry key="key1">value1</entry>
   <entry key="key2">value2</entry>
   <entry key="key3">value3</entry>
 </properties>
 
The Java 5.0 runtime is not required to use this class. The default encoding for this configuration format is UTF-8. Note that unlike PropertiesConfiguration, XMLPropertiesConfiguration does not support includes.

Since: 1.1

Version: $Revision: 439648 $, $Date: 2006-09-02 22:42:10 +0200 (Sa, 02 Sep 2006) $

Author: Emmanuel Bourg Alistair Young

Nested Class Summary
classXMLPropertiesConfiguration.XMLPropertiesHandler
SAX Handler to parse a XML properties file.
Field Summary
static StringDEFAULT_ENCODING
The default encoding (UTF-8 as specified by http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html)
Constructor Summary
XMLPropertiesConfiguration()
Creates an empty XMLPropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().
XMLPropertiesConfiguration(String fileName)
Creates and loads the xml properties from the specified file.
XMLPropertiesConfiguration(File file)
Creates and loads the xml properties from the specified file.
XMLPropertiesConfiguration(URL url)
Creates and loads the xml properties from the specified URL.
Method Summary
voidload(Reader in)
voidsave(Writer out)
voidwriteProperty(PrintWriter out, String key, Object value)
Write a property.
voidwriteProperty(PrintWriter out, String key, List values)
Write a list property.

Field Detail

DEFAULT_ENCODING

private static final String DEFAULT_ENCODING
The default encoding (UTF-8 as specified by http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html)

Constructor Detail

XMLPropertiesConfiguration

public XMLPropertiesConfiguration()
Creates an empty XMLPropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving(). An object constructed by this C'tor can not be tickled into loading included files because it cannot supply a base for relative includes.

XMLPropertiesConfiguration

public XMLPropertiesConfiguration(String fileName)
Creates and loads the xml properties from the specified file. The specified file can contain "include" properties which then are loaded and merged into the properties.

Parameters: fileName The name of the properties file to load.

Throws: ConfigurationException Error while loading the properties file

XMLPropertiesConfiguration

public XMLPropertiesConfiguration(File file)
Creates and loads the xml properties from the specified file. The specified file can contain "include" properties which then are loaded and merged into the properties.

Parameters: file The properties file to load.

Throws: ConfigurationException Error while loading the properties file

XMLPropertiesConfiguration

public XMLPropertiesConfiguration(URL url)
Creates and loads the xml properties from the specified URL. The specified file can contain "include" properties which then are loaded and merged into the properties.

Parameters: url The location of the properties file to load.

Throws: ConfigurationException Error while loading the properties file

Method Detail

load

public void load(Reader in)

save

public void save(Writer out)

writeProperty

private void writeProperty(PrintWriter out, String key, Object value)
Write a property.

Parameters: out the output stream key the key of the property value the value of the property

writeProperty

private void writeProperty(PrintWriter out, String key, List values)
Write a list property.

Parameters: out the output stream key the key of the property values a list with all property values