EAF 7.6 Util

org.enhydra.xml.io
Class ExtXMLFormatter

java.lang.Object
  extended by org.enhydra.xml.io.ExtXMLFormatter
All Implemented Interfaces:
org.enhydra.util.DOMFormatter, org.enhydra.xml.dom.DOMTraversal.Handler, org.enhydra.xml.io.Formatter

public class ExtXMLFormatter
extends java.lang.Object
implements org.enhydra.util.DOMFormatter

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 java.lang.String ATTR_QUOTE_CHAR_ENTITY_REF
          Entity reference for attribute value quote character.
protected  org.w3c.dom.DocumentType fDocType
          DocumentType from document.
protected  org.w3c.dom.Document fDocument
          Document being formatted.
protected  int fDynamicFormattedElementCount
          Count of element open tags that were written not using preformatted text.
protected  org.enhydra.xml.io.OutputOptions fOptions
          The output options.
protected  java.io.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  java.lang.String fPublicId
          Public id to use for DOCTYPE, or null if none.
protected  java.lang.String fSystemId
          System id to use for DOCTYPE, or null if none.
protected  org.enhydra.xml.dom.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.
 
Fields inherited from interface org.enhydra.util.DOMFormatter
FORMATTER_NAME
 
Constructor Summary
ExtXMLFormatter(org.w3c.dom.Node node, org.enhydra.xml.io.OutputOptions outputOptions, boolean forPreFormatting)
          Constructor.
 
Method Summary
static org.enhydra.xml.io.DocumentInfo findDocumentInfo(org.w3c.dom.Document document)
          Get the DocumentInfo object, if available.
protected  java.lang.String getCharacterEntity(char textChar)
          Get a character entity name for a character.
 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.
static org.enhydra.xml.io.Formatter getFormatter(org.w3c.dom.Node node, org.enhydra.xml.io.OutputOptions outputOptions, boolean forPreFormatting)
           
 java.lang.String getMIMEEncoding()
           
 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(org.w3c.dom.Attr attr)
          Handler called for Attr nodes.
 void handleCDATASection(org.w3c.dom.CDATASection cdata)
          Handler called for CDATASection nodes.
 void handleComment(org.w3c.dom.Comment comment)
          Handler called for Comment nodes.
 void handleDocument(org.w3c.dom.Document document)
          Handler called for Document nodes; creates the XML file header.
 void handleDocumentFragment(org.w3c.dom.DocumentFragment documentFragment)
          Handler called for DocumentFragment nodes; just process children
 void handleDocumentType(org.w3c.dom.DocumentType documentType)
          Handler called for Document nodes; writes the DOCTYPE specification.
 void handleElement(org.w3c.dom.Element element)
          Handler called for Element nodes.
 void handleEntity(org.w3c.dom.Entity entity)
          Handler called for Entity nodes; should never be called.
 void handleEntityReference(org.w3c.dom.EntityReference entityRef)
          Handler called for EntityReference nodes.
 void handleNotation(org.w3c.dom.Notation notation)
          Handler called for Notation nodes; should never be called.
 void handleProcessingInstruction(org.w3c.dom.ProcessingInstruction pi)
          Handler called for ProcessingInstruction nodes.
 void handleText(org.w3c.dom.Text text)
          Handler called for Text nodes.
 java.lang.String preFormatNode(org.w3c.dom.Node node)
           
protected  void printIndent()
          Print indentation to the current level.
 byte[] toBytes(org.w3c.dom.Node document)
           
 boolean usedPreFormattedElements()
           
 boolean usedPreFormattedText()
           
 void write(org.w3c.dom.Node node, java.io.OutputStream out)
          Output a document or any node and its children to a OutputStream.
 void write(org.w3c.dom.Node node, java.io.Writer writer)
          Format a Node and children to the specified writer.
protected  void writeAttributeValue(org.w3c.dom.Attr attr)
          Write an attribute value.
protected  void writeln()
          Write a newline
protected  void writeOpenTag(org.w3c.dom.Element element, java.lang.String tagName, boolean hasChildren)
          Write an element open tag.
