Package org.jvnet.staxex.util
Class DOMStreamReader
java.lang.Object
org.jvnet.staxex.util.DOMStreamReader
- All Implemented Interfaces:
NamespaceContext,XMLStreamConstants,XMLStreamReader
- Direct Known Subclasses:
LazyEnvelopeStaxReader,SaajStaxReaderEx
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.
- Author:
- Santiago.PericasGeertsen@sun.com, Kohsuke Kawaguchi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classNamespace declarations on one element. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected NodeCurrent DOM node being traversed.protected intState of this reader.protected intDepth of the current element.protected DOMStreamReader.Scope[]DOMStreamReader.Scopebuffer.protected StringIf the reader points atthe text node, its whole value.Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int_next()voidclose()intgetAttributeLocalName(int index) Return an attribute's local name.getAttributeName(int index) Return an attribute's qname.getAttributeNamespace(int index) getAttributePrefix(int index) getAttributeType(int index) getAttributeValue(int index) getAttributeValue(String namespaceURI, String localName) intReturn an element's local name.getName()Return an element's qname.intgetNamespacePrefix(int index) getNamespaceURI(int index) getNamespaceURI(String prefix) This method is not particularly fast, but shouldn't be called very often.getPrefixes(String nsUri) getProperty(String str) getText()char[]intgetTextCharacters(int sourceStart, char[] target, int targetStart, int targetLength) intintbooleanhasName()booleanhasNext()booleanhasText()booleanisAttributeSpecified(int param) booleanbooleanbooleanbooleanbooleanintnext()intnextTag()voidvoidsetCurrentNode(Node node) protected voidCalled when the current node isElementto look at attribute list (which contains both ns decl and attributes in DOM) and split them to attributes-proper and namespace decls.boolean
-
Field Details
-
_current
Current DOM node being traversed. -
wholeText
If the reader points atthe text node, its whole value.This is simply a cache of
Text.getWholeText()of_current, but when a large binary data sent as base64 text, this could get very much non-trivial. -
scopes
DOMStreamReader.Scopebuffer. -
depth
protected int depthDepth of the current element. The first element gets depth==0. Also used as the index toscopes. -
_state
protected int _stateState of this reader. Any of the valid states defined in StAX' XMLStreamConstants class.
-
-
Constructor Details
-
DOMStreamReader
public DOMStreamReader() -
DOMStreamReader
-
-
Method Details
-
setCurrentNode
-
close
- Specified by:
closein interfaceXMLStreamReader- Throws:
XMLStreamException
-
splitAttributes
protected void splitAttributes()Called when the current node isElementto look at attribute list (which contains both ns decl and attributes in DOM) and split them to attributes-proper and namespace decls. -
getAttributeCount
public int getAttributeCount()- Specified by:
getAttributeCountin interfaceXMLStreamReader
-
getAttributeLocalName
Return an attribute's local name. Handle the case of DOM level 1 nodes.- Specified by:
getAttributeLocalNamein interfaceXMLStreamReader
-
getAttributeName
Return an attribute's qname. Handle the case of DOM level 1 nodes.- Specified by:
getAttributeNamein interfaceXMLStreamReader
-
getAttributeNamespace
- Specified by:
getAttributeNamespacein interfaceXMLStreamReader
-
getAttributePrefix
- Specified by:
getAttributePrefixin interfaceXMLStreamReader
-
getAttributeType
- Specified by:
getAttributeTypein interfaceXMLStreamReader
-
getAttributeValue
- Specified by:
getAttributeValuein interfaceXMLStreamReader
-
getAttributeValue
- Specified by:
getAttributeValuein interfaceXMLStreamReader
-
getCharacterEncodingScheme
- Specified by:
getCharacterEncodingSchemein interfaceXMLStreamReader
-
getElementText
- Specified by:
getElementTextin interfaceXMLStreamReader- Throws:
XMLStreamException
-
getEncoding
- Specified by:
getEncodingin interfaceXMLStreamReader
-
getEventType
public int getEventType()- Specified by:
getEventTypein interfaceXMLStreamReader
-
getLocalName
Return an element's local name. Handle the case of DOM level 1 nodes.- Specified by:
getLocalNamein interfaceXMLStreamReader
-
getLocation
- Specified by:
getLocationin interfaceXMLStreamReader
-
getName
Return an element's qname. Handle the case of DOM level 1 nodes.- Specified by:
getNamein interfaceXMLStreamReader
-
getNamespaceContext
- Specified by:
getNamespaceContextin interfaceXMLStreamReader
-
getNamespaceCount
public int getNamespaceCount()- Specified by:
getNamespaceCountin interfaceXMLStreamReader
-
getNamespacePrefix
- Specified by:
getNamespacePrefixin interfaceXMLStreamReader
-
getNamespaceURI
- Specified by:
getNamespaceURIin interfaceXMLStreamReader
-
getNamespaceURI
- Specified by:
getNamespaceURIin interfaceXMLStreamReader
-
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.- Specified by:
getNamespaceURIin interfaceNamespaceContext- Specified by:
getNamespaceURIin interfaceXMLStreamReader
-
getPrefix
- Specified by:
getPrefixin interfaceNamespaceContext
-
getPrefixes
- Specified by:
getPrefixesin interfaceNamespaceContext
-
getPIData
- Specified by:
getPIDatain interfaceXMLStreamReader
-
getPITarget
- Specified by:
getPITargetin interfaceXMLStreamReader
-
getPrefix
- Specified by:
getPrefixin interfaceXMLStreamReader
-
getProperty
- Specified by:
getPropertyin interfaceXMLStreamReader- Throws:
IllegalArgumentException
-
getText
- Specified by:
getTextin interfaceXMLStreamReader
-
getTextCharacters
public char[] getTextCharacters()- Specified by:
getTextCharactersin interfaceXMLStreamReader
-
getTextCharacters
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int targetLength) throws XMLStreamException - Specified by:
getTextCharactersin interfaceXMLStreamReader- Throws:
XMLStreamException
-
getTextLength
public int getTextLength()- Specified by:
getTextLengthin interfaceXMLStreamReader
-
getTextStart
public int getTextStart()- Specified by:
getTextStartin interfaceXMLStreamReader
-
getVersion
- Specified by:
getVersionin interfaceXMLStreamReader
-
hasName
public boolean hasName()- Specified by:
hasNamein interfaceXMLStreamReader
-
hasNext
- Specified by:
hasNextin interfaceXMLStreamReader- Throws:
XMLStreamException
-
hasText
public boolean hasText()- Specified by:
hasTextin interfaceXMLStreamReader
-
isAttributeSpecified
public boolean isAttributeSpecified(int param) - Specified by:
isAttributeSpecifiedin interfaceXMLStreamReader
-
isCharacters
public boolean isCharacters()- Specified by:
isCharactersin interfaceXMLStreamReader
-
isEndElement
public boolean isEndElement()- Specified by:
isEndElementin interfaceXMLStreamReader
-
isStandalone
public boolean isStandalone()- Specified by:
isStandalonein interfaceXMLStreamReader
-
isStartElement
public boolean isStartElement()- Specified by:
isStartElementin interfaceXMLStreamReader
-
isWhiteSpace
public boolean isWhiteSpace()- Specified by:
isWhiteSpacein interfaceXMLStreamReader
-
next
- Specified by:
nextin interfaceXMLStreamReader- Throws:
XMLStreamException
-
_next
- Throws:
XMLStreamException
-
nextTag
- Specified by:
nextTagin interfaceXMLStreamReader- Throws:
XMLStreamException
-
require
- Specified by:
requirein interfaceXMLStreamReader- Throws:
XMLStreamException
-
standaloneSet
public boolean standaloneSet()- Specified by:
standaloneSetin interfaceXMLStreamReader
-