XML Parser for Java 1.1.16

com.ibm.xml.parser.util
Class 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();

 

By default, this doesn't print non-specified attributes.

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

Field Summary
protected  java.lang.String doctype
           
protected  int level
           
 
Fields inherited from class com.ibm.xml.parser.ToXMLStringVisitor
encoding, isPrintNonSpecifiedAttributes, writer
 
Constructor Summary
HTMLPrintVisitor(java.io.Writer writer)
          Constructor for default encoding.
HTMLPrintVisitor(java.io.Writer writer, java.lang.String encoding)
          Constructor for customized encoding.
HTMLPrintVisitor(java.io.Writer writer, java.lang.String encoding, java.lang.String doctype)
          Constructor for customized encoding and doctype.
 
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 visitDTDPost(DTD dtd)
          Ignore DTD Nodes.
 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 visitEntityDeclPre(EntityDecl entity)
          Ignore Entity Nodes.
 void visitGeneralReferencePre(GeneralReference generalReference)
          Ignore GeneralReference 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
getPrintNonSpecifiedAttributes, setPrintNonSpecifiedAttributes, visitCommentPre, 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

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.lang.Exception
Writes the doctype from the constructor (if any).
Parameters:
document - Node print as HTML.
Throws:
java.lang.Exception - 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.lang.Exception
Flush the writer.
Parameters:
document - Node to print as HTML.
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, and directs it to the print writer.
Parameters:
element - Node to print as HTML.
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, and directs it to the print writer.
Parameters:
element - Node to print as HTML.
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

visitAttributePre

public void visitAttributePre(TXAttribute attribute)
                       throws java.lang.Exception
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.lang.Exception - 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.lang.Exception
Ignore TXPI Nodes.
Parameters:
pi - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.
Overrides:
visitPIPre in class ToXMLStringVisitor
See Also:
TXPI

visitTextPre

public void visitTextPre(TXText text)
                  throws java.lang.Exception
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.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
Ignore DTD Nodes.
Parameters:
dtd - CURRENTLY NOT IMPLEMENTED.
Throws:
ToNextSibligTraversalException - Always thrown.
Overrides:
visitDTDPre in class ToXMLStringVisitor
See Also:
DTD

visitDTDPost

public void visitDTDPost(DTD dtd)
                  throws java.lang.Exception
Ignore DTD Nodes.
Parameters:
dtd - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.
Overrides:
visitDTDPost in class ToXMLStringVisitor
See Also:
DTD

visitElementDeclPre

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

visitAttlistPre

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

visitAttDefPre

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

visitEntityDeclPre

public void visitEntityDeclPre(EntityDecl entity)
                        throws java.lang.Exception
Ignore Entity Nodes.
Parameters:
entity - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.
Overrides:
visitEntityDeclPre in class ToXMLStringVisitor
See Also:
EntityDecl

visitNotationPre

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

visitGeneralReferencePre

public void visitGeneralReferencePre(GeneralReference generalReference)
                              throws java.lang.Exception
Ignore GeneralReference Nodes. Print contents of GeneralReferences.
Parameters:
generalReference - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - Never thrown.
Overrides:
visitGeneralReferencePre in class ToXMLStringVisitor
See Also:
GeneralReference

XML Parser for Java 1.1.16