protected  void writeText(java.lang.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
 

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 java.lang.String ATTR_QUOTE_CHAR_ENTITY_REF
Entity reference for attribute value quote character.

See Also:
Constant Field Values

fOptions

protected final org.enhydra.xml.io.OutputOptions fOptions
The output options.


fOut

protected java.io.Writer fOut
Output writer.


fTraverser

protected final org.enhydra.xml.dom.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, in which case it's 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 org.w3c.dom.Document fDocument
Document being formatted.


fDocType

protected final org.w3c.dom.DocumentType fDocType
DocumentType from document.


fPublicId

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


fSystemId

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

Constructor Detail

ExtXMLFormatter

public ExtXMLFormatter(org.w3c.dom.Node node,
                       org.enhydra.xml.io.OutputOptions outputOptions,
                       boolean forPreFormatting)
Constructor.

Method Detail

getCharacterEntity

protected final java.lang.String getCharacterEntity(char textChar)
Get a character entity name for a character. This is the slow-path, so its ok this is an abstract method call.

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

handleDocument

public void handleDocument(org.w3c.dom.Document document)
                    throws java.io.IOException
Handler called for Document nodes; creates the XML file header.

Specified by:
handleDocument in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleDocument(org.w3c.dom.Document)

handleDocumentType

public void handleDocumentType(org.w3c.dom.DocumentType documentType)
                        throws java.io.IOException
Handler called for Document nodes; writes the DOCTYPE specification.

Specified by:
handleDocumentType in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleDocumentType(org.w3c.dom.DocumentType)

handleDocumentFragment

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

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

handleAttr

public void handleAttr(org.w3c.dom.Attr attr)
                throws java.io.IOException
Handler called for Attr nodes.

Specified by:
handleAttr in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleAttr(org.w3c.dom.Attr)

writeOpenTag

protected final void writeOpenTag(org.w3c.dom.Element element,
                                  java.lang.String tagName,
                                  boolean hasChildren)
                           throws java.io.IOException
Write an element open tag.

Throws:
java.io.IOException

handleElement

public void handleElement(org.w3c.dom.Element element)
                   throws java.io.IOException
Handler called for Element nodes.

Specified by:
handleElement in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleElement(org.w3c.dom.Element)

handleProcessingInstruction

public void handleProcessingInstruction(org.w3c.dom.ProcessingInstruction pi)
                                 throws java.io.IOException
Handler called for ProcessingInstruction nodes.

Specified by:
handleProcessingInstruction in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleProcessingInstruction(org.w3c.dom.ProcessingInstruction)

handleCDATASection

public void handleCDATASection(org.w3c.dom.CDATASection cdata)
                        throws java.io.IOException
Handler called for CDATASection nodes.

Specified by:
handleCDATASection in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleCDATASection(org.w3c.dom.CDATASection)

handleText

public final void handleText(org.w3c.dom.Text text)
                      throws java.io.IOException
Handler called for Text nodes.

Specified by:
handleText in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleText(org.w3c.dom.Text)

toBytes

public byte[] toBytes(org.w3c.dom.Node document)
Specified by:
toBytes in interface org.enhydra.util.DOMFormatter

write

public void write(org.w3c.dom.Node node,
                  java.io.OutputStream out)
           throws java.io.IOException
Output a document or any node and its children to a OutputStream.

Throws:
java.io.IOException

getFormatter

public static org.enhydra.xml.io.Formatter getFormatter(org.w3c.dom.Node node,
                                                        org.enhydra.xml.io.OutputOptions outputOptions,
                                                        boolean forPreFormatting)

findDocumentInfo

public static org.enhydra.xml.io.DocumentInfo findDocumentInfo(org.w3c.dom.Document document)
Get the DocumentInfo object, if available. This is our extension


getMIMEEncoding

public final java.lang.String getMIMEEncoding()
Specified by:
getMIMEEncoding in interface org.enhydra.xml.io.Formatter
See Also:
Formatter.getMIMEEncoding()

usedPreFormattedText

public boolean usedPreFormattedText()
Specified by:
usedPreFormattedText in interface org.enhydra.xml.io.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 org.enhydra.xml.io.Formatter

getDynamicFormattedTextCount

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

Specified by:
getDynamicFormattedTextCount in interface org.enhydra.xml.io.Formatter

usedPreFormattedElements

public final boolean usedPreFormattedElements()
Specified by:
usedPreFormattedElements in interface org.enhydra.xml.io.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 org.enhydra.xml.io.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 org.enhydra.xml.io.Formatter

writeln

protected final void writeln()
                      throws java.io.IOException
Write a newline

Throws:
java.io.IOException

printIndent

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

Throws:
java.io.IOException

writeText

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

Throws:
java.io.IOException

handleEntity

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

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

handleNotation

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

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

handleEntityReference

public final void handleEntityReference(org.w3c.dom.EntityReference entityRef)
                                 throws java.io.IOException
Handler called for EntityReference nodes.

Specified by:
handleEntityReference in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleEntityReference(org.w3c.dom.EntityReference)

handleComment

public final void handleComment(org.w3c.dom.Comment comment)
                         throws java.io.IOException
Handler called for Comment nodes.

Specified by:
handleComment in interface org.enhydra.xml.dom.DOMTraversal.Handler
Throws:
java.io.IOException
See Also:
DOMTraversal.Handler.handleComment(org.w3c.dom.Comment)

writeAttributeValue

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

Throws:
java.io.IOException

preFormatNode

public final java.lang.String preFormatNode(org.w3c.dom.Node node)
Specified by:
preFormatNode in interface org.enhydra.xml.io.Formatter
See Also:
Formatter.preFormatNode(org.w3c.dom.Node)

write

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

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

EAF 7.6 Util