Class com.ibm.xml.parser.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:
- Indenting all elements of an internal DTD subset definition
- Indenting nested TXElement nodes
- Allowing a single Node type per line of output (except for TXText nodes)
- Space is respected according to TXElement#isPreserveSpace and TXText#getIsIgnorableWhitespace
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: %M% %I% %W% %Q%
- See Also:
- printWithFormat, isPreserveSpace, getIsIgnorableWhitespace, Visitor, TreeTraversal, NonRecursivePreorderTreeTraversal, ToXMLStringVisitor, HTMLPrintVisitor
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
|
visitEntityPre(Entity entity)
Creates a formatted string representation of the specified entity 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
|
visitAttDefPre, visitAttlistPre, visitAttributePre, visitCommentPre, visitDocumentPost, visitDocumentPre, visitDTDPre, visitElementDeclPre, visitElementPost, visitElementPre, visitEntityPre, visitGeneralReferencePre, visitNotationPre, visitPIPre, visitPseudoNodePre, visitTextPre |
Methods inherited from class com.ibm.xml.parser.NOOPVisitor
|
visitAttDefPost, visitAttDefPre, visitAttlistPost, visitAttlistPre, visitAttributePost, visitAttributePre, visitCommentPost, visitCommentPre, visitDocumentPost, visitDocumentPre, visitDTDPost, visitDTDPre, visitElementDeclPost, visitElementDeclPre, visitElementPost, visitElementPre, visitEntityPost, visitEntityPre, visitGeneralReferencePost, visitGeneralReferencePre, visitNotationPost, visitNotationPre, visitPIPost, visitPIPre, visitPseudoNodePost, visitPseudoNodePre, visitTextPost, visitTextPre |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
currentIndent
protected int currentIndent
indent
protected int indent
ispreserve
protected boolean ispreserve
preserves
protected java.util.Stack preserves
isprevtext
protected boolean isprevtext
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.
visitDocumentPost
public void visitDocumentPost(TXDocument document) throws java.io.IOException
- Flush the writer.
- Implements:
- visitDocumentPost in interface Visitor
- Parameters:
document
- Node to print with format.
- Throws:
- java.io.IOException - 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.io.IOException
- 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.
- Implements:
- visitElementPre in interface Visitor
- Parameters:
element
- Node to print with format.
- Throws:
- java.io.IOException - 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.io.IOException
- Creates a formatted string representation of the end of the specified element Node
in XML format, and directs it to the print writer.
- Implements:
- visitElementPost in interface Visitor
- Parameters:
element
- Node to print with format.
- Throws:
- java.io.IOException - 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.io.IOException
- Creates a formatted string representation of the specified pi Node in XML
format, and directs it to the print writer.
- Implements:
- visitPIPre in interface Visitor
- Parameters:
pi
- Node to print with format.
- Throws:
- java.io.IOException - 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.io.IOException
- Creates a formatted string representation of the specified comment Node in
XML format, and directs it to the print writer.
- Implements:
- visitCommentPre in interface Visitor
- Parameters:
comment
- Node to print with format.
- Throws:
- java.io.IOException - 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.io.IOException
- Creates a formatted string representation of the specified text Node in XML
format, and directs it to the print writer. CDATASections are respected.
- Implements:
- visitTextPre in interface Visitor
- Parameters:
text
- Node to print with format.
- Throws:
- java.io.IOException - 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.io.IOException
- 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()
.
- Implements:
- visitDTDPre in interface Visitor
- Parameters:
dtd
- Node to print with format.
- Throws:
- java.io.IOException - Thrown if this Node can not be visitted because of an invalid character output stream.
- Overrides:
- visitDTDPre in class ToXMLStringVisitor
- See Also:
- isPrintInternalDTD, DTD
visitDTDPost
public void visitDTDPost(DTD dtd) throws java.io.IOException
- Creates a formatted string representation of the end of the specified dtd Node
in XML format, and directs it to the print writer.
- Implements:
- visitDTDPost in interface Visitor
- Parameters:
dtd
- Node to print with format.
- Throws:
- java.io.IOException - Thrown if this Node can not be visitted because of an invalid character output stream.
- Overrides:
- visitDTDPost in class NOOPVisitor
- See Also:
- DTD
visitElementDeclPre
public void visitElementDeclPre(ElementDecl elementDecl) throws java.io.IOException
- Creates a formatted string representation of the specified elementDecl Node
in XML format, and directs it to the print writer.
- Implements:
- visitElementDeclPre in interface Visitor
- Parameters:
elementDecl
- Node to print with format.
- Throws:
- java.io.IOException - 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.io.IOException
- Creates a formatted string representation of the specified attlist Node and any
associated AttDefs in XML format, and directs it to the print writer.
- Implements:
- visitAttlistPre in interface Visitor
- Parameters:
attlist
- Node to print with format.
- Throws:
- java.io.IOException - Thrown if this Node can not be visitted because of an invalid character output stream.
- Overrides:
- visitAttlistPre in class ToXMLStringVisitor
- See Also:
- Attlist
visitEntityPre
public void visitEntityPre(Entity entity) throws java.io.IOException
- Creates a formatted string representation of the specified entity Node in
XML format, and directs it to the print writer.
- Implements:
- visitEntityPre in interface Visitor
- Parameters:
entity
- Node to print with format.
- Throws:
- java.io.IOException - Thrown if this Node can not be visitted because of an invalid character output stream.
- Overrides:
- visitEntityPre in class ToXMLStringVisitor
- See Also:
- Entity
visitNotationPre
public void visitNotationPre(TXNotation notation) throws java.io.IOException
- Creates a formatted string representation of the specified notation Node in
XML format, and directs it to the print writer.
- Implements:
- visitNotationPre in interface Visitor
- Parameters:
notation
- Node to print with format.
- Throws:
- java.io.IOException - Thrown if this Node can not be visitted because of an invalid character output stream.
- Overrides:
- visitNotationPre in class ToXMLStringVisitor
- See Also:
- com.ibm.xml.parser.Notation