com.taursys.dom
Class XMLWriter

java.lang.Object
  extended bycom.taursys.dom.AbstractWriter
      extended bycom.taursys.dom.XMLWriter
Direct Known Subclasses:
HTMLWriter

public class XMLWriter
extends AbstractWriter

This class is used to write a given Document to an OutputStream or Writer.


Field Summary
protected  java.io.PrintWriter printWriter
           
 
Constructor Summary
XMLWriter()
          Default constructor.
 
Method Summary
protected  void normalizeAndPrint(char c)
          Normalizes and print the given character.
protected  void normalizeAndPrint(java.lang.String s)
          Normalizes and prints the given string.
protected  org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
          Returns a sorted list of attributes for the given map.
 void write(org.w3c.dom.Document doc, java.io.OutputStream stream)
          Writes the specified Document to the OutputStream.
 void write(org.w3c.dom.Document doc, java.io.Writer writer)
          Writes the specified Document to the Writer.
protected  void write(org.w3c.dom.Node node)
          Write the specified node, recursively.
protected  void writeAttributes(org.w3c.dom.Node node)
          Writes the attributes for the given node in alphabetic order.
protected  void writeElementNode(org.w3c.dom.Node node)
          Write the given element node recursively.
protected  void writeEmptyElementNode(org.w3c.dom.Node node)
          Writes the given empty element node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

printWriter

protected java.io.PrintWriter printWriter
Constructor Detail

XMLWriter

public XMLWriter()
Default constructor.

Method Detail

write

public void write(org.w3c.dom.Document doc,
                  java.io.OutputStream stream)
Writes the specified Document to the OutputStream.

Specified by:
write in class AbstractWriter
Parameters:
doc - the Document to write
stream - the OutputStream to write to

write

public void write(org.w3c.dom.Document doc,
                  java.io.Writer writer)
Writes the specified Document to the Writer.

Specified by:
write in class AbstractWriter
Parameters:
doc - the Document to write
writer - the Writer to write to

write

protected void write(org.w3c.dom.Node node)
Write the specified node, recursively. This implementation will write the following type Nodes:

Parameters:
node - the starting node to write and recurse.

writeElementNode

protected void writeElementNode(org.w3c.dom.Node node)
Write the given element node recursively. This method first checks to see if the given element node has any children. If it does NOT have any children, it invokes the writeEmptyElementNode method. Otherwise, it writes the element node itself. It begins by invoking the writeAttributes method to generate the attributes for the element node. It then invokes the write method for each child. Finally it writes the end tag for the node.

Parameters:
node - the element node to recursively write.

writeEmptyElementNode

protected void writeEmptyElementNode(org.w3c.dom.Node node)
Writes the given empty element node. This implementation simply writes the opening tag with attributes and then the closing tag. It does not use the empty tag shorthand method. It uses the writeAttributes method to generate the attributes for the node.

Parameters:
node - the element node to write

writeAttributes

protected void writeAttributes(org.w3c.dom.Node node)
Writes the attributes for the given node in alphabetic order. All attributes are written as attributeName="value". The value is normalized before it is written.

Parameters:
node - the node with the attributes to write.
See Also:
normalizeAndPrint(java.lang.String)

sortAttributes

protected org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
Returns a sorted list of attributes for the given map.

Parameters:
attrs - the attribute map to sort
Returns:
an Attr[] of sorted attributes

normalizeAndPrint

protected void normalizeAndPrint(java.lang.String s)
Normalizes and prints the given string. This method normalizes each character. It replaces any special characters with the &XX; notation.

Parameters:
s - the String to normalize and print

normalizeAndPrint

protected void normalizeAndPrint(char c)
Normalizes and print the given character. It replaces any special characters with the &XX; notation.

Parameters:
c - the char to normalize and print


Copyright © 2007 Martin T Phelan. All Rights Reserved.