org.apache.xml.serializer.dom3
Class DOM3TreeWalker

java.lang.Object
  extended by org.apache.xml.serializer.dom3.DOM3TreeWalker

final class DOM3TreeWalker
extends java.lang.Object

Built on org.apache.xml.serializer.TreeWalker and adds functionality to traverse and serialize a DOM Node (Level 2 or Level 3) as specified in the DOM Level 3 LS Recommedation by evaluating and applying DOMConfiguration parameters and filters if any during serialization.


Field Summary
private static int CANONICAL
           
private static int CDATA
           
private static int CHARNORMALIZE
           
private static int COMMENTS
           
private static int DISCARDDEFAULT
           
private static int DTNORMALIZE
           
private static int ELEM_CONTENT_WHITESPACE
           
private static int ENTITIES
           
private  java.util.Properties fDOMConfigProperties
          DOMConfiguration Properties
private  int fElementDepth
          stores the current element depth
private  org.w3c.dom.DOMErrorHandler fErrorHandler
          ErrorHandler
private  int fFeatures
          DOM Configuration Parameters
private  org.w3c.dom.ls.LSSerializerFilter fFilter
          LSSerializerFilter
private  boolean fInEntityRef
          Keeps track if we are in an entity reference when entities=true
private  boolean fIsLevel3DOM
          Is the Node a Level 3 DOM node
private  boolean fIsXMLVersion11
          XML Version, default 1.0
private  org.xml.sax.ext.LexicalHandler fLexicalHandler
          If the serializer is an instance of a LexicalHandler
protected  NamespaceSupport fLocalNSBinder
          stores all namespace bindings on the current element
private  org.xml.sax.helpers.LocatorImpl fLocator
          Locator object for this TreeWalker
private  java.lang.String fNewLine
          New Line character to use in serialization
(package private)  boolean fNextIsRaw
          Flag indicating whether following text to be processed is raw text
protected  NamespaceSupport fNSBinder
          stores namespaces in scope
private  SerializationHandler fSerializer
          The SerializationHandler, it extends ContentHandler and when this class is instantiated via the constructor provided, a SerializationHandler object is passed to it.
private  int fWhatToShowFilter
           
private  java.lang.String fXMLVersion
          Stores the version of the XML document to be serialize
private static int IGNORE_CHAR_DENORMALIZE
           
private static int INFOSET
           
private static int NAMESPACEDECLS
           
private static int NAMESPACES
           
private static int NORMALIZECHARS
           
private static int PRETTY_PRINT
           
private static java.util.Hashtable s_propKeys
          This table is a quick lookup of a property key (String) to the integer that is the bit to flip in the fFeatures field, so the integers should have values 1,2,4,8,16...
private static int SCHEMAVALIDATE
           
private static int SPLITCDATA
           
private static int VALIDATE
           
private static int WELLFORMED
           
private static java.lang.String XML_PREFIX
           
private static java.lang.String XML_URI
           
private static int XMLDECL
           
private static java.lang.String XMLNS_PREFIX
           
private static java.lang.String XMLNS_URI
           
 
Constructor Summary
DOM3TreeWalker(SerializationHandler serialHandler, org.w3c.dom.DOMErrorHandler errHandler, org.w3c.dom.ls.LSSerializerFilter filter, java.lang.String newLine)
          Constructor.
 
Method Summary
protected  boolean applyFilter(org.w3c.dom.Node node, int nodeType)
          Applies a filter on the node to serialize
protected  void checkUnboundPrefixInEntRef(org.w3c.dom.Node node)
          If the configuration parameter "namespaces" is set to true, this methods checks if an entity whose replacement text contains unbound namespace prefixes is referenced in a location where there are no bindings for the namespace prefixes and if so raises a LSException with the error-type "unbound-prefix-in-entity-reference"
private  void dispatachChars(org.w3c.dom.Node node)
          Optimized dispatch of characters.
protected  void endNode(org.w3c.dom.Node node)
          End processing of given node
protected  void fixupElementNS(org.w3c.dom.Node node)
          Fixes an element's namespace
