com.lotus.xsl.xml4j
Class HTMLFormatPrintVisitor

com.lotus.xsl.xml4j.HTMLFormatPrintVisitor

public class HTMLFormatPrintVisitor

HTMLFormatPrintVisitor 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

Formatted printing is defined as:

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


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

 

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


Field Summary
 int indent
           
 java.lang.String m_attrSpecialChars
          These are characters that will be escaped in the output.
 
Constructor Summary
HTMLFormatPrintVisitor(java.io.Writer writer)
          Constructor for default encoding.
HTMLFormatPrintVisitor(java.io.Writer writer, java.lang.String encoding)
          Constructor for customized encoding.
HTMLFormatPrintVisitor(java.io.Writer writer, java.lang.String encoding, java.lang.String doctype)
          Constructor for customized encoding and doctype.
HTMLFormatPrintVisitor(java.io.Writer writer, java.lang.String encoding, java.lang.String doctype, int indent)
          Constructor for customized encoding and doctype.
 
Method Summary
 void visitAttDefPre(com.lotus.xsl.xml4j.AttDef attDef)
          Ignore AttDef Nodes.
 void visitAttlistPre(com.lotus.xsl.xml4j.Attlist attlist)
          Ignore Attlist Nodes.
 void visitAttributePre(com.lotus.xsl.xml4j.TXAttribute attribute)
          Creates a formatted string representation of the specified attribute Node and its associated attributes, and directs it to the print writer.
 void visitCommentPre(com.lotus.xsl.xml4j.TXComment comment)
          Creates a formatted string representation of the specified comment Node in XML format, and directs it to the print writer.
 void visitDocumentPost(com.lotus.xsl.xml4j.TXDocument document)
          Flush the writer.
 void visitDocumentPre(com.lotus.xsl.xml4j.TXDocument document)
          Writes the doctype from the constructor (if any).
 void visitDTDPost(com.lotus.xsl.xml4j.DTD dtd)
          Ignore DTD Nodes.
 void visitDTDPre(com.lotus.xsl.xml4j.DTD dtd)
          Ignore DTD Nodes.
 void visitElementDeclPre(com.lotus.xsl.xml4j.ElementDecl elementDecl)
          Ignore ElementDecl Nodes.
 void visitElementPost(com.lotus.xsl.xml4j.TXElement element)
          Creates a formatted string representation of the end of the specified element Node, and directs it to the print writer.
 void visitElementPre(com.lotus.xsl.xml4j.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(com.lotus.xsl.xml4j.EntityDecl entity)
          Ignore Entity Nodes.
 void visitGeneralReferencePre(com.lotus.xsl.xml4j.GeneralReference generalReference)
          Ignore GeneralReference Nodes.
 void visitNotationPre(com.lotus.xsl.xml4j.TXNotation notation)
          Ignore TXNotation Nodes.
 void visitPIPre(com.lotus.xsl.xml4j.TXPI pi)
          Ignore TXPI Nodes.
 void visitTextPre(com.lotus.xsl.xml4j.TXText text)
          Creates a formatted string representation of the specified text Node, and directs it to the print writer.
 

Field Detail

indent

public int indent

m_attrSpecialChars

public java.lang.String m_attrSpecialChars
These are characters that will be escaped in the output.
Constructor Detail

HTMLFormatPrintVisitor

public HTMLFormatPrintVisitor(java.io.Writer writer,
                              java.lang.String encoding,
                              java.lang.String doctype,
                              int indent)
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.
indent - Number of spaces to indent at each nesting level.

HTMLFormatPrintVisitor

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

HTMLFormatPrintVisitor

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

HTMLFormatPrintVisitor

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

visitDocumentPre

public void visitDocumentPre(com.lotus.xsl.xml4j.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.

visitDocumentPost

public void visitDocumentPost(com.lotus.xsl.xml4j.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.

visitElementPre

public void visitElementPre(com.lotus.xsl.xml4j.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.
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.

visitElementPost

public void visitElementPost(com.lotus.xsl.xml4j.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.

visitAttributePre

public void visitAttributePre(com.lotus.xsl.xml4j.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.

visitPIPre

public void visitPIPre(com.lotus.xsl.xml4j.TXPI pi)
                throws java.lang.Exception
Ignore TXPI Nodes.
Parameters:
pi - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.

visitTextPre

public void visitTextPre(com.lotus.xsl.xml4j.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.

visitDTDPre

public void visitDTDPre(com.lotus.xsl.xml4j.DTD dtd)
                 throws java.lang.Exception
Ignore DTD Nodes.
Parameters:
dtd - CURRENTLY NOT IMPLEMENTED.
Throws:
ToNextSibligTraversalException - Always thrown.

visitDTDPost

public void visitDTDPost(com.lotus.xsl.xml4j.DTD dtd)
                  throws java.lang.Exception
Ignore DTD Nodes.
Parameters:
dtd - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.

visitElementDeclPre

public void visitElementDeclPre(com.lotus.xsl.xml4j.ElementDecl elementDecl)
                         throws java.lang.Exception
Ignore ElementDecl Nodes.
Parameters:
elementDecl - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.

visitAttlistPre

public void visitAttlistPre(com.lotus.xsl.xml4j.Attlist attlist)
                     throws java.lang.Exception
Ignore Attlist Nodes.
Parameters:
attlist - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.

visitAttDefPre

public void visitAttDefPre(com.lotus.xsl.xml4j.AttDef attDef)
                    throws java.lang.Exception
Ignore AttDef Nodes.
Parameters:
attDef - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.

visitEntityDeclPre

public void visitEntityDeclPre(com.lotus.xsl.xml4j.EntityDecl entity)
                        throws java.lang.Exception
Ignore Entity Nodes.
Parameters:
entity - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.

visitNotationPre

public void visitNotationPre(com.lotus.xsl.xml4j.TXNotation notation)
                      throws java.lang.Exception
Ignore TXNotation Nodes.
Parameters:
notation - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - CURRENTLY NEVER THROWN.

visitGeneralReferencePre

public void visitGeneralReferencePre(com.lotus.xsl.xml4j.GeneralReference generalReference)
                              throws java.lang.Exception
Ignore GeneralReference Nodes. Print contents of GeneralReferences.
Parameters:
generalReference - CURRENTLY NOT IMPLEMENTED.
Throws:
java.lang.Exception - Never thrown.

visitCommentPre

public void visitCommentPre(com.lotus.xsl.xml4j.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.
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.