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
public class DOMStreamReader extends Object implements XMLStreamReader, NamespaceContext
Create anXMLStreamReaderon 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 Classes Modifier and Type Class Description protected static classDOMStreamReader.ScopeNamespace declarations on one element.
-
Field Summary
Fields Modifier and Type Field Description protected Node_currentCurrent DOM node being traversed.protected int_stateState of this reader.protected intdepthDepth of the current element.protected DOMStreamReader.Scope[]scopesDOMStreamReader.Scopebuffer.protected StringwholeTextIf 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 Constructor Description DOMStreamReader()DOMStreamReader(Node node)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int_next()voidclose()intgetAttributeCount()StringgetAttributeLocalName(int index)Return an attribute's local name.QNamegetAttributeName(int index)Return an attribute's qname.StringgetAttributeNamespace(int index)StringgetAttributePrefix(int index)StringgetAttributeType(int index)StringgetAttributeValue(int index)StringgetAttributeValue(String namespaceURI, String localName)StringgetCharacterEncodingScheme()StringgetElementText()StringgetEncoding()intgetEventType()StringgetLocalName()Return an element's local name.LocationgetLocation()QNamegetName()Return an element's qname.NamespaceContextgetNamespaceContext()intgetNamespaceCount()StringgetNamespacePrefix(int index)StringgetNamespaceURI()StringgetNamespaceURI(int index)StringgetNamespaceURI(String prefix)This method is not particularly fast, but shouldn't be called very often.StringgetPIData()StringgetPITarget()StringgetPrefix()StringgetPrefix(String nsUri)IteratorgetPrefixes(String nsUri)ObjectgetProperty(String str)StringgetText()char[]getTextCharacters()intgetTextCharacters(int sourceStart, char[] target, int targetStart, int targetLength)intgetTextLength()intgetTextStart()StringgetVersion()booleanhasName()booleanhasNext()booleanhasText()booleanisAttributeSpecified(int param)booleanisCharacters()booleanisEndElement()booleanisStandalone()booleanisStartElement()booleanisWhiteSpace()intnext()intnextTag()voidrequire(int type, String namespaceURI, String localName)voidsetCurrentNode(Node node)protected voidsplitAttributes()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.booleanstandaloneSet()
-
-
-
Field Detail
-
_current
protected Node _current
Current DOM node being traversed.
-
wholeText
protected String 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
protected DOMStreamReader.Scope[] scopes
DOMStreamReader.Scopebuffer.
-
depth
protected int depth
Depth of the current element. The first element gets depth==0. Also used as the index toscopes.
-
_state
protected int _state
State of this reader. Any of the valid states defined in StAX' XMLStreamConstants class.
-
-
Constructor Detail
-
DOMStreamReader
public DOMStreamReader()
-
DOMStreamReader
public DOMStreamReader(Node node)
-
-
Method Detail
-
setCurrentNode
public void setCurrentNode(Node node)
-
close
public void close() throws XMLStreamException- 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
public String getAttributeLocalName(int index)
Return an attribute's local name. Handle the case of DOM level 1 nodes.- Specified by:
getAttributeLocalNamein interfaceXMLStreamReader
-
getAttributeName
public QName getAttributeName(int index)
Return an attribute's qname. Handle the case of DOM level 1 nodes.- Specified by:
getAttributeNamein interfaceXMLStreamReader
-
getAttributeNamespace
public String getAttributeNamespace(int index)
- Specified by:
getAttributeNamespacein interfaceXMLStreamReader
-
getAttributePrefix
public String getAttributePrefix(int index)
- Specified by:
getAttributePrefixin interfaceXMLStreamReader
-
getAttributeType
public String getAttributeType(int index)
- Specified by:
getAttributeTypein interfaceXMLStreamReader
-
getAttributeValue
public String getAttributeValue(int index)
- Specified by:
getAttributeValuein interfaceXMLStreamReader
-
getAttributeValue
public String getAttributeValue(String namespaceURI, String localName)
- Specified by:
getAttributeValuein interfaceXMLStreamReader
-
getCharacterEncodingScheme
public String getCharacterEncodingScheme()
- Specified by:
getCharacterEncodingSchemein interfaceXMLStreamReader
-
getElementText
public String getElementText() throws XMLStreamException
- Specified by:
getElementTextin interfaceXMLStreamReader- Throws:
XMLStreamException
-
getEncoding
public String getEncoding()
- Specified by:
getEncodingin interfaceXMLStreamReader
-
getEventType
public int getEventType()
- Specified by:
getEventTypein interfaceXMLStreamReader
-
getLocalName
public String getLocalName()
Return an element's local name. Handle the case of DOM level 1 nodes.- Specified by:
getLocalNamein interfaceXMLStreamReader
-
getLocation
public Location getLocation()
- Specified by:
getLocationin interfaceXMLStreamReader
-
getName
public QName getName()
Return an element's qname. Handle the case of DOM level 1 nodes.- Specified by:
getNamein interfaceXMLStreamReader
-
getNamespaceContext
public NamespaceContext getNamespaceContext()
- Specified by:
getNamespaceContextin interfaceXMLStreamReader
-
getNamespaceCount
public int getNamespaceCount()
- Specified by:
getNamespaceCountin interfaceXMLStreamReader
-
getNamespacePrefix
public String getNamespacePrefix(int index)
- Specified by:
getNamespacePrefixin interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI(int index)
- Specified by:
getNamespaceURIin interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI()
- Specified by:
getNamespaceURIin interfaceXMLStreamReader
-
getNamespaceURI
public String getNamespaceURI(String prefix)
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
public String getPrefix(String nsUri)
- Specified by:
getPrefixin interfaceNamespaceContext
-
getPrefixes
public Iterator getPrefixes(String nsUri)
- Specified by:
getPrefixesin interfaceNamespaceContext
-
getPIData
public String getPIData()
- Specified by:
getPIDatain interfaceXMLStreamReader
-
getPITarget
public String getPITarget()
- Specified by:
getPITargetin interfaceXMLStreamReader
-
getPrefix
public String getPrefix()
- Specified by:
getPrefixin interfaceXMLStreamReader
-
getProperty
public Object getProperty(String str) throws IllegalArgumentException
- Specified by:
getPropertyin interfaceXMLStreamReader- Throws:
IllegalArgumentException
-
getText
public String 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
public String getVersion()
- Specified by:
getVersionin interfaceXMLStreamReader
-
hasName
public boolean hasName()
- Specified by:
hasNamein interfaceXMLStreamReader
-
hasNext
public boolean hasNext() throws XMLStreamException- 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
public int next() throws XMLStreamException- Specified by:
nextin interfaceXMLStreamReader- Throws:
XMLStreamException
-
_next
protected int _next() throws XMLStreamException- Throws:
XMLStreamException
-
nextTag
public int nextTag() throws XMLStreamException- Specified by:
nextTagin interfaceXMLStreamReader- Throws:
XMLStreamException
-
require
public void require(int type, String namespaceURI, String localName) throws XMLStreamException- Specified by:
requirein interfaceXMLStreamReader- Throws:
XMLStreamException
-
standaloneSet
public boolean standaloneSet()
- Specified by:
standaloneSetin interfaceXMLStreamReader
-
-