protected  void initProperties(java.util.Properties properties)
          Initializes fFeatures based on the DOMConfiguration Parameters set.
protected  void isAttributeWellFormed(org.w3c.dom.Node node)
          Checks if an attr node is well-formed, by checking it's Name and value for well-formedness.
protected  void isCDATASectionWellFormed(org.w3c.dom.CDATASection node)
          Checks if an CDATASection node is well-formed, by checking it's data for well-formedness.
protected  void isCommentWellFormed(java.lang.String data)
          Checks if a comment node is well-formed
protected  void isElementWellFormed(org.w3c.dom.Node node)
          Checks if an element node is well-formed, by checking its Name for well-formedness.
protected  void isEntityReferneceWellFormed(org.w3c.dom.EntityReference node)
          Checks if an EntityRefernece node is well-formed, by checking it's node name.
protected  void isPIWellFormed(org.w3c.dom.ProcessingInstruction node)
          Checks if a PI node is well-formed, by checking it's Name and data for well-formedness.
protected  void isTextWellFormed(org.w3c.dom.Text node)
          Checks if an Text node is well-formed, by checking if it contains invalid XML characters.
protected  boolean isValidQName(java.lang.String prefix, java.lang.String local, boolean xml11Version)
          Taken from org.apache.xerces.dom.CoreDocumentImpl Checks if the given qualified name is legal with respect to the version of XML to which this document must conform.
protected  java.lang.Character isWFXMLChar(java.lang.String chardata)
          Checks if a XML character is well-formed.
protected  boolean isWFXMLChar(java.lang.String chardata, java.lang.Character refInvalidChar)
          Checks if a XML character is well-formed
protected  boolean isXMLName(java.lang.String s, boolean xml11Version)
          Taken from org.apache.xerces.dom.CoreDocumentImpl Check the string against XML's definition of acceptable names for elements and attributes and so on using the XMLCharacterProperties utility class
protected  void recordLocalNSDecl(org.w3c.dom.Node node)
          Records local namespace declarations, to be used for normalization later
protected  void serializeAttList(org.w3c.dom.Element node)
          Serializes the Attr Nodes of an Element.
protected  void serializeCDATASection(org.w3c.dom.CDATASection node)
          Serializes an CDATASection Node.
protected  void serializeComment(org.w3c.dom.Comment node)
          Serializes a Comment Node.
protected  void serializeDocType(org.w3c.dom.DocumentType node, boolean bStart)
          Serializes a Document Type Node.
protected  void serializeElement(org.w3c.dom.Element node, boolean bStart)
          Serializes an Element Node.
protected  void serializeEntityReference(org.w3c.dom.EntityReference node, boolean bStart)
          Serializes an EntityReference Node.
protected  void serializePI(org.w3c.dom.ProcessingInstruction node)
          Serializes an ProcessingInstruction Node.
protected  void serializeText(org.w3c.dom.Text node)
          Serializes an Text Node.
protected  void startNode(org.w3c.dom.Node node)
          Start processing given node
 void traverse(org.w3c.dom.Node pos)
          Perform a pre-order traversal non-recursive style.
 void traverse(org.w3c.dom.Node pos, org.w3c.dom.Node top)
          Perform a pre-order traversal non-recursive style.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fSerializer

private SerializationHandler fSerializer
The SerializationHandler, it extends ContentHandler and when this class is instantiated via the constructor provided, a SerializationHandler object is passed to it.


fLocator

private org.xml.sax.helpers.LocatorImpl fLocator
Locator object for this TreeWalker


fErrorHandler

private org.w3c.dom.DOMErrorHandler fErrorHandler
ErrorHandler


fFilter

private org.w3c.dom.ls.LSSerializerFilter fFilter
LSSerializerFilter


fLexicalHandler

private org.xml.sax.ext.LexicalHandler fLexicalHandler
If the serializer is an instance of a LexicalHandler


fWhatToShowFilter

private int fWhatToShowFilter

fNewLine

