Top Description Inners Fields Constructors Methods
org.jvnet.staxex.util

public Class DOMStreamReader

extends Object
implements XMLStreamReader, NamespaceContext
Class Inheritance
All Implemented Interfaces
javax.xml.namespace.NamespaceContext, javax.xml.stream.XMLStreamReader, javax.xml.stream.XMLStreamConstants
Imports
org.w3c.dom.Attr, .Element, .NamedNodeMap, .Node, .ProcessingInstruction, .Text, javax.xml.namespace.NamespaceContext, .QName, javax.xml.stream.Location, .XMLStreamException, .XMLStreamReader, java.util.Collections, .Iterator

Create an XMLStreamReader on top of a DOM tree.

Since various libraries as well as users often create "incorrect" DOM node, this class spends a lot of efforts making sure that broken DOM trees are nevertheless interpreted correctly.

For example, if a DOM level 1 tree is passed, each method will attempt to return the correct value by using Node#getNodeName().

Similarly, if DOM is missing explicit namespace declarations, this class attempts to emulate necessary declarations.

Authors
[email protected], Kohsuke Kawaguchi

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
DOMStreamReader.Scope

Namespace declarations on one element.

Field Summary

Modifier and TypeField and Description
protected Node
_current

Current DOM node being traversed.

private final FinalArrayList<Attr>
_currentAttributes

List of attributes extracted from _namedNodeMap.

private NamedNodeMap
_namedNodeMap

Named mapping for attributes and NS decls for the current node.

private Node
_start

Starting node of the subtree being traversed.

protected int
_state

State of this reader.

protected int
depth

Depth of the current element.

protected DOMStreamReader.Scope[]
scopes

Scope buffer.

protected String
wholeText

If the reader points at the text node, its whole value.

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected int
private DOMStreamReader.Scope
public void
close()

Implements javax.xml.stream.XMLStreamReader.close.

Frees any resources associated with this Reader.

private void
ensureNs(Node n)

Sub-routine of splitAttributes().

private Node
findRootElement()

Finds the root element node of the traversal.

private static String
public int
getAttributeCount()

Implements javax.xml.stream.XMLStreamReader.getAttributeCount.

Returns the count of attributes on this START_ELEMENT, this method is only valid on a START_ELEMENT or ATTRIBUTE.

