Class XMLPropertiesConfiguration
java.lang.Object
org.apache.commons.configuration.event.EventSource
org.apache.commons.configuration.AbstractConfiguration
org.apache.commons.configuration.BaseConfiguration
org.apache.commons.configuration.AbstractFileConfiguration
org.apache.commons.configuration.PropertiesConfiguration
org.apache.commons.configuration.XMLPropertiesConfiguration
- All Implemented Interfaces:
Cloneable, Configuration, FileConfiguration, FileSystemBased
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.
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
- Version:
- $Id: XMLPropertiesConfiguration.java 1534399 2013-10-21 22:25:03Z henning $
- Author:
- Emmanuel Bourg, Alistair Young
-
Nested Class Summary
Nested classes/interfaces inherited from class PropertiesConfiguration
PropertiesConfiguration.DefaultIOFactory, PropertiesConfiguration.IOFactory, PropertiesConfiguration.PropertiesReader, PropertiesConfiguration.PropertiesWriter -
Field Summary
Fields inherited from class AbstractFileConfiguration
autoSave, basePath, EVENT_CONFIG_CHANGED, EVENT_RELOAD, fileName, reloadLock, strategyFields inherited from class AbstractConfiguration
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty XMLPropertyConfiguration object which can be used to synthesize a new Properties file by adding values and then saving().Creates and loads the xml properties from the specified file.XMLPropertiesConfiguration(String fileName) Creates and loads the xml properties from the specified file.Creates and loads the xml properties from the specified URL.XMLPropertiesConfiguration(Element element) Creates and loads the xml properties from the specified DOM node. -
Method Summary
Modifier and TypeMethodDescriptionvoidLoad the properties from the given reader.voidParses a DOM element containing the properties.voidSave the configuration to the specified stream.voidWrites the configuration as child to the given DOM nodeMethods inherited from class PropertiesConfiguration
clone, createLayout, getEncoding, getFooter, getHeader, getInclude, getIncludesAllowed, getIOFactory, getLayout, isIncludesAllowed, setBasePath, setFooter, setHeader, setInclude, setIncludesAllowed, setIOFactory, setLayout, unescapeJavaMethods inherited from class AbstractFileConfiguration
addProperty, clearProperty, closeSilent, configurationChanged, containsKey, enterNoReload, exitNoReload, fireEvent, getBasePath, getFile, getFileName, getFileSystem, getKeys, getPath, getProperty, getReloadingStrategy, getReloadLock, getURL, isAutoSave, isEmpty, load, load, load, load, load, load, possiblySave, refresh, reload, reload, resetFileSystem, save, save, save, save, save, save, setAutoSave, setEncoding, setFile, setFileName, setFileSystem, setPath, setProperty, setReloadingStrategy, setURLMethods inherited from class BaseConfiguration
addPropertyDirect, clear, clearPropertyDirectMethods inherited from class AbstractConfiguration
addErrorLogListener, append, copy, createInterpolator, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDefaultListDelimiter, getDelimiter, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getList, getList, getListDelimiter, getLogger, getLong, getLong, getLong, getProperties, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, getSubstitutor, interpolate, interpolate, interpolatedConfiguration, interpolateHelper, isDelimiterParsingDisabled, isScalarValue, isThrowExceptionOnMissing, resolveContainerStore, setDefaultListDelimiter, setDelimiter, setDelimiterParsingDisabled, setListDelimiter, setLogger, setThrowExceptionOnMissing, subsetMethods inherited from class EventSource
addConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, createErrorEvent, createEvent, fireError, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEventsMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Configuration
clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, subset
-
Constructor Details
-
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
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
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
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
-
XMLPropertiesConfiguration
Creates and loads the xml properties from the specified DOM node.- Parameters:
element- The DOM element- Throws:
ConfigurationException- Error while loading the properties file- Since:
- 2.0
-
-
Method Details
-
load
Description copied from class:PropertiesConfigurationLoad the properties from the given reader. Note that theclear()method is not called, so the properties contained in the loaded file will be added to the actual set of properties.- Specified by:
loadin interfaceFileConfiguration- Overrides:
loadin classPropertiesConfiguration- Parameters:
in- An InputStream.- Throws:
ConfigurationException- if an error occurs
-
load
Parses a DOM element containing the properties. The DOM element has to follow the XML properties format introduced in Java 5.0, see http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html- Parameters:
element- The DOM element- Throws:
ConfigurationException- Error while interpreting the DOM- Since:
- 2.0
-
save
Description copied from class:PropertiesConfigurationSave the configuration to the specified stream.- Specified by:
savein interfaceFileConfiguration- Overrides:
savein classPropertiesConfiguration- Parameters:
out- the output stream used to save the configuration- Throws:
ConfigurationException- if an error occurs
-
save
-