private java.lang.String fNewLine
New Line character to use in serialization


fDOMConfigProperties

private java.util.Properties fDOMConfigProperties
DOMConfiguration Properties


fInEntityRef

private boolean fInEntityRef
Keeps track if we are in an entity reference when entities=true


fXMLVersion

private java.lang.String fXMLVersion
Stores the version of the XML document to be serialize


fIsXMLVersion11

private boolean fIsXMLVersion11
XML Version, default 1.0


fIsLevel3DOM

private boolean fIsLevel3DOM
Is the Node a Level 3 DOM node


fFeatures

private int fFeatures
DOM Configuration Parameters


fNextIsRaw

boolean fNextIsRaw
Flag indicating whether following text to be processed is raw text


XMLNS_URI

private static final java.lang.String XMLNS_URI
See Also:
Constant Field Values

XMLNS_PREFIX

private static final java.lang.String XMLNS_PREFIX
See Also:
Constant Field Values

XML_URI

private static final java.lang.String XML_URI
See Also:
Constant Field Values

XML_PREFIX

private static final java.lang.String XML_PREFIX
See Also:
Constant Field Values

fNSBinder

protected NamespaceSupport fNSBinder
stores namespaces in scope


fLocalNSBinder

protected NamespaceSupport fLocalNSBinder
stores all namespace bindings on the current element


fElementDepth

private int fElementDepth
stores the current element depth


CANONICAL

private static final int CANONICAL
See Also:
Constant Field Values

CDATA

private static final int CDATA
See Also:
Constant Field Values

CHARNORMALIZE

private static final int CHARNORMALIZE
See Also:
Constant Field Values

COMMENTS

private static final int COMMENTS
See Also:
Constant Field Values

DTNORMALIZE

private static final int DTNORMALIZE
See Also:
Constant Field Values

ELEM_CONTENT_WHITESPACE

private static final int ELEM_CONTENT_WHITESPACE
See Also:
Constant Field Values

ENTITIES

private static final int ENTITIES
See Also:
Constant Field Values

INFOSET

private static final int INFOSET
See Also:
Constant Field Values

NAMESPACES

private static final int NAMESPACES
See Also:
Constant Field Values

NAMESPACEDECLS

private static final int NAMESPACEDECLS
See Also:
Constant Field Values

NORMALIZECHARS

private static final int NORMALIZECHARS
See Also:
Constant Field Values

SPLITCDATA

private static final int SPLITCDATA
See Also:
Constant Field Values

VALIDATE

private static final int VALIDATE
See Also:
Constant Field Values

SCHEMAVALIDATE

private static final int SCHEMAVALIDATE
See Also:
Constant Field Values

WELLFORMED

private static final int WELLFORMED
See Also:
Constant Field Values

DISCARDDEFAULT

private static final int DISCARDDEFAULT
See Also:
Constant Field Values

PRETTY_PRINT

private static final int PRETTY_PRINT
See Also:
Constant Field Values

IGNORE_CHAR_DENORMALIZE

private static final int IGNORE_CHAR_DENORMALIZE
See Also:
Constant Field Values

XMLDECL

private static final int XMLDECL
See Also:
Constant Field Values

s_propKeys

private static final java.util.Hashtable s_propKeys
This table is a quick lookup of a property key (String) to the integer that is the bit to flip in the fFeatures field, so the integers should have values 1,2,4,8,16...

Constructor Detail

DOM3TreeWalker

DOM3TreeWalker(SerializationHandler serialHandler,
               org.w3c.dom.DOMErrorHandler errHandler,
               org.w3c.dom.ls.LSSerializerFilter filter,
               java.lang.String newLine)
Constructor.

Parameters:
contentHandler - serialHandler The implemention of the SerializationHandler interface
Method Detail

traverse

public void traverse(org.w3c.dom.Node pos)
              throws org.xml.sax.SAXException
Perform a pre-order traversal non-recursive style. Note that TreeWalker assumes that the subtree is intended to represent a complete (though not necessarily well-formed) document and, during a traversal, startDocument and endDocument will always be issued to the SAX listener.

