sunlabs.brazil.sunlabs
Class XmlTree

java.lang.Object
  extended by java.util.Dictionary
      extended by sunlabs.brazil.sunlabs.XmlTree (view source)
All Implemented Interfaces:
PropertiesCacheManager.Saveable

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 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 tree
static interface XmlTree.NodeName
           
static class XmlTree.XmlErrorInfo
           
 
Constructor Summary
XmlTree()
          Make an empty tree.
XmlTree(String src)
          Given an XML string, build the tree.
 
Method Summary
 Enumeration elements()
           
static void elements(XmlTree.Node n, Vector v)
           
 Object get(Object k)
          Given a node description, return the value, if any.
static String getFile(InputStream in)
           
static String getFile(String s)
           
 String getPart(String s)
          Given a node descriptor, return the result.
 XmlTree.Node getRoot()
           
 Hashtable getTags()
           
 void ignoreUnknownTags(boolean flag)
          set unknown tag disposition
 boolean isEmpty()
          The current object state is the "default"; "save" does not need to write out any state.
 Enumeration keys()
           
 void keys(XmlTree.Node n, String prefix, String delim, Vector v)
           
 void load(InputStream in)
          Recreate the object from the ascii representation stored as a Properties format file.
static void main(String[] args)
           
 Vector match(String pattern)
          Find all nodes that match a glob pattern, starting at the root.
 void match(XmlTree.Node node, StringTokenizer st, Vector results)
          Find all nodes that match a glob pattern, starting at any node.
 Object put(Object k, Object v)
           
 Object remove(Object o)
           
 void replace(String src)
          Replace the XmlTree with new markup.
 void save(OutputStream out, String header)
          Create an ascii representation of this object in a Java Properties format.
 XmlTree.Node search(String s)
          Find a node in the tree by name, starting at the root.
 XmlTree.Node search(XmlTree.Node node, StringTokenizer st)
          Find a node in the tree by name, starting under any node.
 boolean setAttribute(String name, String key, String value)
           
 boolean setCdata(String name, String data)
           
 void setComparator(XmlTree.NodeName nodeName)
          Set the class that determines a node's name.
 void setDelim(String delim)
          set the node delimiter.
 boolean setDflt(String dflt)
           
 void setIdent(String ident)
           
 void setPrefix(String prefix)
          set the name of this tree
 void setTag(String tag)
          Add an element to the tag process list.
 void setTags(Hashtable tags)
          Set the list of tags to process
 int size()
           
 String toString()
           
 void toString(XmlTree.Node node, StringBuffer sb, int level)
          Print a tree
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XmlTree

public XmlTree()
Make an empty tree.


XmlTree

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

Throws:
IllegalArgumentException
Method Detail

ignoreUnknownTags

public void ignoreUnknownTags(boolean flag)
set unknown tag disposition


setIdent

public void setIdent(String ident)

getRoot

public XmlTree.Node getRoot()

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


getTags

public Hashtable getTags()

setPrefix

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


setDelim

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


setDflt

public boolean setDflt(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 String toString()
Overrides:
toString in class Object

toString

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

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

replace

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

Parameters:
src - the xml data
Throws:
XmlTree.IllegalXmlException

setAttribute

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

setCdata

public boolean setCdata(String name,
                        String data)

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.


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.


elements

public Enumeration elements()
Specified by:
elements in class Dictionary

elements

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

keys

public Enumeration keys()
Specified by:
keys in class Dictionary

keys

public void keys(XmlTree.Node n,
                 String prefix,
                 String delim,
                 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.

Specified by:
get in class Dictionary

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


put

public Object put(Object k,
                  Object v)
Specified by:
put in class Dictionary

remove

public Object remove(Object o)
Specified by:
remove in class Dictionary

size

public int size()
Specified by:
size in class 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 interface PropertiesCacheManager.Saveable
Specified by:
isEmpty in class Dictionary

load

public void load(InputStream in)
          throws IOException
Description copied from interface: PropertiesCacheManager.Saveable
Recreate the object from the ascii representation stored as a Properties format file.

Specified by:
load in interface PropertiesCacheManager.Saveable
Throws:
IOException

save

public void save(OutputStream out,
                 String header)
          throws IOException
Description copied from interface: PropertiesCacheManager.Saveable
Create an ascii representation of this object in a Java Properties format.

Specified by:
save in interface PropertiesCacheManager.Saveable
Throws:
IOException

main

public static void main(String[] args)

getFile

public static String getFile(String s)
                      throws IOException
Throws:
IOException

getFile

public static String getFile(InputStream in)
                      throws IOException
Throws:
IOException

Version Kenai-svn-r24, Generated 08/18/09
Copyright (c) 2001-2009, Sun Microsystems.