Contents | Package | Class | Tree | Deprecated | Index | Help XML for Java 1.0.4
PREV | NEXT SHOW LISTS | HIDE LISTS

Class com.ibm.xml.parser.util.HTMLPrintVisitor

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

public class HTMLPrintVisitor
extends ToXMLStringVisitor
HTMLPrintVisitor implements the Visitor interface in the visitor design pattern for the purpose of printing in HTML-like format the various DOM- and XML4J-defined Nodes.

In HTML-like printing, only the following Nodes are printed:

TXDocument
Only the doctype provided on this constructor is written (i.e. no XML declaration, <!DOCTYPE>, or internal DTD).
TXElement
All element names are uppercased.
Empty elements are written as <BR> instead of <BR/>.
TXAttribute
All attribute names are lowercased.
TXText
CDATASections are respected.
TXComment
GeneralReference
PseudoNode

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


 PrintWriter printWriter = new PrintWriter();
 Visitor htmlPrintVisitor = new HTMLPrintVisitor(printWriter);
 TreeTraversal treeTraversal = new NonRecursivePreorderTreeTraversal(htmlPrintVisitor);
 treeTraversal.traverse(document);
 printWriter.close();

 

Version:
Revision: %M% %I% %W% %Q%
See Also:
Visitor, TreeTraversal, NonRecursivePreorderTreeTraversal, ToXMLStringVisitor, FormatPrintVisitor

Field Summary
java.lang.String  doctype
 
int  level
 
 
Fields inherited from class com.ibm.xml.parser.ToXMLStringVisitor
 encoding, writer
 

Constructor Summary
 HTMLPrintVisitor(java.io.Writer writer, java.lang.String encoding, java.lang.String doctype)
Constructor for customized encoding and doctype.
 HTMLPrintVisitor(java.io.Writer writer, java.lang.String encoding)
Constructor for customized encoding.
 HTMLPrintVisitor(java.io.Writer writer)
Constructor for default encoding.
 

Method Summary
void  visitAttDefPre(AttDef attDef)
Ignore AttDef Nodes.
void  visitAttlistPre(Attlist attlist)
Ignore Attlist Nodes.
void  visitAttributePre(TXAttribute attribute)
Creates a formatted string representation of the specified attribute Node and its associated attributes, and directs it to the print writer.
void  visitDocumentPost(TXDocument document)
Flush the writer.
void  visitDocumentPre(TXDocument document)
Writes the doctype from the constructor (if any).
void  visitDTDPre(DTD dtd)
Ignore DTD Nodes.
void  visitElementDeclPre(ElementDecl elementDecl)
Ignore ElementDecl Nodes.
void  visitElementPost(TXElement element)
Creates a formatted string representation of the end of the specified element Node, 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, and directs it to the print writer.
void  visitEntityPre(Entity entity)
Ignore Entity Nodes.
void  visitNotationPre(TXNotation notation)
Ignore TXNotation Nodes.
void  visitPIPre(TXPI pi)
Ignore TXPI Nodes.
void  visitTextPre(TXText text)
Creates a formatted string representation of the specified text Node, 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
 

Field Detail

level

protected int level

doctype

protected java.lang.String doctype
Constructor Detail

HTMLPrintVisitor

public HTMLPrintVisitor(java.io.Writer writer,
                        java.lang.String encoding,
                        java.lang.String doctype)
Constructor for customized encoding and doctype.
Parameters:
writer - The character output stream to use.
encoding - Java character encoding in use by writer.
doctype - String to be printed at the top of the document.

HTMLPrintVisitor

public HTMLPrintVisitor(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.

HTMLPrintVisitor

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

visitDocumentPre

public void visitDocumentPre(TXDocument document) throws java.io.IOException
Writes the doctype from the constructor (if any).
Parameters:
document - Node print as HTML.
Throws:
java.io.IOException - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitDocumentPre in class ToXMLStringVisitor
See Also:
TXDocument

visitDocumentPost

public void visitDocumentPost(TXDocument document) throws java.io.IOException
Flush the writer.
Parameters:
document - Node to print as HTML.
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, and directs it to the print writer.
Parameters:
element - Node to print as HTML.
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, and directs it to the print writer.
Parameters:
element - Node to print as HTML.
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

visitAttributePre

public void visitAttributePre(TXAttribute attribute) throws java.io.IOException
Creates a formatted string representation of the specified attribute Node and its associated attributes, and directs it to the print writer.

Note that TXAttribute Nodes are not parsed into the document object hierarchy by the XML4J parser; attributes exist as part of a TXElement Node.

Parameters:
element - Node to print as HTML.
Throws:
java.io.IOException - Thrown if this Node can not be visitted because of an invalid character output stream.
Overrides:
visitAttributePre in class ToXMLStringVisitor
See Also:
TXElement

visitPIPre

public void visitPIPre(TXPI pi) throws java.io.IOException
Ignore TXPI Nodes.
Parameters:
pi - CURRENTLY NOT IMPLEMENTED.
Throws:
java.io.IOException - CURRENTLY NEVER THROWN.
Overrides:
visitPIPre in class ToXMLStringVisitor
See Also:
TXPI

visitTextPre

public void visitTextPre(TXText text) throws java.io.IOException
Creates a formatted string representation of the specified text Node, and directs it to the print writer. CDATASections are respected.
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
Ignore DTD Nodes.
Parameters:
dtd - CURRENTLY NOT IMPLEMENTED.
Throws:
java.io.IOException - CURRENTLY NEVER THROWN.
Overrides:
visitDTDPre in class ToXMLStringVisitor
See Also:
DTD

visitElementDeclPre

public void visitElementDeclPre(ElementDecl elementDecl) throws java.io.IOException
Ignore ElementDecl Nodes.
Parameters:
elementDecl - CURRENTLY NOT IMPLEMENTED.
Throws:
java.io.IOException - CURRENTLY NEVER THROWN.
Overrides:
visitElementDeclPre in class ToXMLStringVisitor
See Also:
ElementDecl

visitAttlistPre

public void visitAttlistPre(Attlist attlist) throws java.io.IOException
Ignore Attlist Nodes.
Parameters:
attlist - CURRENTLY NOT IMPLEMENTED.
Throws:
java.io.IOException - CURRENTLY NEVER THROWN.
Overrides:
visitAttlistPre in class ToXMLStringVisitor
See Also:
Attlist

visitAttDefPre

public void visitAttDefPre(AttDef attDef) throws java.io.IOException
Ignore AttDef Nodes.
Parameters:
attDef - CURRENTLY NOT IMPLEMENTED.
Throws:
java.io.IOException - CURRENTLY NEVER THROWN.
Overrides:
visitAttDefPre in class ToXMLStringVisitor
See Also:
AttDef

visitEntityPre

public void visitEntityPre(Entity entity) throws java.io.IOException
Ignore Entity Nodes.
Parameters:
entity - CURRENTLY NOT IMPLEMENTED.
Throws:
java.io.IOException - CURRENTLY NEVER THROWN.
Overrides:
visitEntityPre in class ToXMLStringVisitor
See Also:
Entity

visitNotationPre

public void visitNotationPre(TXNotation notation) throws java.io.IOException
Ignore TXNotation Nodes.
Parameters:
notation - CURRENTLY NOT IMPLEMENTED.
Throws:
java.io.IOException - CURRENTLY NEVER THROWN.
Overrides:
visitNotationPre in class ToXMLStringVisitor
See Also:
TXNotation

Contents | Package | Class | Tree | Deprecated | Index | Help
PREV | NEXT SHOW LISTS | HIDE LISTS