Parameters:
pos - Node in the tree where to start traversal
Throws:
TransformerException
org.xml.sax.SAXException

traverse

public void traverse(org.w3c.dom.Node pos,
                     org.w3c.dom.Node top)
              throws org.xml.sax.SAXException
Perform a pre-order traversal non-recursive style. Note that TreeWalker assumes that the subtree is intended to represent a complete (though not necessarily well-formed) document and, during a traversal, startDocument and endDocument will always be issued to the SAX listener.

Parameters:
pos - Node in the tree where to start traversal
top - Node in the tree where to end traversal
Throws:
TransformerException
org.xml.sax.SAXException

dispatachChars

private final void dispatachChars(org.w3c.dom.Node node)
                           throws org.xml.sax.SAXException
Optimized dispatch of characters.

Throws:
org.xml.sax.SAXException

startNode

protected void startNode(org.w3c.dom.Node node)
                  throws org.xml.sax.SAXException
Start processing given node

Parameters:
node - Node to process
Throws:
org.xml.sax.SAXException

endNode

protected void endNode(org.w3c.dom.Node node)
                throws org.xml.sax.SAXException
End processing of given node

Parameters:
node - Node we just finished processing
Throws:
org.xml.sax.SAXException

applyFilter

protected boolean applyFilter(org.w3c.dom.Node node,
                              int nodeType)
Applies a filter on the node to serialize

Parameters:
node - The Node to serialize
Returns:
True if the node is to be serialized else false if the node is to be rejected or skipped.

serializeDocType

protected void serializeDocType(org.w3c.dom.DocumentType node,
                                boolean bStart)
                         throws org.xml.sax.SAXException
Serializes a Document Type Node.

Parameters:
node - The Docuemnt Type Node to serialize
bStart - Invoked at the start or end of node. Default true.
Throws:
org.xml.sax.SAXException

serializeComment

protected void serializeComment(org.w3c.dom.Comment node)
                         throws org.xml.sax.SAXException
Serializes a Comment Node.

Parameters:
node - The Comment Node to serialize
Throws:
org.xml.sax.SAXException

serializeElement

protected void serializeElement(org.w3c.dom.Element node,
                                boolean bStart)
                         throws org.xml.sax.SAXException
Serializes an Element Node.

Parameters:
node - The Element Node to serialize
bStart - Invoked at the start or end of node.
Throws:
org.xml.sax.SAXException

serializeAttList

protected void serializeAttList(org.w3c.dom.Element node)
                         throws org.xml.sax.SAXException
Serializes the Attr Nodes of an Element.

Parameters:
node - The OwnerElement whose Attr Nodes are to be serialized.
Throws:
org.xml.sax.SAXException

serializePI

protected void serializePI(org.w3c.dom.ProcessingInstruction node)
                    throws org.xml.sax.SAXException
Serializes an ProcessingInstruction Node.

Parameters:
node - The ProcessingInstruction Node to serialize
Throws:
org.xml.sax.SAXException

serializeCDATASection

protected void serializeCDATASection(org.w3c.dom.CDATASection node)
                              throws org.xml.sax.SAXException
Serializes an CDATASection Node.

Parameters:
node - The CDATASection Node to serialize
Throws:
org.xml.sax.SAXException

serializeText

protected void serializeText(org.w3c.dom.Text node)
                      throws org.xml.sax.SAXException
Serializes an Text Node.

Parameters:
node - The Text Node to serialize
Throws:
org.xml.sax.SAXException

serializeEntityReference

protected void serializeEntityReference(org.w3c.dom.EntityReference node,
                                        boolean bStart)
                                 throws org.xml.sax.SAXException
Serializes an EntityReference Node.

Parameters:
node - The EntityReference Node to serialize
bStart - Inicates if called from start or endNode
Throws:
org.xml.sax.SAXException

isXMLName

protected boolean isXMLName(java.lang.String s,
                            boolean xml11Version)
