Class XMLPropertiesConfiguration

All Implemented Interfaces:
Cloneable, Configuration, EventSource, FileBasedConfiguration, ImmutableConfiguration, FileBased, FileLocatorAware, SynchronizerSupport

This configuration implements the XML properties format introduced in Java, see https://docs.oracle.com/javase/8/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 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. Note:Configuration objects of this type can be read concurrently by multiple threads. However if one of these threads modifies the object, synchronization has to be performed manually.
Since:
1.1
  • Field Details

    • DEFAULT_ENCODING

      public static final String DEFAULT_ENCODING
      The default encoding (UTF-8 as specified by https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html)
  • Constructor Details

    • 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

      Creates and loads the XML properties from the specified DOM node.
      Parameters:
      element - The non-null DOM element.
      Throws:
      ConfigurationException - Error while loading the Element.
      Since:
      2.0
  • Method Details

    • getHeader

      public String getHeader()
      Gets the header comment of this configuration.
      Returns:
      the header comment
    • initFileLocator

      public void initFileLocator(FileLocator locator)
      Initializes this object with a FileLocator. The locator is accessed during load and save operations.
      Specified by:
      initFileLocator in interface FileLocatorAware
      Parameters:
      locator - the associated FileLocator
    • load

      public void load(Element element) throws ConfigurationException
      Parses a DOM element containing the properties. The DOM element has to follow the XML properties format introduced in Java, see https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html
      Parameters:
      element - The DOM element
      Throws:
      ConfigurationException - Error while interpreting the DOM
      Since:
      2.0
    • read

      public void read(Reader in) throws ConfigurationException
      Description copied from interface: FileBased
      Reads the content of this object from the given reader. Client code should not call this method directly, but use a FileHandler for reading data.
      Specified by:
      read in interface FileBased
      Parameters:
      in - the reader
      Throws:
      ConfigurationException - if a non-I/O related problem occurs, e.g. the data read does not have the expected format
    • save

      public void save(Document document, Node parent)
      Writes the configuration as child to the given DOM node
      Parameters:
      document - The DOM document to add the configuration to
      parent - The DOM parent node
      Since:
      2.0
    • setHeader

      public void setHeader(String header)
      Sets the header comment of this configuration.
      Parameters:
      header - the header comment
    • write

      public void write(Writer out) throws ConfigurationException
      Description copied from interface: FileBased
      Writes the content of this object to the given writer. Client code should not call this method directly, but use a FileHandler for writing data.
      Specified by:
      write in interface FileBased
      Parameters:
      out - the writer
      Throws:
      ConfigurationException - if a non-I/O related problem occurs, e.g. the data read does not have the expected format