org.enhydra.xml.io
Class HTMLFormatter

java.lang.Object
  |
  +--org.enhydra.xml.io.BaseDOMFormatter
        |
        +--org.enhydra.xml.io.HTMLFormatter
All Implemented Interfaces:
DOMTraversal.Handler, Formatter

final class HTMLFormatter
extends BaseDOMFormatter
implements Formatter

Formatter for outputting a HTML DOM as a HTML text document.


Field Summary
protected static char ATTR_QUOTE_CHAR
          Quote character to use for attribute values.
protected static String ATTR_QUOTE_CHAR_ENTITY_REF
          Entity reference for attribute value quote character.
protected  DocumentType fDocType
          DocumentType from document.
protected  Document fDocument
          Document being formatted.
protected  int fDynamicFormattedElementCount
          Count of element open tags that were written not using preformatted text.
protected  OutputOptions fOptions
          The output options.
protected  Writer fOut
          Output writer.
protected  boolean fPreFormatMode
          Are we doing pre-formatting?
protected  int fPreFormattedElementCount
          Count of preformatted element open tags that were written.
protected  boolean fPrettyPrinting
          Are we pretty-printing?
protected  String fPublicId
          Public id to use for DOCTYPE, or null if none.
protected  String fSystemId
          System id to use for DOCTYPE, or null if none.
protected  DOMTraversal fTraverser
          DOM traverser.
protected  boolean fUsePreFormattedAttrText
          Should pre-formatted text be use for descendents of attribute nodes.
protected  boolean fUsePreFormattedElements
          Should pre-formatted Elements be written.
protected  boolean fUsePreFormattedText
          Should pre-formatted text be written.
protected static int MAX_ENTITY_QUICK_CHECK_CHAR
          Maximum character value in an entity quick-check table.
 
Constructor Summary
HTMLFormatter(Node node, OutputOptions outputOptions, boolean forPreFormatting)
          Constructor.
 
Method Summary
protected  String getCharacterEntity(char textChar)
          Get a character entity name for a character.
(package private) static OutputOptions getDefaultOutputOptions()
          Get the default OutputOptions for a document formatter with this formatter.
 int getDynamicFormattedElementCount()
          Get the count of element open tags that were written not using preformatted text.
 int getDynamicFormattedTextCount()
          Get the count of text nodes that were written not using preformatted text.
 String getMIMEEncoding()
          Get the MIME-preferred encoding, determined from the OutputOptions and the formatter type.
 int getPreFormattedElementCount()
          Get the count of preformatted element open tags that were written.
 int getPreFormattedTextCount()
          Get the count of preformatted text nodes that were written.
 void handleAttr(Attr attr)
          Handler called for Attr nodes.
 void handleCDATASection(CDATASection cdata)
          Handler called for CDATASection nodes.
 void handleComment(Comment comment)
          Handler called for Comment nodes.
 void handleDocument(Document document)
          Handler called for Document nodes.
 void handleDocumentFragment(DocumentFragment documentFragment)
          Handler called for DocumentFragment nodes; just process children.
 void handleDocumentType(DocumentType documentType)
          Handler called for Document nodes; should never be called.
 void handleElement(Element element)
          Handler called for Element nodes.
 void handleEntity(Entity entity)
          Handler called for Entity nodes; should never be called.
 void handleEntityReference(EntityReference entityRef)
          Handler called for EntityReference nodes.
 void handleNotation(Notation notation)
          Handler called for Notation nodes; should never be called.
 void handleProcessingInstruction(ProcessingInstruction pi)
          Handler called for ProcessingInstruction nodes.
 void handleText(Text text)
          Handler called for Text nodes.
 String preFormatNode(Node node)
          Format the contents of a node that can later be returned by a node implementing FormattedText.
protected  void printIndent()
          Print indentation to the current level.
 boolean usedPreFormattedElements()
          Determine if preformatted element open tags were used for the last document formatted.
 boolean usedPreFormattedText()
          Determine if preformatted text was used for the last document formatted.
 void write(Node node, Writer writer)
          Format a Node and children to the specified writer.
protected  void writeAttributeValue(Attr attr)
          Write an attribute value.
protected  void writeln()
          Write a newline
protected  void writeOpenTag(Element element, String tagName, boolean hasChildren)
          Write an element open tag.
protected  void writeText(String text)
          Write a text string, encoding document type-specific character entities.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.enhydra.xml.io.Formatter
getDynamicFormattedElementCount, getDynamicFormattedTextCount, getMIMEEncoding, getPreFormattedElementCount, getPreFormattedTextCount, preFormatNode, usedPreFormattedElements, usedPreFormattedText, write
 

Field Detail

MAX_ENTITY_QUICK_CHECK_CHAR

