com.ibm.dom.util
Class ToXMLVisitor

java.lang.Object
  |
  +--com.ibm.dom.util.NOOPVisitor
        |
        +--com.ibm.dom.util.ToXMLVisitor

public class ToXMLVisitor
extends NOOPVisitor

See Also:
TreeTraversal, com.ibm.xml.parser.ToXMLStringVisitor

Field Summary
protected  java.lang.String encoding
           
protected  boolean isPrintNonSpecifiedAttributes
           
protected  java.io.Writer writer
           
 
Constructor Summary
ToXMLVisitor(java.io.Writer writer)
          Constructor for default encoding.
ToXMLVisitor(java.io.Writer writer, java.lang.String encoding)
          Constructor for customized encoding.
 
Method Summary
 void escapedWrite(java.io.Writer writer, java.lang.String string, java.lang.String encoding)
          Writes the specified string to specified Writer after substituting &, <, >, , and UTF-16 surrogates for the set of entitiy references (&amp;, &lt;, &gt;) and numeric character references (&#...) respectively.
 void escapedWrite(java.io.Writer writer, java.lang.String string, java.lang.String specials, java.lang.String encoding)
          Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn.
 boolean getPrintNonSpecifiedAttributes()
          Returns whether this prints non-specified default attributes appended by DTD.
 void setPrintNonSpecifiedAttributes(boolean print)
          Sets whether this prints non-specified default attributes appended by DTD.
 void visitAttributePre(Attr attribute)
          Creates a string representation of the specified attribute Node in XML format.
 void visitCDATASectionPre(CDATASection cdata)
          Creates a string representation of the specified cdata Node in XML format.
 void visitCommentPre(Comment comment)
          Creates a string representation of the specified comment Node in XML format.
 void visitDocumentPost(Document document)
          Flush the writer.
 void visitDocumentPre(Document document)
          Creates a string representation of the specified document Node in XML format.
 void visitDocumentTypePre(DocumentType doctype)
          Creates a string representation of the specified doctype Node in XML format.
 void visitElementPost(Element element)
          Creates a string representation of the end of the specified element Node in XML format.
 void visitElementPre(Element element)
          Creates a string representation of the start of the specified element Node and its associated attributes in XML format.
 void visitEntityReference(EntityReference ref)
          Creates a string representation of the specified ref Node in XML format.
 void visitProcessingInstructionPre(ProcessingInstruction pi)
          Creates a string representation of the specified pi Node in XML format.
 void visitTextPre(Text text)
          Creates a string representation of the specified text Node in XML format.
 
Methods inherited from class com.ibm.dom.util.NOOPVisitor
traverse, visitAttributePost, visitCDATASectionPost, visitCommentPost, visitDocumentFragmentPost, visitDocumentFragmentPre, visitDocumentTypePost, visitEntityPost, visitEntityPre, visitEntityReferencePost, visitEntityReferencePre, visitNotationPost, visitNotationPre, visitProcessingInstructionPost, visitTextPost, visitUnknownPost, visitUnknownPre
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

protected java.io.Writer writer

encoding

protected java.lang.String encoding

isPrintNonSpecifiedAttributes

protected boolean isPrintNonSpecifiedAttributes
Constructor Detail

ToXMLVisitor

public ToXMLVisitor(java.io.Writer writer,
                    java.lang.String encoding)
Constructor for customized encoding.
Parameters:
writer - The character output stream to use. This MUST be UTF-8 or UTF-16 Writer.
encoding - Java character encoding in use by writer.

ToXMLVisitor

public ToXMLVisitor(java.io.Writer writer)
Constructor for default encoding.
Parameters:
writer - The character output stream to use. This MUST be UTF-8 or UTF-16 Writer.
Method Detail

setPrintNonSpecifiedAttributes

public void setPrintNonSpecifiedAttributes(boolean print)
Sets whether this prints non-specified default attributes appended by DTD.

By default, non-specified attributes are printed.

See Also:
Attr.getSpecified()

getPrintNonSpecifiedAttributes

public boolean getPrintNonSpecifiedAttributes()
Returns whether this prints non-specified default attributes appended by DTD.

visitDocumentPre

public void visitDocumentPre(Document document)
                      throws java.lang.Exception
Creates a string representation of the specified document Node in XML format.
Parameters:
document - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDocumentPre in class NOOPVisitor

visitDocumentPost

public void visitDocumentPost(Document document)
                       throws java.lang.Exception
Flush the writer.
Parameters:
document - Not used.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDocumentPost in class NOOPVisitor

visitElementPre

public void visitElementPre(Element element)
                     throws java.lang.Exception
Creates a string representation of the start of the specified element Node and its associated attributes in XML format.
Parameters:
element - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitElementPre in class NOOPVisitor

visitElementPost

public void visitElementPost(Element element)
                      throws java.lang.Exception
Creates a string representation of the end of the specified element Node in XML format.
Parameters:
element - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitElementPost in class NOOPVisitor

visitAttributePre

public void visitAttributePre(Attr attribute)
                       throws java.lang.Exception
Creates a string representation of the specified attribute Node in XML format.
Parameters:
attribute - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitAttributePre in class NOOPVisitor

visitProcessingInstructionPre

public void visitProcessingInstructionPre(ProcessingInstruction pi)
                                   throws java.lang.Exception
Creates a string representation of the specified pi Node in XML format.
Parameters:
pi - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitProcessingInstructionPre in class NOOPVisitor

visitCommentPre

public void visitCommentPre(Comment comment)
                     throws java.lang.Exception
Creates a string representation of the specified comment Node in XML format.
Parameters:
comment - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitCommentPre in class NOOPVisitor

visitTextPre

public void visitTextPre(Text text)
                  throws java.lang.Exception
Creates a string representation of the specified text Node in XML format.
Parameters:
text - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitTextPre in class NOOPVisitor

visitCDATASectionPre

public void visitCDATASectionPre(CDATASection cdata)
                          throws java.lang.Exception
Creates a string representation of the specified cdata Node in XML format.
Parameters:
cdata - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitCDATASectionPre in class NOOPVisitor

visitDocumentTypePre

public void visitDocumentTypePre(DocumentType doctype)
                          throws java.lang.Exception
Creates a string representation of the specified doctype Node in XML format.
Parameters:
doctype - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDocumentTypePre in class NOOPVisitor

visitEntityReference

public void visitEntityReference(EntityReference ref)
                          throws java.lang.Exception
Creates a string representation of the specified ref Node in XML format.
Parameters:
ref - Node toString in XML format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.

escapedWrite

public void escapedWrite(java.io.Writer writer,
                         java.lang.String string,
                         java.lang.String encoding)
                  throws java.io.IOException
Writes the specified string to specified Writer after substituting &, <, >, , and UTF-16 surrogates for the set of entitiy references (&amp;, &lt;, &gt;) and numeric character references (&#...) respectively.
Parameters:
writer - Writer for output. Buffered writer is recommended.
string - String to convert to XML format.
encoding - CURRENTLY NOT IMPLEMENTED.

escapedWrite

public void escapedWrite(java.io.Writer writer,
                         java.lang.String string,
                         java.lang.String specials,
                         java.lang.String encoding)
                  throws java.io.IOException
Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn.
Parameters:
writer - Writer for output. Buffered writer is recommended.
string - String to convert to XML format.
specials - Chracters, should be represeted in chracter referenfces.
encoding - CURRENTLY NOT IMPLEMENTED.