sunlabs.brazil.sunlabs

Class XmlTree

public class XmlTree extends 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
static classXmlTree.DefaultNodeName
The node is named by the specified attribute.
static classXmlTree.IllegalXmlException
Do some more reasonable error handling.
static classXmlTree.Node
This describes a node of the XML tree
interfaceXmlTree.NodeName
static classXmlTree.XmlErrorInfo
Constructor Summary
XmlTree()
Make an empty tree.
XmlTree(String src)
Given an XML string, build the tree.
Method Summary
Enumerationelements()
static voidelements(XmlTree.Node n, Vector v)
Objectget(Object k)
Given a node description, return the value, if any.
static StringgetFile(String s)
static StringgetFile(InputStream in)
StringgetPart(String s)
Given a node descriptor, return the result.
XmlTree.NodegetRoot()
HashtablegetTags()
booleanisEmpty()
Enumerationkeys()
voidkeys(XmlTree.Node n, String prefix, String delim, Vector v)
voidload(InputStream in)
static voidmain(String[] args)
Vectormatch(String pattern)
Find all nodes that match a glob pattern, starting at the root.
voidmatch(XmlTree.Node node, StringTokenizer st, Vector results)
Find all nodes that match a glob pattern, starting at any node.
Objectput(Object k, Object v)
Objectremove(Object o)
voidreplace(String src)
Replace the XmlTree with new markup.
voidsave(OutputStream out, String header)
XmlTree.Nodesearch(String s)
Find a node in the tree by name, starting at the root.
XmlTree.Nodesearch(XmlTree.Node node, StringTokenizer st)
Find a node in the tree by name, starting under any node.
booleansetAttribute(String name, String key, String value)
booleansetCdata(String name, String data)
voidsetComparator(XmlTree.NodeName nodeName)
Set the class that determines a node's name.
voidsetDelim(String delim)
set the node delimiter.
booleansetDflt(String dflt)
voidsetIdent(String ident)
voidsetPrefix(String prefix)
set the name of this tree
voidsetTag(String tag)
Add an element to the tag process list.
voidsetTags(Hashtable tags)
Set the list of tags to process
intsize()
StringtoString()
Print a tree
voidtoString(XmlTree.Node node, StringBuffer sb, int level)

Constructor Detail

XmlTree

public XmlTree()
Make an empty tree.

XmlTree

public XmlTree(String src)
Given an XML string, build the tree.

Method Detail

elements

public Enumeration elements()

elements

public static void elements(XmlTree.Node n, Vector v)

get

public Object get(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.

getFile

public static String getFile(String s)

getFile

public static String getFile(InputStream in)

getPart

public String getPart(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

getRoot

public XmlTree.Node getRoot()

getTags

public Hashtable getTags()

isEmpty

public boolean isEmpty()

keys

public Enumeration keys()

keys

public void keys(XmlTree.Node n, String prefix, String delim, Vector v)

load

public void load(InputStream in)

main

public static void main(String[] args)

match

public Vector match(String pattern)
Find all nodes that match a glob pattern, starting at the root.

match

public void match(XmlTree.Node node, StringTokenizer st, Vector results)
Find all nodes that match a glob pattern, starting at any node.

put

public Object put(Object k, Object v)

remove

public Object remove(Object o)

replace

public void replace(String src)
Replace the XmlTree with new markup.

Parameters: src: the xml data

save

public void save(OutputStream out, String header)

search

public XmlTree.Node search(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, StringTokenizer st)
Find a node in the tree by name, starting under any node.

setAttribute

public boolean setAttribute(String name, String key, String value)

setCdata

public boolean setCdata(String name, String data)

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.

setDelim

public void setDelim(String delim)
set the node delimiter.

setDflt

public boolean setDflt(String dflt)

setIdent

public void setIdent(String ident)

setPrefix

public void setPrefix(String prefix)
set the name of this tree

setTag

public void setTag(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(Hashtable tags)
Set the list of tags to process

size

public int size()

toString

public String toString()
Print a tree

Parameters: node: The starting node sb: where to append the results to level: the nesting level

toString

public void toString(XmlTree.Node node, StringBuffer sb, int level)