Taken from org.apache.xerces.dom.CoreDocumentImpl Check the string against XML's definition of acceptable names for elements and attributes and so on using the XMLCharacterProperties utility class


isValidQName

protected boolean isValidQName(java.lang.String prefix,
                               java.lang.String local,
                               boolean xml11Version)
Taken from org.apache.xerces.dom.CoreDocumentImpl Checks if the given qualified name is legal with respect to the version of XML to which this document must conform.

Parameters:
prefix - prefix of qualified name
local - local part of qualified name

isWFXMLChar

protected boolean isWFXMLChar(java.lang.String chardata,
                              java.lang.Character refInvalidChar)
Checks if a XML character is well-formed

Parameters:
characters - A String of characters to be checked for Well-Formedness
refInvalidChar - A reference to the character to be returned that was determined invalid.

isWFXMLChar

protected java.lang.Character isWFXMLChar(java.lang.String chardata)
Checks if a XML character is well-formed. If there is a problem with the character a non-null Character is returned else null is returned.

Parameters:
characters - A String of characters to be checked for Well-Formedness
Returns:
Character A reference to the character to be returned that was determined invalid.

isCommentWellFormed

protected void isCommentWellFormed(java.lang.String data)
Checks if a comment node is well-formed

Parameters:
data - The contents of the comment node

isElementWellFormed

protected void isElementWellFormed(org.w3c.dom.Node node)
Checks if an element node is well-formed, by checking its Name for well-formedness.

Parameters:
data - The contents of the comment node

isAttributeWellFormed

protected void isAttributeWellFormed(org.w3c.dom.Node node)
Checks if an attr node is well-formed, by checking it's Name and value for well-formedness.

Parameters:
data - The contents of the comment node

isPIWellFormed

protected void isPIWellFormed(org.w3c.dom.ProcessingInstruction node)
Checks if a PI node is well-formed, by checking it's Name and data for well-formedness.

Parameters:
data - The contents of the comment node

isCDATASectionWellFormed

protected void isCDATASectionWellFormed(org.w3c.dom.CDATASection node)
Checks if an CDATASection node is well-formed, by checking it's data for well-formedness. Note that the presence of a CDATA termination mark in the contents of a CDATASection is handled by the parameter spli-cdata-sections

Parameters:
data - The contents of the comment node

isTextWellFormed

protected void isTextWellFormed(org.w3c.dom.Text node)
Checks if an Text node is well-formed, by checking if it contains invalid XML characters.

Parameters:
data - The contents of the comment node

isEntityReferneceWellFormed

protected void isEntityReferneceWellFormed(org.w3c.dom.EntityReference node)
Checks if an EntityRefernece node is well-formed, by checking it's node name. Then depending on whether it is referenced in Element content or in an Attr Node, checks if the EntityReference references an unparsed entity or a external entity and if so throws raises the appropriate well-formedness error.

Parameters:
data - The contents of the comment node

checkUnboundPrefixInEntRef

protected void checkUnboundPrefixInEntRef(org.w3c.dom.Node node)
If the configuration parameter "namespaces" is set to true, this methods checks if an entity whose replacement text contains unbound namespace prefixes is referenced in a location where there are no bindings for the namespace prefixes and if so raises a LSException with the error-type "unbound-prefix-in-entity-reference"

Parameters:
Node, - The EntityReference nodes whose children are to be checked

recordLocalNSDecl

protected void recordLocalNSDecl(org.w3c.dom.Node node)
Records local namespace declarations, to be used for normalization later

Parameters:
Node, - The element node, whose namespace declarations are to be recorded

fixupElementNS

protected void fixupElementNS(org.w3c.dom.Node node)
                       throws org.xml.sax.SAXException
Fixes an element's namespace

Parameters:
Node, - The element node, whose namespace is to be fixed
Throws:
org.xml.sax.SAXException

initProperties

protected void initProperties(java.util.Properties properties)
Initializes fFeatures based on the DOMConfiguration Parameters set.

Parameters:
properties - DOMConfiguraiton properties that were set and which are to be used while serializing the DOM.