|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.rice.cs.cunit.util.XMLConfig
public class XMLConfig
XML configuration management.
This class uses DOM paths of a specific form to refer to nodes in the XML document. Consider this XML structure:
Nested Class Summary | |
---|---|
static class |
XMLConfig.XMLConfigException
Exception in XMLConfig methods. |
static class |
XMLConfig.XMLConfigTest
Unit tests. |
Field Summary | |
---|---|
private org.w3c.dom.Document |
_document
XML document. |
static java.lang.String |
NL
Newline string. |
Constructor Summary | |
---|---|
XMLConfig()
Creates an empty configuration. |
|
XMLConfig(java.io.File f)
Creates a configuration from a file. |
|
XMLConfig(java.io.InputStream is)
Creates a configuration from an input stream. |
|
XMLConfig(java.io.Reader r)
Creates a configuration from a reader. |
|
XMLConfig(java.lang.String filename)
Creates a configuration from a file name. |
Method Summary | |
---|---|
org.w3c.dom.Node |
createNode(java.lang.String path)
Create the node specified by the DOM path. |
org.w3c.dom.Node |
createNode(java.lang.String path,
org.w3c.dom.Node n)
Create the node specified by the DOM path. |
org.w3c.dom.Node |
createNode(java.lang.String path,
org.w3c.dom.Node n,
boolean overwrite)
Create the node specified by the DOM path. |
java.lang.String |
get(java.lang.String path)
Returns the value as specified by the DOM path. |
java.lang.String |
get(java.lang.String path,
java.lang.String defaultVal)
Returns the value as specified by the DOM path, or the default value if the value could not be found. |
java.util.List<java.lang.String> |
getMultiple(java.lang.String path)
Returns the value as specified by the DOM path. |
java.util.List<java.lang.String> |
getMultiple(java.lang.String path,
org.w3c.dom.Node root)
Returns the value as specified by the DOM path. |
private void |
getMultipleAddAttributesHelper(java.lang.String path,
org.w3c.dom.Node n,
java.util.List<org.w3c.dom.Node> accum)
|
private void |
getMultipleHelper(java.lang.String path,
org.w3c.dom.Node n,
java.util.List<org.w3c.dom.Node> accum,
boolean dotRead)
Returns the value as specified by the DOM path. |
static java.lang.String |
getNodePath(org.w3c.dom.Node n)
Return the path of a node as it is used in XMLConfig. |
java.util.List<org.w3c.dom.Node> |
getNodes(java.lang.String path)
Returns the nodes as specified by the DOM path. |
java.util.List<org.w3c.dom.Node> |
getNodes(java.lang.String path,
org.w3c.dom.Node root)
Returns the nodes as specified by the DOM path. |
private void |
init(org.xml.sax.InputSource is)
Initialize this XML configuration. |
void |
save(java.io.File f)
Saves configuration to a file. |
void |
save(java.io.OutputStream os)
Saves configuration to an output stream |
void |
save(java.lang.String filename)
Saves configuration to a file specified by a file name. |
org.w3c.dom.Node |
set(java.lang.String path,
java.lang.String value)
Set the value of the node or attribute specified by the DOM path. |
org.w3c.dom.Node |
set(java.lang.String path,
java.lang.String value,
boolean overwrite)
Set the value of the node or attribute specified by the DOM path. |
org.w3c.dom.Node |
set(java.lang.String path,
java.lang.String value,
org.w3c.dom.Node n,
boolean overwrite)
Set the value of the node or attribute specified by the DOM path. |
java.lang.String |
toString()
Returns a string representation of the object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String NL
private org.w3c.dom.Document _document
Constructor Detail |
---|
public XMLConfig()
public XMLConfig(java.io.InputStream is)
is
- input streampublic XMLConfig(java.io.Reader r)
r
- readerpublic XMLConfig(java.io.File f)
f
- filepublic XMLConfig(java.lang.String filename)
filename
- file nameMethod Detail |
---|
private void init(org.xml.sax.InputSource is)
is
- the XML input sourcepublic void save(java.io.OutputStream os)
os
- output streampublic void save(java.io.File f)
f
- filepublic void save(java.lang.String filename)
filename
- file namepublic java.lang.String get(java.lang.String path)
path
- DOM path
public java.util.List<java.lang.String> getMultiple(java.lang.String path)
path
- DOM path
public java.util.List<java.lang.String> getMultiple(java.lang.String path, org.w3c.dom.Node root)
path
- DOM pathroot
- node where the search should start
public java.util.List<org.w3c.dom.Node> getNodes(java.lang.String path)
path
- DOM path
public java.util.List<org.w3c.dom.Node> getNodes(java.lang.String path, org.w3c.dom.Node root)
path
- DOM pathroot
- node where the search should start
private void getMultipleHelper(java.lang.String path, org.w3c.dom.Node n, java.util.List<org.w3c.dom.Node> accum, boolean dotRead)
path
- DOM pathn
- node where the search beginsaccum
- accumulatordotRead
- whether a dot has been readprivate void getMultipleAddAttributesHelper(java.lang.String path, org.w3c.dom.Node n, java.util.List<org.w3c.dom.Node> accum)
public java.lang.String get(java.lang.String path, java.lang.String defaultVal)
path
- DOM pathdefaultVal
- default value in case value is not in DOM
public org.w3c.dom.Node set(java.lang.String path, java.lang.String value)
path
- DOM pathvalue
- node or attribute value
public org.w3c.dom.Node set(java.lang.String path, java.lang.String value, boolean overwrite)
path
- DOM pathvalue
- node or attribute valueoverwrite
- whether to overwrite (true) or add (false)
public org.w3c.dom.Node set(java.lang.String path, java.lang.String value, org.w3c.dom.Node n, boolean overwrite)
path
- DOM pathvalue
- node or attribute valuen
- node where the search should startoverwrite
- whether to overwrite (true) or add (false) -- only applies for last node!
public org.w3c.dom.Node createNode(java.lang.String path)
path
- DOM path
public org.w3c.dom.Node createNode(java.lang.String path, org.w3c.dom.Node n)
path
- DOM pathn
- node where the search should start, or null for the root
public org.w3c.dom.Node createNode(java.lang.String path, org.w3c.dom.Node n, boolean overwrite)
path
- DOM pathn
- node where the search should start, or null for the rootoverwrite
- whether to overwrite (true) or add (false) -- only applies for last node!
public java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String getNodePath(org.w3c.dom.Node n)
n
- node
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |