XML for Java Compatibility API 2.0.6

com.ibm.xml.parser
Class FormatPrintVisitor

java.lang.Object
  |
  +--com.ibm.xml.parser.NOOPVisitor
        |
        +--com.ibm.xml.parser.ToXMLStringVisitor
              |
              +--com.ibm.xml.parser.FormatPrintVisitor

public class FormatPrintVisitor
extends ToXMLStringVisitor
implements Visitor

FormatPrintVisitor implements the Visitor interface in the visitor design pattern for the purpose of supporting TXDocument#printWithFormat on the various DOM- and XML4J-defined Nodes.

Formatted printing is defined as:

The following sample code uses the FormatPrintVisitor on a hierarchy of nodes:


 Visitor visitor = new FormatPrintVisitor(printWriter, encoding, indent);
 new NonRecursivePreorderTreeTraversal(visitor).traverse(this);

 

Version:
Revision: 70 1.4 src/com/ibm/xml/parser/FormatPrintVisitor.java, parser, xml4j2, xml4j2_0_6
See Also:
TXDocument.printWithFormat(java.io.Writer), TXElement.isPreserveSpace(), TXText.getIsIgnorableWhitespace(), Visitor, TreeTraversal, NonRecursivePreorderTreeTraversal, ToXMLStringVisitor, HTMLPrintVisitor

Field Summary
protected  int currentIndent
           
protected  int indent
           
protected  boolean ispreserve
           
protected  boolean isprevtext
           
protected  java.util.Stack preserves
           
 
Fields inherited from class com.ibm.xml.parser.ToXMLStringVisitor
encoding, isPrintNonSpecifiedAttributes, writer
 
Constructor Summary
FormatPrintVisitor(java.io.Writer writer)
          Constructor for default encoding.
FormatPrintVisitor(java.io.Writer writer, java.lang.String encoding)
          Constructor for customized encoding.
FormatPrintVisitor(java.io.Writer writer, java.lang.String encoding, int indent)
          Constructor for customized encoding and indent.
 
Method Summary
 void visitAttlistPre(Attlist attlist)
          Creates a formatted string representation of the specified attlist Node and any associated AttDefs in XML format, and directs it to the print writer.
 void visitCommentPre(TXComment comment)
          Creates a formatted string representation of the specified comment Node in XML format, and directs it to the print writer.
 void visitDocumentPost(TXDocument document)
          Flush the writer.
 void visitDTDPost(DTD dtd)
          Creates a formatted string representation of the end of the specified dtd Node in XML format, and directs it to the print writer.
 void visitDTDPre(DTD dtd)
          Creates a formatted string representation of the start of the specified dtd Node in XML format, and directs it to the print writer.
 void visitElementDeclPre(ElementDecl elementDecl)
          Creates a formatted string representation of the specified elementDecl Node in XML format, and directs it to the print writer.
 void visitElementPost(TXElement element)
          Creates a formatted string representation of the end of the specified element Node in XML format, and directs it to the print writer.
 void visitElementPre(TXElement element)
          Creates a formatted string representation of the start of the specified element Node and its associated attributes in XML format, and directs it to the print writer.
 void visitEntityDeclPre(EntityDecl entityDecl)
          Creates a formatted string representation of the specified entityDecl Node in XML format, and directs it to the print writer.
 void visitNotationPre(TXNotation notation)
          Creates a formatted string representation of the specified notation Node in XML format, and directs it to the print writer.
 void visitPIPre(TXPI pi)
          Creates a formatted string representation of the specified pi Node in XML format, and directs it to the print writer.
 void visitTextPre(TXText text)
          Creates a formatted string representation of the specified text Node in XML format, and directs it to the print writer.
 
Methods inherited from class com.ibm.xml.parser.ToXMLStringVisitor
getPrintNonSpecifiedAttributes, setPrintNonSpecifiedAttributes, visitAttDefPre, visitAttributePre, visitDocumentPre, visitGeneralReferencePre, visitPseudoNodePre
 
Methods inherited from class com.ibm.xml.parser.NOOPVisitor
visitAttDefPost, visitAttlistPost, visitAttributePost, visitCommentPost, visitDocumentFragmentPost, visitDocumentFragmentPre, visitElementDeclPost, visitEntityDeclPost, visitGeneralReferencePost, visitNotationPost, visitPIPost, visitPseudoNodePost, visitTextPost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentIndent

protected int currentIndent

indent

protected int indent

ispreserve

protected boolean ispreserve

preserves

protected java.util.Stack preserves

isprevtext

protected boolean isprevtext
Constructor Detail

FormatPrintVisitor

public FormatPrintVisitor(java.io.Writer writer,
                          java.lang.String encoding,
                          int indent)
Constructor for customized encoding and indent.
Parameters:
writer - The character output stream to use.
encoding - Java character encoding in use by writer.
indent - Number of spaces to indent at each nesting level.

