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 class
XmlTree.DefaultNodeName
The node is named by the specified attribute.static class
XmlTree.IllegalXmlException
Do some more reasonable error handling.static class
XmlTree.Node
This describes a node of the XML treestatic interface
XmlTree.NodeName
static class
XmlTree.XmlErrorInfo
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Enumeration
elements()
static void
elements(XmlTree.Node n, java.util.Vector v)
java.lang.Object
get(java.lang.Object k)
Given a node description, return the value, if any.static java.lang.String
getFile(java.io.InputStream in)
static java.lang.String
getFile(java.lang.String s)
java.lang.String
getPart(java.lang.String s)
Given a node descriptor, return the result.XmlTree.Node
getRoot()
java.util.Hashtable
getTags()
boolean
isEmpty()
The current object state is the "default"; "save" does not need to write out any state.java.util.Enumeration
keys()
void
keys(XmlTree.Node n, java.lang.String prefix, java.lang.String delim, java.util.Vector v)
void
load(java.io.InputStream in)
Recreate the object from the ascii representation stored as a Properties format file.static void
main(java.lang.String[] args)
java.util.Vector
match(java.lang.String pattern)
Find all nodes that match a glob pattern, starting at the root.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.java.lang.Object
put(java.lang.Object k, java.lang.Object v)
java.lang.Object
remove(java.lang.Object o)
void
replace(java.lang.String src)
Replace the XmlTree with new markup.void
save(java.io.OutputStream out, java.lang.String header)
Create an ascii representation of this object in a Java Properties format.XmlTree.Node
search(java.lang.String s)
Find a node in the tree by name, starting at the root.XmlTree.Node
search(XmlTree.Node node, java.util.StringTokenizer st)
Find a node in the tree by name, starting under any node.boolean
setAttribute(java.lang.String name, java.lang.String key, java.lang.String value)
boolean
setCdata(java.lang.String name, java.lang.String data)
void
setComparator(XmlTree.NodeName nodeName)
Set the class that determines a node's name.void
setDelim(java.lang.String delim)
set the node delimiter.boolean
setDflt(java.lang.String dflt)
void
setIdent(java.lang.String ident)
void
setPrefix(java.lang.String prefix)
set the name of this treevoid
setTag(java.lang.String tag)
Add an element to the tag process list.void
setTags(java.util.Hashtable tags)
Set the list of tags to processint
size()
java.lang.String
toString()
Print a treevoid
toString(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:
toString
in 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.IllegalXmlException
Replace 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:
elements
in classjava.util.Dictionary
-
elements
public static void elements(XmlTree.Node n, java.util.Vector v)
-
keys
public java.util.Enumeration keys()
- Specified by:
keys
in 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:
get
in 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:
put
in classjava.util.Dictionary
-
remove
public java.lang.Object remove(java.lang.Object o)
- Specified by:
remove
in classjava.util.Dictionary
-
size
public int size()
- Specified by:
size
in classjava.util.Dictionary
-
isEmpty
public boolean isEmpty()
Description copied from interface:PropertiesCacheManager.Saveable
The current object state is the "default"; "save" does not need to write out any state.- Specified by:
isEmpty
in interfacePropertiesCacheManager.Saveable
- Specified by:
isEmpty
in classjava.util.Dictionary
-
load
public void load(java.io.InputStream in) throws java.io.IOException
Description copied from interface:PropertiesCacheManager.Saveable
Recreate the object from the ascii representation stored as a Properties format file.- Specified by:
load
in interfacePropertiesCacheManager.Saveable
- Throws:
java.io.IOException
-
save
public void save(java.io.OutputStream out, java.lang.String header) throws java.io.IOException
Description copied from interface:PropertiesCacheManager.Saveable
Create an ascii representation of this object in a Java Properties format.- Specified by:
save
in 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
-
-