public String
getAttributeLocalName(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributeLocalName.

Return an attribute's local name.Handle the case of DOM level 1 nodes.

public QName
getAttributeName(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributeName.

Return an attribute's qname.

public String
getAttributeNamespace(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributeNamespace.

Returns the namespace of the attribute at the provided index

public String
getAttributePrefix(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributePrefix.

Returns the prefix of this attribute at the provided index

public String
getAttributeType(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributeType.

Returns the XML type of the attribute at the provided index

public String
getAttributeValue(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributeValue.

Returns the value of the attribute at the index

public String
getAttributeValue(String namespaceURI, String localName)

Implements javax.xml.stream.XMLStreamReader.getAttributeValue.

Returns the normalized attribute value of the attribute with the namespace and localName If the namespaceURI is null the namespace is not checked for equality

public String
getCharacterEncodingScheme()

Implements javax.xml.stream.XMLStreamReader.getCharacterEncodingScheme.

Returns the character encoding declared on the xml declaration Returns null if none was declared

private DOMStreamReader.Scope
getCheckedScope()

Verifies the current state to see if we can return the scope, and do so if appropriate.

public String
getElementText()

Implements javax.xml.stream.XMLStreamReader.getElementText.

Reads the content of a text-only element, an exception is thrown if this is not a text-only element.

public String
getEncoding()

Implements javax.xml.stream.XMLStreamReader.getEncoding.

Return input encoding if known or null if unknown.

public int
getEventType()

Implements javax.xml.stream.XMLStreamReader.getEventType.

Returns an integer code that indicates the type of the event the cursor is pointing to.

public String
getLocalName()

Implements javax.xml.stream.XMLStreamReader.getLocalName.

Return an element's local name.Handle the case of DOM level 1 nodes.

public Location
getLocation()

Implements javax.xml.stream.XMLStreamReader.getLocation.

Return the current location of the processor.

public QName
getName()

Implements javax.xml.stream.XMLStreamReader.getName.

Return an element's qname.

public NamespaceContext
getNamespaceContext()

Implements javax.xml.stream.XMLStreamReader.getNamespaceContext.

Returns a read only namespace context for the current position.

public int
getNamespaceCount()

Implements javax.xml.stream.XMLStreamReader.getNamespaceCount.

Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT, this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE.

public String
getNamespacePrefix(int index)

Implements javax.xml.stream.XMLStreamReader.getNamespacePrefix.

Returns the prefix for the namespace declared at the index.

public String
getNamespaceURI(int index)

Implements javax.xml.stream.XMLStreamReader.getNamespaceURI.

Returns the uri for the namespace declared at the index.

public String
getNamespaceURI()

Implements javax.xml.stream.XMLStreamReader.getNamespaceURI.

If the current event is a START_ELEMENT or END_ELEMENT this method returns the URI of the prefix or the default namespace.

public String
getNamespaceURI(String prefix)

Implements javax.xml.stream.XMLStreamReader.getNamespaceURI, javax.xml.namespace.NamespaceContext.getNamespaceURI.

This method is not particularly fast, but shouldn't be called very often.If we start to use it more, we should keep track of the NS declarations using a NamespaceContext implementation instead.

public String
getPIData()

Implements javax.xml.stream.XMLStreamReader.getPIData.

Get the data section of a processing instruction

public String
getPITarget()

Implements javax.xml.stream.XMLStreamReader.getPITarget.

Get the target of a processing instruction

public String
getPrefix(String nsUri)

Implements javax.xml.namespace.NamespaceContext.getPrefix.

Get prefix bound to Namespace URI in the current scope.

public String
getPrefix()

Implements javax.xml.stream.XMLStreamReader.getPrefix.

Returns the prefix of the current event or null if the event does not have a prefix

public Iterator<String>
getPrefixes(String nsUri)

Implements javax.xml.namespace.NamespaceContext.getPrefixes.

Get all prefixes bound to a Namespace URI in the current scope.

private static String
getPrefixForAttr(Attr attr, String nsUri)

If the given attribute is a namespace declaration for the given namespace URI, return its prefix.

public Object
getProperty(String str)

Implements javax.xml.stream.XMLStreamReader.getProperty.

Get the value of a feature/property from the underlying implementation

public String
getText()

Implements javax.xml.stream.XMLStreamReader.getText.

Returns the current value of the parse event as a string, this returns the string value of a CHARACTERS event, returns the value of a COMMENT, the replacement value for an ENTITY_REFERENCE, the string value of a CDATA section, the string value for a SPACE event, or the String value of the internal subset of the DTD.

public char[]
getTextCharacters()

Implements javax.xml.stream.XMLStreamReader.getTextCharacters.

Returns an array which contains the characters from this event.

public int
getTextCharacters(int sourceStart, char[] target, int targetStart, int targetLength)

Implements javax.xml.stream.XMLStreamReader.getTextCharacters.

Gets the text associated with a CHARACTERS, SPACE or CDATA event.

public int
getTextLength()

Implements javax.xml.stream.XMLStreamReader.getTextLength.

Returns the length of the sequence of characters for this Text event within the text character array.

public int
getTextStart()

Implements javax.xml.stream.XMLStreamReader.getTextStart.

Returns the offset into the text character array where the first character (of this text event) is stored.

public String
getVersion()

Implements javax.xml.stream.XMLStreamReader.getVersion.

Get the xml version declared on the xml declaration Returns null if none was declared

public boolean
hasName()

Implements javax.xml.stream.XMLStreamReader.hasName.

returns a boolean indicating whether the current event has a name (is a START_ELEMENT or END_ELEMENT).

public boolean
hasNext()

Implements javax.xml.stream.XMLStreamReader.hasNext.

Returns true if there are more parsing events and false if there are no more events.

public boolean
hasText()

Implements javax.xml.stream.XMLStreamReader.hasText.

Return a boolean indicating whether the current event has text.

public boolean
isAttributeSpecified(int param)

Implements javax.xml.stream.XMLStreamReader.isAttributeSpecified.

Returns a boolean which indicates if this attribute was created by default

public boolean
isCharacters()

Implements javax.xml.stream.XMLStreamReader.isCharacters.

Returns true if the cursor points to a character data event

public boolean
isEndElement()

Implements javax.xml.stream.XMLStreamReader.isEndElement.

Returns true if the cursor points to an end tag (otherwise false)

public boolean
isStandalone()

Implements javax.xml.stream.XMLStreamReader.isStandalone.

Get the standalone declaration from the xml declaration

public boolean
isStartElement()

Implements javax.xml.stream.XMLStreamReader.isStartElement.

Returns true if the cursor points to a start tag (otherwise false)

public boolean
isWhiteSpace()

Implements javax.xml.stream.XMLStreamReader.isWhiteSpace.

Returns true if the cursor points to a character data event that consists of all whitespace

private static int
mapNodeTypeToState(int nodetype)

public int
next()

Implements javax.xml.stream.XMLStreamReader.next.

Get next parsing event - a processor may return all contiguous character data in a single chunk, or it may split it into several chunks.

public int
nextTag()

Implements javax.xml.stream.XMLStreamReader.nextTag.

Skips any white space (isWhiteSpace() returns true), COMMENT, or PROCESSING_INSTRUCTION, until a START_ELEMENT or END_ELEMENT is reached.

public void
require(int type, String namespaceURI, String localName)

Implements javax.xml.stream.XMLStreamReader.require.

Test if the current event is of the given type and if the namespace and name match the current namespace and name of the current event.

public void
protected void
splitAttributes()

Called when the current node is Element to look at attribute list (which contains both ns decl and attributes in DOM) and split them to attributes-proper and namespace decls.

public boolean
standaloneSet()

Implements javax.xml.stream.XMLStreamReader.standaloneSet.

Checks if standalone was set in the document

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait