public class DOMStreamReader extends Object implements javax.xml.stream.XMLStreamReader, NamespaceContext
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.
Modifier and Type | Class and Description |
---|---|
protected static class |
DOMStreamReader.Scope
Namespace declarations on one element.
|
Modifier and Type | Field and Description |
---|---|
protected Node |
_current
Current DOM node being traversed.
|
protected int |
_state
State of this reader.
|
protected int |
depth
Depth of the current element.
|
protected DOMStreamReader.Scope[] |
scopes
DOMStreamReader.Scope buffer. |
protected String |
wholeText
If the reader points at
the text node ,
its whole value. |
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
Constructor and Description |
---|
DOMStreamReader() |
DOMStreamReader(Node node) |
Modifier and Type | Method and Description |
---|---|
protected int |
_next() |
void |
close() |
int |
getAttributeCount() |
String |
getAttributeLocalName(int index)
Return an attribute's local name.
|
QName |
getAttributeName(int index)
Return an attribute's qname.
|
String |
getAttributeNamespace(int index) |
String |
getAttributePrefix(int index) |
String |
getAttributeType(int index) |
String |
getAttributeValue(int index) |
String |
getAttributeValue(String namespaceURI,
String localName) |
String |
getCharacterEncodingScheme() |
String |
getElementText() |
String |
getEncoding() |
int |
getEventType() |
String |
getLocalName()
Return an element's local name.
|
javax.xml.stream.Location |
getLocation() |
QName |
getName()
Return an element's qname.
|
NamespaceContext |
getNamespaceContext() |
int |
getNamespaceCount() |
String |
getNamespacePrefix(int index) |
String |
getNamespaceURI() |
String |
getNamespaceURI(int index) |
String |
getNamespaceURI(String prefix)
This method is not particularly fast, but shouldn't be called very
often.
|
String |
getPIData() |
String |
getPITarget() |
String |
getPrefix() |
String |
getPrefix(String nsUri) |
Iterator |
getPrefixes(String nsUri) |
Object |
getProperty(String str) |
String |
getText() |
char[] |
getTextCharacters() |
int |
getTextCharacters(int sourceStart,
char[] target,
int targetStart,
int targetLength) |
int |
getTextLength() |
int |
getTextStart() |
String |
getVersion() |
boolean |
hasName() |
boolean |
hasNext() |
boolean |
hasText() |
boolean |
isAttributeSpecified(int param) |
boolean |
isCharacters() |
boolean |
isEndElement() |
boolean |
isStandalone() |
boolean |
isStartElement() |
boolean |
isWhiteSpace() |
int |
next() |
int |
nextTag() |
void |
require(int type,
String namespaceURI,
String localName) |
void |
setCurrentNode(Node node) |
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. |
boolean |
standaloneSet() |
protected Node _current
protected String wholeText
the 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.
protected DOMStreamReader.Scope[] scopes
DOMStreamReader.Scope
buffer.protected int depth
scopes
.protected int _state
public DOMStreamReader()
public DOMStreamReader(Node node)
public void setCurrentNode(Node node)
public void close() throws javax.xml.stream.XMLStreamException
close
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
protected void splitAttributes()
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 int getAttributeCount()
getAttributeCount
in interface javax.xml.stream.XMLStreamReader
public String getAttributeLocalName(int index)
getAttributeLocalName
in interface javax.xml.stream.XMLStreamReader
public QName getAttributeName(int index)
getAttributeName
in interface javax.xml.stream.XMLStreamReader
public String getAttributeNamespace(int index)
getAttributeNamespace
in interface javax.xml.stream.XMLStreamReader
public String getAttributePrefix(int index)
getAttributePrefix
in interface javax.xml.stream.XMLStreamReader
public String getAttributeType(int index)
getAttributeType
in interface javax.xml.stream.XMLStreamReader
public String getAttributeValue(int index)
getAttributeValue
in interface javax.xml.stream.XMLStreamReader
public String getAttributeValue(String namespaceURI, String localName)
getAttributeValue
in interface javax.xml.stream.XMLStreamReader
public String getCharacterEncodingScheme()
getCharacterEncodingScheme
in interface javax.xml.stream.XMLStreamReader
public String getElementText() throws javax.xml.stream.XMLStreamException
getElementText
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
public String getEncoding()
getEncoding
in interface javax.xml.stream.XMLStreamReader
public int getEventType()
getEventType
in interface javax.xml.stream.XMLStreamReader
public String getLocalName()
getLocalName
in interface javax.xml.stream.XMLStreamReader
public javax.xml.stream.Location getLocation()
getLocation
in interface javax.xml.stream.XMLStreamReader
public QName getName()
getName
in interface javax.xml.stream.XMLStreamReader
public NamespaceContext getNamespaceContext()
getNamespaceContext
in interface javax.xml.stream.XMLStreamReader
public int getNamespaceCount()
getNamespaceCount
in interface javax.xml.stream.XMLStreamReader
public String getNamespacePrefix(int index)
getNamespacePrefix
in interface javax.xml.stream.XMLStreamReader
public String getNamespaceURI(int index)
getNamespaceURI
in interface javax.xml.stream.XMLStreamReader
public String getNamespaceURI()
getNamespaceURI
in interface javax.xml.stream.XMLStreamReader
public String getNamespaceURI(String prefix)
getNamespaceURI
in interface NamespaceContext
getNamespaceURI
in interface javax.xml.stream.XMLStreamReader
public String getPrefix(String nsUri)
getPrefix
in interface NamespaceContext
public Iterator getPrefixes(String nsUri)
getPrefixes
in interface NamespaceContext
public String getPIData()
getPIData
in interface javax.xml.stream.XMLStreamReader
public String getPITarget()
getPITarget
in interface javax.xml.stream.XMLStreamReader
public String getPrefix()
getPrefix
in interface javax.xml.stream.XMLStreamReader
public Object getProperty(String str) throws IllegalArgumentException
getProperty
in interface javax.xml.stream.XMLStreamReader
IllegalArgumentException
public String getText()
getText
in interface javax.xml.stream.XMLStreamReader
public char[] getTextCharacters()
getTextCharacters
in interface javax.xml.stream.XMLStreamReader
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int targetLength) throws javax.xml.stream.XMLStreamException
getTextCharacters
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
public int getTextLength()
getTextLength
in interface javax.xml.stream.XMLStreamReader
public int getTextStart()
getTextStart
in interface javax.xml.stream.XMLStreamReader
public String getVersion()
getVersion
in interface javax.xml.stream.XMLStreamReader
public boolean hasName()
hasName
in interface javax.xml.stream.XMLStreamReader
public boolean hasNext() throws javax.xml.stream.XMLStreamException
hasNext
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
public boolean hasText()
hasText
in interface javax.xml.stream.XMLStreamReader
public boolean isAttributeSpecified(int param)
isAttributeSpecified
in interface javax.xml.stream.XMLStreamReader
public boolean isCharacters()
isCharacters
in interface javax.xml.stream.XMLStreamReader
public boolean isEndElement()
isEndElement
in interface javax.xml.stream.XMLStreamReader
public boolean isStandalone()
isStandalone
in interface javax.xml.stream.XMLStreamReader
public boolean isStartElement()
isStartElement
in interface javax.xml.stream.XMLStreamReader
public boolean isWhiteSpace()
isWhiteSpace
in interface javax.xml.stream.XMLStreamReader
public int next() throws javax.xml.stream.XMLStreamException
next
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
protected int _next() throws javax.xml.stream.XMLStreamException
public int nextTag() throws javax.xml.stream.XMLStreamException
nextTag
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
public void require(int type, String namespaceURI, String localName) throws javax.xml.stream.XMLStreamException
require
in interface javax.xml.stream.XMLStreamReader
javax.xml.stream.XMLStreamException
public boolean standaloneSet()
standaloneSet
in interface javax.xml.stream.XMLStreamReader
Copyright © 2006–2020. All rights reserved.