junit.extensions.xml
Class XMLWriter

java.lang.Object
  extended byjunit.extensions.xml.XMLWriter

public class XMLWriter
extends java.lang.Object

A sample DOM writer. This sample program illustrates how to traverse a DOM tree in order to print a document that is parsed.

Version:
$Id: XMLWriter.java,v 1.3 2004/12/20 20:33:19 kwilson227 Exp $
Author:
Andy Clark, IBM

Field Summary
protected static boolean DEFAULT_CANONICAL
          Default canonical output (false).
protected static boolean DEFAULT_NAMESPACES
          Default namespaces support (true).
protected static java.lang.String DEFAULT_PARSER_NAME
          Default parser name.
protected static boolean DEFAULT_SCHEMA_FULL_CHECKING
          Default Schema full checking support (false).
protected static boolean DEFAULT_SCHEMA_VALIDATION
          Default Schema validation support (false).
protected static boolean DEFAULT_VALIDATION
          Default validation support (false).
protected static java.lang.String LEXICAL_HANDLER_PROPERTY_ID
          Lexical handler property id (http://xml.org/sax/properties/lexical-handler).
private  boolean m_fCanonical
          Canonical output.
private  java.io.PrintWriter m_fOut
          Print writer.
protected static java.lang.String NAMESPACES_FEATURE_ID
          Namespaces feature id (http://xml.org/sax/features/namespaces).
protected static java.lang.String SCHEMA_FULL_CHECKING_FEATURE_ID
          Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking).
protected static java.lang.String SCHEMA_VALIDATION_FEATURE_ID
          Schema validation feature id (http://apache.org/xml/features/validation/schema).
protected static java.lang.String VALIDATION_FEATURE_ID
          Validation feature id (http://xml.org/sax/features/validation).
 
Constructor Summary
XMLWriter()
          Default constructor.
XMLWriter(boolean canonical)
          Write the XML file in cannonical form.
 
Method Summary
 boolean getCanonical()
          Get the canonical state of the writer.
protected  void normalizeAndPrint(char c)
          Normalizes and print the given character.
protected  void normalizeAndPrint(java.lang.String s)
          Write the string after normalization.
private  void processCData(org.w3c.dom.Node node)
          Process CDATA nodes.
private  void processComment(org.w3c.dom.Node node)
          Process Comment Nodes.
private  void processDocument(org.w3c.dom.Node node)
          Process Document Nodes.
private  void processDocumentType(org.w3c.dom.Node node)
          Process Document Type nodes.
private  void processElement(short type, org.w3c.dom.Node node)
          Process Element node.
private  void processEntityRef(org.w3c.dom.Node node)
          Process EntityRef nodes.
private  void processInstructions(org.w3c.dom.Node node)
          Process Instruction nodes.
private  void processOther(org.w3c.dom.Node node)
          Process nodes which are not handled any other way.
private  void processText(org.w3c.dom.Node node)
          Process Text nodes.
 void setCanonical(boolean canonical)
          set canonical form of writting.
 void setOutput(java.io.OutputStream stream, java.lang.String encoding)
          Sets the output stream for printing.
 void setOutput(java.io.Writer writer)
          Sets the output writer.
protected  org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
          Returns a sorted list of attributes.
 void write(org.w3c.dom.Node node)
          Writes the specified node, recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACES_FEATURE_ID

protected static final java.lang.String NAMESPACES_FEATURE_ID
Namespaces feature id (http://xml.org/sax/features/namespaces).

See Also:
Constant Field Values

VALIDATION_FEATURE_ID

protected static final java.lang.String VALIDATION_FEATURE_ID
Validation feature id (http://xml.org/sax/features/validation).

See Also:
Constant Field Values

SCHEMA_VALIDATION_FEATURE_ID

protected static final java.lang.String SCHEMA_VALIDATION_FEATURE_ID
Schema validation feature id (http://apache.org/xml/features/validation/schema).

See Also:
Constant Field Values

SCHEMA_FULL_CHECKING_FEATURE_ID

protected static final java.lang.String SCHEMA_FULL_CHECKING_FEATURE_ID
Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking).

See Also:
Constant Field Values

LEXICAL_HANDLER_PROPERTY_ID

protected static final java.lang.String LEXICAL_HANDLER_PROPERTY_ID
Lexical handler property id (http://xml.org/sax/properties/lexical-handler).

See Also:
Constant Field Values

DEFAULT_PARSER_NAME

protected static final java.lang.String DEFAULT_PARSER_NAME
Default parser name.

See Also:
Constant Field Values

DEFAULT_NAMESPACES

protected static final boolean DEFAULT_NAMESPACES
Default namespaces support (true).

See Also:
Constant Field Values

DEFAULT_VALIDATION

protected static final boolean DEFAULT_VALIDATION
Default validation support (false).

See Also:
Constant Field Values

DEFAULT_SCHEMA_VALIDATION

protected static final boolean DEFAULT_SCHEMA_VALIDATION
Default Schema validation support (false).

See Also:
Constant Field Values

DEFAULT_SCHEMA_FULL_CHECKING

protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING
Default Schema full checking support (false).

See Also:
Constant Field Values

DEFAULT_CANONICAL

protected static final boolean DEFAULT_CANONICAL
Default canonical output (false).

See Also:
Constant Field Values

m_fOut

private java.io.PrintWriter m_fOut
Print writer.


m_fCanonical

private boolean m_fCanonical
Canonical output.

Constructor Detail

XMLWriter

public XMLWriter()
Default constructor.


XMLWriter

public XMLWriter(boolean canonical)
Write the XML file in cannonical form.

Parameters:
canonical - true if the file is to be written in cannonical form
Method Detail

setCanonical

public void setCanonical(boolean canonical)
set canonical form of writting.

Parameters:
canonical - true if canonical.

getCanonical

public boolean getCanonical()
Get the canonical state of the writer.

Returns:
true if the canonical state is set.

setOutput

public void setOutput(java.io.Writer writer)
Sets the output writer.

Parameters:
writer - The writer to be used.

setOutput

public void setOutput(java.io.OutputStream stream,
                      java.lang.String encoding)
               throws java.io.UnsupportedEncodingException
Sets the output stream for printing.

Parameters:
stream - The output stream the XML will be written to.
encoding - The encoding to be used for the output stream.
Throws:
java.io.UnsupportedEncodingException - if the encoding passed is not supported.

write

public void write(org.w3c.dom.Node node)
Writes the specified node, recursively.

Parameters:
node - Node to be written.

normalizeAndPrint

protected void normalizeAndPrint(java.lang.String s)
Write the string after normalization.

Parameters:
s - String to be normalized and printed.

normalizeAndPrint

protected void normalizeAndPrint(char c)
Normalizes and print the given character. Normalizing converts the special HTML characters to there &..; mapping.

Parameters:
c - The character to be printed.

sortAttributes

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

Parameters:
attrs - The array of attributes to be sorted.
Returns:
Attr[] The attrs in sorted order.

processCData

private void processCData(org.w3c.dom.Node node)
Process CDATA nodes.

Parameters:
node - Node to be processed.

processComment

private void processComment(org.w3c.dom.Node node)
Process Comment Nodes.

Parameters:
node - Node to be processed.

processDocument

private void processDocument(org.w3c.dom.Node node)
Process Document Nodes.

Parameters:
node - Node to be processed.

processDocumentType

private void processDocumentType(org.w3c.dom.Node node)
Process Document Type nodes.

Parameters:
node - Node to be processed.

processElement

private void processElement(short type,
                            org.w3c.dom.Node node)
Process Element node.

Parameters:
type - Type of the node.
node - Node to be processed.

processEntityRef

private void processEntityRef(org.w3c.dom.Node node)
Process EntityRef nodes.

Parameters:
node - Node to be processed.

processInstructions

private void processInstructions(org.w3c.dom.Node node)
Process Instruction nodes.

Parameters:
node - Node to be processed

processOther

private void processOther(org.w3c.dom.Node node)
Process nodes which are not handled any other way.

Parameters:
node - Node to be processed.

processText

private void processText(org.w3c.dom.Node node)
Process Text nodes.

Parameters:
node - Node to be processed.


Licensed under: GNU Lesser General Public License, Ver 2.1, February 1999