protected static final int MAX_ENTITY_QUICK_CHECK_CHAR
Maximum character value in an entity quick-check table.

See Also:
Constant Field Values

ATTR_QUOTE_CHAR

protected static final char ATTR_QUOTE_CHAR
Quote character to use for attribute values.

See Also:
Constant Field Values

ATTR_QUOTE_CHAR_ENTITY_REF

protected static final String ATTR_QUOTE_CHAR_ENTITY_REF
Entity reference for attribute value quote character.

See Also:
Constant Field Values

fOptions

protected final OutputOptions fOptions
The output options.


fOut

protected Writer fOut
Output writer.


fTraverser

protected final DOMTraversal fTraverser
DOM traverser.


fPreFormatMode

protected final boolean fPreFormatMode
Are we doing pre-formatting?


fUsePreFormattedText

protected final boolean fUsePreFormattedText
Should pre-formatted text be written. This is only enabled if the document implements PreFormattedTextDocument and the preformatted encoding matches the output encoding. This option only controls text nodes that are not children of attributes.


fUsePreFormattedAttrText

protected final boolean fUsePreFormattedAttrText
Should pre-formatted text be use for descendents of attribute nodes. A seperate flag is required to support the omitAttributeCharEntityRefs option.


fUsePreFormattedElements

protected final boolean fUsePreFormattedElements
Should pre-formatted Elements be written. This is the same as fUsePreFormattedText, unless a URLRewriter is present, it which cases its false, since we need to check the attributes for URLs.


fPreFormattedElementCount

protected int fPreFormattedElementCount
Count of preformatted element open tags that were written.


fDynamicFormattedElementCount

protected int fDynamicFormattedElementCount
Count of element open tags that were written not using preformatted text.


fPrettyPrinting

protected final boolean fPrettyPrinting
Are we pretty-printing?


fDocument

protected final Document fDocument
Document being formatted.


fDocType

protected final DocumentType fDocType
DocumentType from document.


fPublicId

protected final String fPublicId
Public id to use for DOCTYPE, or null if none.


fSystemId

protected final String fSystemId
System id to use for DOCTYPE, or null if none.

Constructor Detail

HTMLFormatter

public HTMLFormatter(Node node,
                     OutputOptions outputOptions,
                     boolean forPreFormatting)
Constructor.

Method Detail

getDefaultOutputOptions

static OutputOptions getDefaultOutputOptions()
Get the default OutputOptions for a document formatter with this formatter. The encoding will not be set, which signals to use the default encoding.


getCharacterEntity

protected final String getCharacterEntity(char textChar)
Description copied from class: BaseDOMFormatter
Get a character entity name for a character. This is the slow-path, so its ok this is an abstract method call.

Specified by:
getCharacterEntity in class BaseDOMFormatter
Returns:
The character entity name, or null if this character doesn't have one.
See Also:
BaseDOMFormatter.getCharacterEntity(char)

handleDocument

public void handleDocument(Document document)
                    throws IOException
Handler called for Document nodes.

Specified by:
handleDocument in interface DOMTraversal.Handler
IOException
See Also:
DOMTraversal.Handler.handleDocument(org.w3c.dom.Document)

handleDocumentType

public void handleDocumentType(DocumentType documentType)
                        throws IOException
Handler called for Document nodes; should never be called.

Specified by:
handleDocumentType in interface DOMTraversal.Handler
IOException
See Also:
DOMTraversal.Handler.handleDocumentType(org.w3c.dom.DocumentType)

handleDocumentFragment

public void handleDocumentFragment(DocumentFragment documentFragment)
Handler called for DocumentFragment nodes; just process children.

Specified by:
handleDocumentFragment in interface DOMTraversal.Handler
See Also:
DOMTraversal.Handler.handleDocumentFragment(org.w3c.dom.DocumentFragment)

handleAttr

public void handleAttr(Attr attr)
                throws IOException
Handler called for Attr nodes.

Specified by:
handleAttr in interface DOMTraversal.Handler
IOException
See Also:
DOMTraversal.Handler.handleAttr(org.w3c.dom.Attr)

writeOpenTag

protected final void writeOpenTag(Element element,
                                  String tagName,
                                  boolean hasChildren)
                           throws IOException
Write an element open tag. The hasChildren option is ignored.

Specified by:
writeOpenTag in class BaseDOMFormatter
IOException

handleElement

public void handleElement(Element element)
                   throws IOException
Handler called for Element nodes.

This optionally corrects problem cases for browsers:

Specified by:
handleElement in interface DOMTraversal.Handler
IOException
See Also:
DOMTraversal.Handler.handleElement(org.w3c.dom.Element)

handleProcessingInstruction

public void handleProcessingInstruction(ProcessingInstruction pi)
                                 throws IOException
Handler called for ProcessingInstruction nodes.

Specified by:
handleProcessingInstruction in interface DOMTraversal.Handler
IOException
See Also:
DOMTraversal.Handler.handleProcessingInstruction(org.w3c.dom.ProcessingInstruction)

handleCDATASection

public void handleCDATASection(CDATASection cdata)
                        throws IOException
Handler called for CDATASection nodes. Non-standard extension: outputs data as-is.

Specified by:
handleCDATASection in interface DOMTraversal.Handler
IOException
See Also:
DOMTraversal.Handler.handleCDATASection(org.w3c.dom.CDATASection)

handleText

public final void handleText(Text text)
                      throws IOException
Handler called for Text nodes.

Specified by:
handleText in interface DOMTraversal.Handler
Overrides:
handleText in class BaseDOMFormatter
IOException
See Also:
DOMTraversal.Handler.handleText(org.w3c.dom.Text)

getMIMEEncoding

public final String getMIMEEncoding()
Description copied from interface: Formatter
Get the MIME-preferred encoding, determined from the OutputOptions and the formatter type.

Specified by:
getMIMEEncoding in interface Formatter
See Also:
Formatter.getMIMEEncoding()

usedPreFormattedText

public boolean usedPreFormattedText()
Description copied from interface: Formatter
Determine if preformatted text was used for the last document formatted. The results are only meaninful if called after a call to write().

Specified by:
usedPreFormattedText in interface Formatter
See Also:
Formatter.usedPreFormattedText()

getPreFormattedTextCount

public final int getPreFormattedTextCount()
Get the count of preformatted text nodes that were written.

Specified by:
getPreFormattedTextCount in interface Formatter

getDynamicFormattedTextCount

public final int getDynamicFormattedTextCount()
Get the count of text nodes that were written not using preformatted text.

Specified by:
getDynamicFormattedTextCount in interface Formatter

usedPreFormattedElements

public final boolean usedPreFormattedElements()
Description copied from interface: Formatter
Determine if preformatted element open tags were used for the last document formatted. The results are only meaninful if called after a call to write().

Specified by:
usedPreFormattedElements in interface Formatter
See Also:
Formatter.usedPreFormattedElements()

getPreFormattedElementCount

public final int getPreFormattedElementCount()
Get the count of preformatted element open tags that were written.

Specified by:
getPreFormattedElementCount in interface Formatter

getDynamicFormattedElementCount

public final int getDynamicFormattedElementCount()
Get the count of element open tags that were written not using preformatted text.

Specified by:
getDynamicFormattedElementCount in interface Formatter

writeln

protected final void writeln()
                      throws IOException
Write a newline

IOException

printIndent

protected final void printIndent()
                          throws IOException
Print indentation to the current level.

IOException

writeText

protected final void writeText(String text)
                        throws IOException
Write a text string, encoding document type-specific character entities. This is an expensive procedure and has been carefully hand optimized.

IOException

handleEntity

public final void handleEntity(Entity entity)
Handler called for Entity nodes; should never be called.

Specified by:
handleEntity in interface DOMTraversal.Handler
See Also:
DOMTraversal.Handler.handleEntity(org.w3c.dom.Entity)

handleNotation

public final void handleNotation(Notation notation)
Handler called for Notation nodes; should never be called.

Specified by:
handleNotation in interface DOMTraversal.Handler
See Also:
DOMTraversal.Handler.handleNotation(org.w3c.dom.Notation)

handleEntityReference

public final void handleEntityReference(EntityReference entityRef)
                                 throws IOException
Handler called for EntityReference nodes.

Specified by:
handleEntityReference in interface DOMTraversal.Handler
IOException
See Also:
DOMTraversal.Handler.handleEntityReference(org.w3c.dom.EntityReference)

handleComment

public final void handleComment(Comment comment)
                         throws IOException
Handler called for Comment nodes.

Specified by:
handleComment in interface DOMTraversal.Handler
IOException
See Also:
DOMTraversal.Handler.handleComment(org.w3c.dom.Comment)

writeAttributeValue

protected final void writeAttributeValue(Attr attr)
                                  throws IOException
Write an attribute value. Convert characters to character entity references as needed.

IOException

preFormatNode

public final String preFormatNode(Node node)
Description copied from interface: Formatter
Format the contents of a node that can later be returned by a node implementing FormattedText. Not all node types will return formatted text.

Specified by:
preFormatNode in interface Formatter
See Also:
Formatter.preFormatNode(org.w3c.dom.Node)

write

public final void write(Node node,
                        Writer writer)
                 throws IOException
Format a Node and children to the specified writer.

Specified by:
write in interface Formatter
IOException
See Also:
Formatter.write(org.w3c.dom.Node, java.io.Writer)


Copyright © 1999-2002 enhydra.org (Mark Diekhans, David Li, Richard Kunze). All Rights reserved.