org.codehaus.staxmate.dom
Class DOMConverter

java.lang.Object
  extended by org.codehaus.staxmate.dom.DOMConverter

public class DOMConverter
extends java.lang.Object

Class that can build DOM trees and fragments using Stax stream readers, and write them out using Stax stream writers.


Field Summary
protected  javax.xml.parsers.DocumentBuilder _docBuilder
           
protected  boolean _inputCfgIgnoreWs
          Whether ignorable white space should be ignored, ie not added in the resulting JDOM tree.
 
Constructor Summary
DOMConverter()
           
DOMConverter(javax.xml.parsers.DocumentBuilder b)
           
 
Method Summary
protected  void _build(javax.xml.stream.XMLStreamReader r0, org.w3c.dom.Document doc)
          This method takes a XMLStreamReader and builds up a JDOM tree.
protected  java.lang.String _buildDTD(org.w3c.dom.DocumentType doctype)
           
protected static boolean _isNamespaceAware(javax.xml.stream.XMLStreamReader r)
           
protected  void _writeElement(org.codehaus.stax2.XMLStreamWriter2 sw, org.w3c.dom.Element elem)
          Method called to output an element node and all of its children (recursively).
protected  void _writeNode(org.codehaus.stax2.XMLStreamWriter2 sw, org.w3c.dom.Node node)
           
 org.w3c.dom.Document buildDocument(javax.xml.stream.XMLStreamReader r)
          This method will create a Document instance using the default JAXP DOM document construction mechanism and populated using the given StAX stream reader.
 void buildDocument(javax.xml.stream.XMLStreamReader r, org.w3c.dom.Document doc)
          This method will populate given Document using the given StAX stream reader instance.
 org.w3c.dom.Document buildDocument(javax.xml.stream.XMLStreamReader r, javax.xml.parsers.DocumentBuilder docbuilder)
          This method will create a Document instance using given DocumentBuilder and populated using the given StAX stream reader.
 void setIgnoreWhitespace(boolean state)
          Method used to change whether the build methods will add ignorable (element) white space in the DOM tree or not.
 void writeDocument(org.w3c.dom.Document doc, javax.xml.stream.XMLStreamWriter sw0)
          Method for writing out given DOM document using specified stream writer.
 void writeFragment(org.w3c.dom.NodeList nodes, javax.xml.stream.XMLStreamWriter sw0)
           
 void writeFragment(org.w3c.dom.Node node, javax.xml.stream.XMLStreamWriter sw0)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_docBuilder

protected final javax.xml.parsers.DocumentBuilder _docBuilder

_inputCfgIgnoreWs

protected boolean _inputCfgIgnoreWs
Whether ignorable white space should be ignored, ie not added in the resulting JDOM tree. If true, it will be ignored; if false, it will be added in the tree. Default value if false.

Constructor Detail

DOMConverter

public DOMConverter()

DOMConverter

public DOMConverter(javax.xml.parsers.DocumentBuilder b)
Method Detail

setIgnoreWhitespace

public void setIgnoreWhitespace(boolean state)
Method used to change whether the build methods will add ignorable (element) white space in the DOM tree or not.

Whether all-whitespace text segment is ignorable white space or not is based on DTD read in, as per XML specifications (white space is only significant in mixed content or pure text elements).


buildDocument

public org.w3c.dom.Document buildDocument(javax.xml.stream.XMLStreamReader r)
                                   throws javax.xml.stream.XMLStreamException
This method will create a Document instance using the default JAXP DOM document construction mechanism and populated using the given StAX stream reader. Namespace-awareness will be enabled for the DocumentBuilderFactory constructed; if this is not wanted, caller should construct DocumentBuilder separately.

Note: underlying stream reader will be closed by the method, but generally this does NOT mean that the stream will be (as per Stax 1.0 specs which defined behavior of XMLStreamReader.close().

Parameters:
r - Stream reader from which input is read.
Returns:
Document - DOM document object.
Throws:
javax.xml.stream.XMLStreamException - If the reader threw such exception (to indicate a parsing or I/O problem)

buildDocument

public org.w3c.dom.Document buildDocument(javax.xml.stream.XMLStreamReader r,
                                          javax.xml.parsers.DocumentBuilder docbuilder)
                                   throws javax.xml.stream.XMLStreamException
This method will create a Document instance using given DocumentBuilder and populated using the given StAX stream reader.

Note: underlying stream reader will be closed by the method, but generally this does NOT mean that the stream will be (as per Stax 1.0 specs which defined behavior of XMLStreamReader.close().

Parameters:
r - Stream reader from which input is read.
Returns:
Document - DOM document object.
Throws:
javax.xml.stream.XMLStreamException - If the reader threw such exception (to indicate a parsing or I/O problem)

buildDocument

public void buildDocument(javax.xml.stream.XMLStreamReader r,
                          org.w3c.dom.Document doc)
                   throws javax.xml.stream.XMLStreamException
This method will populate given Document using the given StAX stream reader instance.

Note: underlying stream reader will be closed by the method, but generally this does NOT mean that the stream will be (as per Stax 1.0 specs which defined behavior of XMLStreamReader.close().

Parameters:
r - Stream reader from which input is read.
Throws:
javax.xml.stream.XMLStreamException - If the reader threw such exception (to indicate a parsing or I/O problem)

_build

protected void _build(javax.xml.stream.XMLStreamReader r0,
                      org.w3c.dom.Document doc)
               throws javax.xml.stream.XMLStreamException
This method takes a XMLStreamReader and builds up a JDOM tree. Recursion has been eliminated by using nodes' parent/child relationship; this improves performance somewhat (classic recursion-by-iteration-and-explicit stack transformation)

Parameters:
r0 - Stream reader to use for reading the document from which to build the tree
doc - Document being built.
Throws:
javax.xml.stream.XMLStreamException

writeDocument

public void writeDocument(org.w3c.dom.Document doc,
                          javax.xml.stream.XMLStreamWriter sw0)
                   throws javax.xml.stream.XMLStreamException
Method for writing out given DOM document using specified stream writer.

Note: only regular XMLStreamWriter.close() is called on the stream writer. This usually means that the underlying stream is not closed (as per Stax 1.0 specification).

Throws:
javax.xml.stream.XMLStreamException

writeFragment

public void writeFragment(org.w3c.dom.NodeList nodes,
                          javax.xml.stream.XMLStreamWriter sw0)
                   throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

writeFragment

public void writeFragment(org.w3c.dom.Node node,
                          javax.xml.stream.XMLStreamWriter sw0)
                   throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

_isNamespaceAware

protected static boolean _isNamespaceAware(javax.xml.stream.XMLStreamReader r)
                                    throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

_writeNode

protected void _writeNode(org.codehaus.stax2.XMLStreamWriter2 sw,
                          org.w3c.dom.Node node)
                   throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

_buildDTD

protected java.lang.String _buildDTD(org.w3c.dom.DocumentType doctype)

_writeElement

protected void _writeElement(org.codehaus.stax2.XMLStreamWriter2 sw,
                             org.w3c.dom.Element elem)
                      throws javax.xml.stream.XMLStreamException
Method called to output an element node and all of its children (recursively).

Parameters:
elem - Element to output
Throws:
javax.xml.stream.XMLStreamException