|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.ucsb.nceas.morpho.framework.ConfigXML
This class is designed to store configuration information in an XML file. The concept is similar to that of a Properties file except that using the XML format allows for a hierarchy of properties and repeated properties. All 'keys' are element names, while values are always stored as XML text nodes. The XML file is parsed and stored in memory as a DOM object. Note that nodes are specified by node tags rather than paths
Constructor Summary | |
ConfigXML(java.io.InputStream configStream)
String passed to the creator is the XML config file name |
|
ConfigXML(java.lang.String filename)
String passed to the creator is the XML config file name |
Method Summary | |
void |
addChild(java.lang.String parentName,
int i,
java.lang.String childName,
java.lang.String value)
Add a child node to the specified parent |
java.util.Vector |
get(java.lang.String key)
Gets the value(s) corresponding to a key string (i.e. |
java.lang.String |
get(java.lang.String key,
int i)
Gets the value(s) corresponding to a key string (i.e. |
static java.lang.String |
getConfigDirectory()
Determine the home directory in which configuration files should be located |
org.w3c.dom.Document |
getDocument()
Gets the document for this DOM |
java.util.Hashtable |
getHashtable(java.lang.String parentName,
java.lang.String keyName,
java.lang.String valueName)
Assume that there is some parent node which has a subset of child nodes that are repeated e.g. |
org.w3c.dom.NodeList |
getPathContent(java.lang.String path)
gets the content of a tag in a given xml file with the given path |
org.w3c.dom.Node |
getRoot()
Gets the root Node for this DOM |
java.util.Vector |
getValuesForPath(java.lang.String pathstring)
|
boolean |
insert(java.lang.String key,
java.lang.String value)
Inserts another node before the first element with the name contained in 'key', otherwise appends it to the end of the config file (last element in root node) |
void |
print(org.w3c.dom.Node node,
java.io.PrintWriter out)
This method can 'print' any DOM subtree. |
void |
removeChildren(java.lang.String parentName,
int i)
removes all children of the specified parent |
void |
removeNode(java.lang.String nodeName,
int i)
deletes indicated node |
void |
save()
Save the configuration file |
void |
saveDOM(org.w3c.dom.Node nd)
This method wraps the 'print' method to send DOM back to the XML document (file) that was used to create the DOM. |
boolean |
set(java.lang.String key,
int i,
java.lang.String value)
used to set a value corresponding to 'key'; value is changed in DOM structure in memory |
void |
sort(java.lang.String xsltStylesheet)
sorts records in the config.xml file based on the passed stylesheet |
protected org.w3c.dom.Attr[] |
sortAttributes(org.w3c.dom.NamedNodeMap attrs)
Returns a sorted list of attributes. |
java.lang.String |
toString()
returns the config file as a string |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ConfigXML(java.lang.String filename) throws java.io.FileNotFoundException
filename
- name of XML filepublic ConfigXML(java.io.InputStream configStream) throws java.io.FileNotFoundException
Method Detail |
public java.util.Vector get(java.lang.String key)
key
- 'key' is element name.
public org.w3c.dom.Document getDocument()
public org.w3c.dom.Node getRoot()
public java.lang.String get(java.lang.String key, int i)
key
- 'key' is element name.i
- zero based index of elements with the name stored in key
public boolean set(java.lang.String key, int i, java.lang.String value)
key
- 'key' is element name.i
- index in set of elements with 'key' namevalue
- new value to be inserted in ith key
public boolean insert(java.lang.String key, java.lang.String value)
key
- element name which will be duplicatedvalue
- value for new element
public void addChild(java.lang.String parentName, int i, java.lang.String childName, java.lang.String value)
parentName
- name of parent elementi
- index of parent elementchildName
- element name of new childvalue
- value of new childpublic void removeNode(java.lang.String nodeName, int i)
nodeName
- node tagi
- node indexpublic void removeChildren(java.lang.String parentName, int i)
parentName
- Name of parent nodei
- index of parent nodepublic java.util.Hashtable getHashtable(java.lang.String parentName, java.lang.String keyName, java.lang.String valueName)
public void save()
public void saveDOM(org.w3c.dom.Node nd)
nd
- node (usually the document root)public void print(org.w3c.dom.Node node, java.io.PrintWriter out)
node
- node usually set to the 'doc' node for complete XML file
re-writeprotected org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
public java.util.Vector getValuesForPath(java.lang.String pathstring)
public org.w3c.dom.NodeList getPathContent(java.lang.String path)
path
- the path to get the content frompublic static java.lang.String getConfigDirectory()
public void sort(java.lang.String xsltStylesheet) throws java.lang.Exception
xsltStylesheet
- the stylesheet to sort the config file
java.lang.Exception
public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |