xtom.parser
Class XMLTree

java.lang.Object
  extended byxtom.parser.XMLTree

public class XMLTree
extends java.lang.Object

Description: The XMLTree is the model representation of the XML document. It provides easy to use access to elements and their children, and attributes.

Version:
$Revision: 1.1 $
Author:
taras

Field Summary
private  boolean caseSensitive
          Sets the sensitivity of element names, default true
private  Element rootElement
          Root element of the XML document
private  java.util.Stack searchTerms
           
 
Constructor Summary
private XMLTree()
           
  XMLTree(Element root)
          Creates a new XMLTree
 
Method Summary
private  void generateXMLAttributes(java.lang.StringBuffer xml, Element el)
          Generates Attribute XML markup for this element.
private  void generateXMLChildren(java.lang.StringBuffer xml, Element el)
          Generates XML markup for this element.
 Element getRootElement()
           
 boolean isCaseSensitive()
           
private  void printAttributes(java.lang.StringBuffer xml, Element el)
          Prints attributes to the XMLBuffer for display.
private  void printChildren(java.lang.StringBuffer xml, Element el, int level)
          Prints children to the XML Buffer for display.
private  java.lang.String printTabs(int howMany)
          Helper method to print tabs.
 void printTree(java.io.OutputStream o)
          Prints an String representation of the tree to a specified outputstream.
 void setCaseSensitive(boolean caseSensitive)
          Sets the whole tree to be case sensitive or not.
 java.lang.String toString()
          The toString method returns toXML() generated xml
 java.lang.String toXML()
          Generates an XML document from an existing tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

searchTerms

private java.util.Stack searchTerms

rootElement

private Element rootElement
Root element of the XML document


caseSensitive

private boolean caseSensitive
Sets the sensitivity of element names, default true

Constructor Detail

XMLTree

private XMLTree()

XMLTree

public XMLTree(Element root)
Creates a new XMLTree

Parameters:
root - The root element.
Throws:
MissingRootElementException - if the root element is null.
Method Detail

getRootElement

public Element getRootElement()
Returns:
The rootElement of this tree.

printTree

public void printTree(java.io.OutputStream o)
Prints an String representation of the tree to a specified outputstream. It will be nicely formated, with tabbed elements.

Parameters:
o - OutputStream to use when printing.
Throws:
java.lang.IllegalArgumentException - if the outputstream is null.

printAttributes

private void printAttributes(java.lang.StringBuffer xml,
                             Element el)
Prints attributes to the XMLBuffer for display.

Parameters:
xml -
el - Does not do anything if xml or el is null.

printChildren

private void printChildren(java.lang.StringBuffer xml,
                           Element el,
                           int level)
Prints children to the XML Buffer for display. This is a recursive method.

Parameters:
xml -
el - Does not do anything if xml or el is null.

printTabs

private java.lang.String printTabs(int howMany)
Helper method to print tabs.

Parameters:
howMany -
Returns:

isCaseSensitive

public boolean isCaseSensitive()
Returns:
Returns the caseSensitive.

setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)
Sets the whole tree to be case sensitive or not. This applies to Element names only, not Attributes. The case sensitivity can only be set through this method, which ensures that the case sensitivity of all elements is managed through one point only.

Parameters:
caseSensitive - The caseSensitive to set.

toXML

public java.lang.String toXML()
Generates an XML document from an existing tree.

Returns:
String of xml.

generateXMLChildren

private void generateXMLChildren(java.lang.StringBuffer xml,
                                 Element el)
Generates XML markup for this element. Recursive method.

Parameters:
xml -
el -

generateXMLAttributes

private void generateXMLAttributes(java.lang.StringBuffer xml,
                                   Element el)
Generates Attribute XML markup for this element.

Parameters:
xml -
el -

toString

public java.lang.String toString()
The toString method returns toXML() generated xml