FormatPrintVisitor

public FormatPrintVisitor(java.io.Writer writer,
                          java.lang.String encoding)
Constructor for customized encoding.
Parameters:
writer - The character output stream to use.
encoding - Java character encoding in use by writer.

FormatPrintVisitor

public FormatPrintVisitor(java.io.Writer writer)
Constructor for default encoding.
Parameters:
writer - The character output stream to use.
Method Detail

visitDocumentPost

public void visitDocumentPost(TXDocument document)
                       throws java.lang.Exception
Flush the writer.
Specified by:
visitDocumentPost in interface Visitor
Parameters:
document - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDocumentPost in class ToXMLStringVisitor
See Also:
TXDocument

visitElementPre

public void visitElementPre(TXElement element)
                     throws java.lang.Exception
Creates a formatted string representation of the start of the specified element Node and its associated attributes in XML format, and directs it to the print writer.
Specified by:
visitElementPre in interface Visitor
Parameters:
element - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitElementPre in class ToXMLStringVisitor
See Also:
TXElement

visitElementPost

public void visitElementPost(TXElement element)
                      throws java.lang.Exception
Creates a formatted string representation of the end of the specified element Node in XML format, and directs it to the print writer.
Specified by:
visitElementPost in interface Visitor
Parameters:
element - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitElementPost in class ToXMLStringVisitor
See Also:
TXElement

visitPIPre

public void visitPIPre(TXPI pi)
                throws java.lang.Exception
Creates a formatted string representation of the specified pi Node in XML format, and directs it to the print writer.
Specified by:
visitPIPre in interface Visitor
Parameters:
pi - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitPIPre in class ToXMLStringVisitor
See Also:
TXPI

visitCommentPre

public void visitCommentPre(TXComment comment)
                     throws java.lang.Exception
Creates a formatted string representation of the specified comment Node in XML format, and directs it to the print writer.
Specified by:
visitCommentPre in interface Visitor
Parameters:
comment - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitCommentPre in class ToXMLStringVisitor
See Also:
TXComment

visitTextPre

public void visitTextPre(TXText text)
                  throws java.lang.Exception
Creates a formatted string representation of the specified text Node in XML format, and directs it to the print writer. CDATASections are respected.
Specified by:
visitTextPre in interface Visitor
Parameters:
text - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitTextPre in class ToXMLStringVisitor
See Also:
TXText

visitDTDPre

public void visitDTDPre(DTD dtd)
                 throws java.lang.Exception
Creates a formatted string representation of the start of the specified dtd Node in XML format, and directs it to the print writer. The internal DTD subset will be included based on the value of isPrintInternalDTD().
Specified by:
visitDTDPre in interface Visitor
Parameters:
dtd - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDTDPre in class ToXMLStringVisitor
See Also:
DTD.isPrintInternalDTD(), DTD

visitDTDPost

public void visitDTDPost(DTD dtd)
                  throws java.lang.Exception
Creates a formatted string representation of the end of the specified dtd Node in XML format, and directs it to the print writer.
Specified by:
visitDTDPost in interface Visitor
Parameters:
dtd - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDTDPost in class ToXMLStringVisitor
See Also:
DTD

visitElementDeclPre

public void visitElementDeclPre(ElementDecl elementDecl)
                         throws java.lang.Exception
Creates a formatted string representation of the specified elementDecl Node in XML format, and directs it to the print writer.
Specified by:
visitElementDeclPre in interface Visitor
Parameters:
elementDecl - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitElementDeclPre in class ToXMLStringVisitor
See Also:
ElementDecl

visitAttlistPre

public void visitAttlistPre(Attlist attlist)
                     throws java.lang.Exception
Creates a formatted string representation of the specified attlist Node and any associated AttDefs in XML format, and directs it to the print writer.
Specified by:
visitAttlistPre in interface Visitor
Parameters:
attlist - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitAttlistPre in class ToXMLStringVisitor
See Also:
Attlist

visitEntityDeclPre

public void visitEntityDeclPre(EntityDecl entityDecl)
                        throws java.lang.Exception
Creates a formatted string representation of the specified entityDecl Node in XML format, and directs it to the print writer.
Specified by:
visitEntityDeclPre in interface Visitor
Parameters:
entityDecl - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitEntityDeclPre in class ToXMLStringVisitor
See Also:
EntityDecl

visitNotationPre

public void visitNotationPre(TXNotation notation)
                      throws java.lang.Exception
Creates a formatted string representation of the specified notation Node in XML format, and directs it to the print writer.
Specified by:
visitNotationPre in interface Visitor
Parameters:
notation - Node to print with format.
Throws:
java.lang.Exception - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitNotationPre in class ToXMLStringVisitor
See Also:
TXNotation

XML for Java Compatibility API 2.0.6