Package sunlabs.brazil.sunlabs
Class XmlTree
- java.lang.Object
-
- java.util.Dictionary
-
- sunlabs.brazil.sunlabs.XmlTree
-
- All Implemented Interfaces:
PropertiesCacheManager.Saveable
public class XmlTree extends java.util.Dictionary implements PropertiesCacheManager.Saveable
Create a tree representation of an xml file whose parts may be referenced as a dictionary. This is currently "read only".
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXmlTree.DefaultNodeNameThe node is named by the specified attribute.static classXmlTree.IllegalXmlExceptionDo some more reasonable error handling.static classXmlTree.NodeThis describes a node of the XML treestatic interfaceXmlTree.NodeNamestatic classXmlTree.XmlErrorInfo
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Enumerationelements()static voidelements(XmlTree.Node n, java.util.Vector v)java.lang.Objectget(java.lang.Object k)Given a node description, return the value, if any.static java.lang.StringgetFile(java.io.InputStream in)static java.lang.StringgetFile(java.lang.String s)java.lang.StringgetPart(java.lang.String s)Given a node descriptor, return the result.XmlTree.NodegetRoot()java.util.HashtablegetTags()booleanisEmpty()The current object state is the "default"; "save" does not need to write out any state.java.util.Enumerationkeys()voidkeys(XmlTree.Node n, java.lang.String prefix, java.lang.String delim, java.util.Vector v)voidload(java.io.InputStream in)Recreate the object from the ascii representation stored as a Properties format file.static voidmain(java.lang.String[] args)java.util.Vectormatch(java.lang.String pattern)Find all nodes that match a glob pattern, starting at the root.voidmatch(XmlTree.Node node, java.util.StringTokenizer st, java.util.Vector results)Find all nodes that match a glob pattern, starting at any node.java.lang.Objectput(java.lang.Object k, java.lang.Object v)java.lang.Objectremove(java.lang.Object o)voidreplace(java.lang.String src)Replace the XmlTree with new markup.voidsave(java.io.OutputStream out, java.lang.String header)Create an ascii representation of this object in a Java Properties format.XmlTree.Nodesearch(java.lang.String s)Find a node in the tree by name, starting at the root.XmlTree.Nodesearch(XmlTree.Node node, java.util.StringTokenizer st)Find a node in the tree by name, starting under any node.booleansetAttribute(java.lang.String name, java.lang.String key, java.lang.String value)booleansetCdata(java.lang.String name, java.lang.String data)voidsetComparator(XmlTree.NodeName nodeName)Set the class that determines a node's name.voidsetDelim(java.lang.String delim)set the node delimiter.booleansetDflt(java.lang.String dflt)voidsetIdent(java.lang.String ident)voidsetPrefix(java.lang.String prefix)set the name of this treevoidsetTag(java.lang.String tag)Add an element to the tag process list.voidsetTags(java.util.Hashtable tags)Set the list of tags to processintsize()java.lang.StringtoString()Print a treevoidtoString(XmlTree.Node node, java.lang.StringBuffer sb, int level)
-
-
-
Method Detail
-
setIdent
public void setIdent(java.lang.String ident)
-
getRoot
public XmlTree.Node getRoot()
-
setTag
public void setTag(java.lang.String tag)
Add an element to the tag process list. Once a Process tag is defined, only tags defined are processed. All other tags are treated as singletons
-
setTags
public void setTags(java.util.Hashtable tags)
Set the list of tags to process
-
getTags
public java.util.Hashtable getTags()
-
setPrefix
public void setPrefix(java.lang.String prefix)
set the name of this tree
-
setDelim
public void setDelim(java.lang.String delim)
set the node delimiter.
-
setDflt
public boolean setDflt(java.lang.String dflt)
-
setComparator
public void setComparator(XmlTree.NodeName nodeName)
Set the class that determines a node's name. This may be used to change the way nodes are named in an arbitrary fashion.
-
toString
public java.lang.String toString()
Print a tree- Overrides:
toStringin classjava.lang.Object- Parameters:
node- : The starting nodesb- : where to append the results tolevel- : the nesting level
-
toString
public void toString(XmlTree.Node node, java.lang.StringBuffer sb, int level)
-
replace
public void replace(java.lang.String src) throws XmlTree.IllegalXmlExceptionReplace the XmlTree with new markup.- Parameters:
src- : the xml data- Throws:
XmlTree.IllegalXmlException
-
setAttribute
public boolean setAttribute(java.lang.String name, java.lang.String key, java.lang.String value)
-
setCdata
public boolean setCdata(java.lang.String name, java.lang.String data)
-
search
public XmlTree.Node search(java.lang.String s)
Find a node in the tree by name, starting at the root.- Parameters:
s- The node pathname- Returns:
- The node, if found, or null
-
search
public XmlTree.Node search(XmlTree.Node node, java.util.StringTokenizer st)
Find a node in the tree by name, starting under any node.
-
match
public java.util.Vector match(java.lang.String pattern)
Find all nodes that match a glob pattern, starting at the root.
-
match
public void match(XmlTree.Node node, java.util.StringTokenizer st, java.util.Vector results)
Find all nodes that match a glob pattern, starting at any node.
-
elements
public java.util.Enumeration elements()
- Specified by:
elementsin classjava.util.Dictionary
-
elements
public static void elements(XmlTree.Node n, java.util.Vector v)
-
keys
public java.util.Enumeration keys()
- Specified by:
keysin classjava.util.Dictionary
-
keys
public void keys(XmlTree.Node n, java.lang.String prefix, java.lang.String delim, java.util.Vector v)
-
get
public java.lang.Object get(java.lang.Object k)
Given a node description, return the value, if any. Descriptions are of the form: [prefix].name.[suffix] where : [prefix] is the name of the tree "." is the current delimiter, name is the path name of a node in the tree [suffix] specifies which part of the node to return as a string. See getpart() for the list of valid suffixes.- Specified by:
getin classjava.util.Dictionary
-
getPart
public java.lang.String getPart(java.lang.String s)
Given a node descriptor, return the result. XXX not done modifiers: cdata: return cdata tag: the name index: which tag within whis parent attributes: the list of attribute names children: the list of children childCount: the number of children.value the value for attribute glob nodes matching the glob pattern all all nodes under this one
-
put
public java.lang.Object put(java.lang.Object k, java.lang.Object v)- Specified by:
putin classjava.util.Dictionary
-
remove
public java.lang.Object remove(java.lang.Object o)
- Specified by:
removein classjava.util.Dictionary
-
size
public int size()
- Specified by:
sizein classjava.util.Dictionary
-
isEmpty
public boolean isEmpty()
Description copied from interface:PropertiesCacheManager.SaveableThe current object state is the "default"; "save" does not need to write out any state.- Specified by:
isEmptyin interfacePropertiesCacheManager.Saveable- Specified by:
isEmptyin classjava.util.Dictionary
-
load
public void load(java.io.InputStream in) throws java.io.IOExceptionDescription copied from interface:PropertiesCacheManager.SaveableRecreate the object from the ascii representation stored as a Properties format file.- Specified by:
loadin interfacePropertiesCacheManager.Saveable- Throws:
java.io.IOException
-
save
public void save(java.io.OutputStream out, java.lang.String header) throws java.io.IOExceptionDescription copied from interface:PropertiesCacheManager.SaveableCreate an ascii representation of this object in a Java Properties format.- Specified by:
savein interfacePropertiesCacheManager.Saveable- Throws:
java.io.IOException
-
main
public static void main(java.lang.String[] args)
-
getFile
public static java.lang.String getFile(java.lang.String s) throws java.io.IOException- Throws:
java.io.IOException
-
getFile
public static java.lang.String getFile(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
-