|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.configuration.event.EventSource
org.apache.commons.configuration.AbstractConfiguration
org.apache.commons.configuration.HierarchicalConfiguration
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration
org.apache.commons.configuration.HierarchicalINIConfiguration
public class HierarchicalINIConfiguration
A specialized hierarchical configuration implementation for parsing ini files.
An initialization or ini file is a configuration file typically found on Microsoft's Windows operating system and contains data for Windows based applications.
Although popularized by Windows, ini files can be used on any system or platform due to the fact that they are merely text files that can easily be parsed and modified by both humans and computers.
A typcial ini file could look something like:
[section1]
; this is a comment!
var1 = foo
var2 = bar
[section2]
var1 = doo
The format of ini files is fairly straight forward and is composed of three
components:
key = value
format.There are various implementations of the ini file format by various vendors which has caused a number of differences to appear. As far as possible this configuration tries to be lenient and support most of the differences.
Some of the differences supported are as follows:
var1 : foo
.Global parameters are also allowed; any parameters declared before a section is declared are added to a global section. It is important to note that this global section does not have a name.
In all instances, a parameter's key is prepended with its section name and a
'.' (period). Thus a parameter named "var1" in "section1" will have the key
section1.var1
in this configuration. (This is the default
behavior. Because this is a hierarchical configuration you can change this by
setting a different ExpressionEngine
.)
default = ok
[section1]
var1 = foo
var2 = doodle
[section2]
; a comment
var1 = baz
var2 = shoodle
bad =
= worse
[section3]
# another comment
var1 : foo
var2 : bar
var5 : test1
[section3]
var3 = foo
var4 = bar
var5 = test2
This ini file will be parsed without error. Note:
getProperty("default")
.getProperty("section1.var1")
.getProperty("section2. ")
, notice the
period '.' and the space following the section name.Internally, this configuration maps the content of the represented ini file to its node structure in the following way:
HierarchicalConfiguration
for querying or
manipulating the hierarchy of configuration nodes, for instance the
configurationAt()
method for obtaining the data of a specific
section.
The set of sections in this configuration can be retrieved using the
getSections()
method. For obtaining a
SubnodeConfiguration
with the content of a specific section the
getSection()
method can be used.
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.apache.commons.configuration.AbstractHierarchicalFileConfiguration |
---|
AbstractHierarchicalFileConfiguration.FileConfigurationDelegate |
Nested classes/interfaces inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
---|
HierarchicalConfiguration.BuilderVisitor, HierarchicalConfiguration.CloneVisitor, HierarchicalConfiguration.DefinedKeysVisitor, HierarchicalConfiguration.DefinedVisitor, HierarchicalConfiguration.Node, HierarchicalConfiguration.NodeVisitor |
Field Summary | |
---|---|
protected static java.lang.String |
COMMENT_CHARS
The characters that signal the start of a comment line. |
private static java.lang.String |
LINE_CONT
The line continuation character. |
private static java.lang.String |
LINE_SEPARATOR
Constant for the line separator. |
protected static java.lang.String |
SEPARATOR_CHARS
The characters used to separate keys from values. |
private static long |
serialVersionUID
The serial version UID. |
Fields inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
---|
EVENT_ADD_NODES, EVENT_CLEAR_TREE, EVENT_SUBNODE_CHANGED |
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
---|
END_TOKEN, EVENT_ADD_PROPERTY, EVENT_CLEAR, EVENT_CLEAR_PROPERTY, EVENT_READ_PROPERTY, EVENT_SET_PROPERTY, START_TOKEN |
Constructor Summary | |
---|---|
HierarchicalINIConfiguration()
Create a new empty INI Configuration. |
|
HierarchicalINIConfiguration(java.io.File file)
Create and load the ini configuration from the given file. |
|
HierarchicalINIConfiguration(java.lang.String filename)
Create and load the ini configuration from the given file. |
|
HierarchicalINIConfiguration(java.net.URL url)
Create and load the ini configuration from the given url. |
Method Summary | |
---|---|
private java.lang.String |
formatValue(java.lang.String value)
Add quotes around the specified value if it contains a comment character. |
private SubnodeConfiguration |
getGlobalSection()
Creates a sub configuration for the global section of the represented INI configuration. |
SubnodeConfiguration |
getSection(java.lang.String name)
Returns a configuration with the content of the specified section. |
private ConfigurationNode |
getSectionNode(java.lang.String sectionName)
Obtains the node representing the specified section. |
java.util.Set |
getSections()
Return a set containing the sections in this ini configuration. |
private static boolean |
isCommentChar(char c)
Tests whether the specified character is a comment character. |
protected boolean |
isCommentLine(java.lang.String line)
Determine if the given line is a comment line. |
protected boolean |
isSectionLine(java.lang.String line)
Determine if the given line is a section. |
private static boolean |
isSectionNode(ConfigurationNode node)
Checks whether the specified configuration node represents a section. |
private static boolean |
lineContinues(java.lang.String line)
Tests whether the specified string contains a line continuation marker. |
private static boolean |
lineContinues(java.lang.String line,
int pos)
Tests whether the specified string contains a line continuation marker after the specified position. |
void |
load(java.io.Reader reader)
Load the configuration from the given reader. |
private static void |
markSectionNode(ConfigurationNode node)
Marks a configuration node as a section node. |
private static java.lang.String |
parseValue(java.lang.String val,
java.io.BufferedReader reader)
Parse the value to remove the quotes and ignoring the comment. |
void |
save(java.io.Writer writer)
Save the configuration to the specified writer. |
Methods inherited from class org.apache.commons.configuration.AbstractHierarchicalFileConfiguration |
---|
addNodes, addPropertyDirect, clearProperty, clearTree, configurationChanged, containsKey, createDelegate, fetchNodeList, getBasePath, getDelegate, getEncoding, getFile, getFileName, getKeys, getKeys, getProperty, getReloadingStrategy, getURL, isAutoSave, isEmpty, load, load, load, load, load, load, reload, save, save, save, save, save, save, setAutoSave, setBasePath, setDelegate, setEncoding, setFile, setFileName, setProperty, setReloadingStrategy, setURL, subnodeConfigurationChanged |
Methods inherited from class org.apache.commons.configuration.HierarchicalConfiguration |
---|
clearNode, clearNode, clearReferences, clone, configurationAt, configurationAt, configurationsAt, createAddPath, createNode, createSubnodeConfiguration, createSubnodeConfiguration, fetchAddNode, findLastPathNode, findPropertyNodes, getDefaultExpressionEngine, getExpressionEngine, getMaxIndex, getRoot, getRootNode, interpolatedConfiguration, nodeDefined, nodeDefined, registerSubnodeConfiguration, removeNode, removeNode, setDefaultExpressionEngine, setExpressionEngine, setRoot, setRootNode, subset |
Methods inherited from class org.apache.commons.configuration.event.EventSource |
---|
addConfigurationListener, addErrorListener, clearConfigurationListeners, clearErrorListeners, createErrorEvent, createEvent, fireError, fireEvent, getConfigurationListeners, getErrorListeners, isDetailEvents, removeConfigurationListener, removeErrorListener, setDetailEvents |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.commons.configuration.Configuration |
---|
addProperty, clear, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getList, getList, getLong, getLong, getLong, getProperties, getShort, getShort, getShort, getString, getString, getStringArray, subset |
Field Detail |
---|
protected static final java.lang.String COMMENT_CHARS
protected static final java.lang.String SEPARATOR_CHARS
private static final long serialVersionUID
private static final java.lang.String LINE_SEPARATOR
private static final java.lang.String LINE_CONT
Constructor Detail |
---|
public HierarchicalINIConfiguration()
public HierarchicalINIConfiguration(java.lang.String filename) throws ConfigurationException
filename
- The name pr path of the ini file to load.
ConfigurationException
- If an error occurs while loading the filepublic HierarchicalINIConfiguration(java.io.File file) throws ConfigurationException
file
- The ini file to load.
ConfigurationException
- If an error occurs while loading the filepublic HierarchicalINIConfiguration(java.net.URL url) throws ConfigurationException
url
- The url of the ini file to load.
ConfigurationException
- If an error occurs while loading the fileMethod Detail |
---|
public void save(java.io.Writer writer) throws ConfigurationException
writer
- - The writer to save the configuration to.
ConfigurationException
- If an error occurs while writing the
configurationpublic void load(java.io.Reader reader) throws ConfigurationException
clear
method is not called so the configuration read in will
be merged with the current configuration.
reader
- The reader to read the configuration from.
ConfigurationException
- If an error occurs while reading the
configurationprivate static java.lang.String parseValue(java.lang.String val, java.io.BufferedReader reader) throws java.io.IOException
"value" ; comment -> value
'value' ; comment -> value
val
- the value to be parsedreader
- the reader (needed if multiple lines have to be read)
java.io.IOException
- if an IO error occursprivate static boolean lineContinues(java.lang.String line)
line
- the string to check
private static boolean lineContinues(java.lang.String line, int pos)
line
- the line to checkpos
- the start position
private static boolean isCommentChar(char c)
c
- the character
private java.lang.String formatValue(java.lang.String value)
protected boolean isCommentLine(java.lang.String line)
line
- The line to check.
protected boolean isSectionLine(java.lang.String line)
line
- The line to check.
public java.util.Set getSections()
public SubnodeConfiguration getSection(java.lang.String name)
HierarchicalConfiguration.configurationAt(String)
with the name of the section in question. There are the following
differences however:
name
- the name of the section in question; null represents
the global section
private ConfigurationNode getSectionNode(java.lang.String sectionName)
sectionName
- the name of the section
private SubnodeConfiguration getGlobalSection()
private static void markSectionNode(ConfigurationNode node)
node
- the node to be markedprivate static boolean isSectionNode(ConfigurationNode node)
node
- the node in question
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |