public abstract class DOMWrappingReader extends Object implements XMLStreamReader2, AttributeInfo, DTDInfo, LocationInfo, NamespaceContext, XMLStreamConstants
XMLStreamReader
. This is mostly useful for
inter-operability purposes, and should only be used when the
input has to come as a DOM object and the original xml content
is not available as a stream.
Note that the implementation is only to be used for use with
javax.xml.transform.dom.DOMSource
. It can however be
used for both full documents, and single element root fragments,
depending on what node is passed as the argument.
Some notes regarding missing/incomplete functionality:
Modifier and Type | Field and Description |
---|---|
protected List |
_attrList
Lazily instantiated List of all actual attributes for the
current (start) element, NOT including namespace declarations.
|
protected StringBase64Decoder |
_base64Decoder
Lazily-constructed decoder object for decoding base64 encoded
binary content.
|
protected boolean |
_cfgInternNames
By default we do not force interning of names: can be
reset by sub-classes.
|
protected boolean |
_cfgInternNsURIs
By default we do not force interning of namespace URIs: can be
reset by sub-classes.
|
protected boolean |
_cfgNsAware
Whether stream reader is to be namespace aware (as per property
XMLInputFactory.IS_NAMESPACE_AWARE ) or not |
protected String |
_coalescedText
In coalescing mode, we may need to combine textual content
from multiple adjacent nodes.
|
protected boolean |
_coalescing
Whether stream reader is to coalesce adjacent textual
(CHARACTERS, SPACE, CDATA) events (as per property
XMLInputFactory.IS_COALESCING ) or not |
protected int |
_currEvent |
protected Node |
_currNode
Current node is the DOM node that contains information
regarding the current event.
|
protected ValueDecoderFactory |
_decoderFactory
Factory used for constructing decoders we need for typed access
|
protected int |
_depth |
protected List |
_nsDeclList
Lazily instantiated String pairs of all namespace declarations for the
current (start/end) element.
|
protected Node |
_rootNode |
protected String |
_systemId |
protected Stax2Util.TextBuffer |
_textBuffer
Helper object used for combining segments of text as needed
|
protected static int |
ERR_STATE_NO_LOCALNAME |
protected static int |
ERR_STATE_NOT_ELEM
Current state not START_ELEMENT or END_ELEMENT, should be
|
protected static int |
ERR_STATE_NOT_PI
Current state not PROCESSING_INSTRUCTION
|
protected static int |
ERR_STATE_NOT_START_ELEM
Current state not START_ELEMENT, should be
|
protected static int |
ERR_STATE_NOT_TEXTUAL
Current state not one where getText() can be used
|
protected static int |
ERR_STATE_NOT_TEXTUAL_OR_ELEM |
protected static int |
ERR_STATE_NOT_TEXTUAL_XXX
Current state not one where getTextXxx() can be used
|
protected static int |
INT_SPACE |
protected static int |
MASK_TYPED_ACCESS_BINARY |
FEATURE_DTD_OVERRIDE
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
Modifier | Constructor and Description |
---|---|
protected |
DOMWrappingReader(DOMSource src,
boolean nsAware,
boolean coalescing) |
Modifier and Type | Method and Description |
---|---|
protected StringBase64Decoder |
_base64Decoder() |
protected TypedXMLStreamException |
_constructTypeException(IllegalArgumentException iae,
String lexicalValue)
Method called to wrap or convert given conversion-fail exception
into a full
TypedXMLStreamException , |
protected TypedXMLStreamException |
_constructTypeException(String msg,
String lexicalValue) |
protected ValueDecoderFactory |
_decoderFactory() |
protected int |
_getAttributeAsArray(TypedArrayDecoder tad,
String attrValue) |
protected String |
_internName(String name)
Method called to do additional intern()ing for a name, if and as
necessary
|
protected String |
_internNsURI(String uri) |
void |
close()
Note: as per StAX 1.0 specs, this method does NOT close the underlying
input reader.
|
void |
closeCompletely()
Method similar to
XMLStreamReader.close() ,
except that this method also does close the underlying input
source if it has not yet been closed. |
protected void |
coalesceText(int initialType) |
int |
findAttributeIndex(String nsURI,
String localName) |
protected String |
findErrorDesc(int errorType,
int currEvent)
Method used to locate error message description to use.
|
void |
getAttributeAs(int index,
TypedValueDecoder tvd)
Generic access method that can be used for efficient
decoding of additional types not support natively
by the typed stream reader.
|
int |
getAttributeAsArray(int index,
TypedArrayDecoder tad)
Method that allows reading contents of an attribute as an array
of whitespace-separate tokens, decoded using specified decoder.
|
byte[] |
getAttributeAsBinary(int index)
Read an attribute value as a byte array.
|
byte[] |
getAttributeAsBinary(int index,
Base64Variant v) |
boolean |
getAttributeAsBoolean(int index)
Read an attribute value as a boolean.
|
BigDecimal |
getAttributeAsDecimal(int index) |
double |
getAttributeAsDouble(int index) |
double[] |
getAttributeAsDoubleArray(int index) |
float |
getAttributeAsFloat(int index) |
float[] |
getAttributeAsFloatArray(int index) |
int |
getAttributeAsInt(int index)
Read an attribute value as a boolean.
|
int[] |
getAttributeAsIntArray(int index)
Read an attribute content as an int array.
|
BigInteger |
getAttributeAsInteger(int index) |
long |
getAttributeAsLong(int index)
Read an attribute value as a boolean.
|
long[] |
getAttributeAsLongArray(int index) |
QName |
getAttributeAsQName(int index) |
int |
getAttributeCount() |
int |
getAttributeIndex(String namespaceURI,
String localName)
Returns the index of the attribute whose local name is
localName and URI is namespaceURI
or -1 if no such attribute exists. |
AttributeInfo |
getAttributeInfo()
Method that can be called to get additional information about
attributes related to the current start element, as well as
related DTD-based information if available.
|
String |
getAttributeLocalName(int index) |
QName |
getAttributeName(int index) |
String |
getAttributeNamespace(int index) |
String |
getAttributePrefix(int index) |
String |
getAttributeType(int index) |
String |
getAttributeValue(int index) |
String |
getAttributeValue(String nsURI,
String localName) |
String |
getCharacterEncodingScheme()
As per Stax (1.0) specs, needs to return whatever xml declaration
claimed encoding is, if any; or null if no xml declaration found.
|
XMLStreamLocation2 |
getCurrentLocation()
A method that returns the current location of the stream reader
at the input source.
|
int |
getDepth()
Method that returns the number of open elements in the stack; 0 when
the reader is in prolog/epilog, 1 inside root element (including
when pointing at the root element itself) and so on.
|
DTDInfo |
getDTDInfo()
Since this class implements
DTDInfo , method can just
return this . |
String |
getDTDInternalSubset() |
String |
getDTDPublicId() |
String |
getDTDRootName() |
String |
getDTDSystemId() |
void |
getElementAs(TypedValueDecoder tvd)
Generic decoding method that can be used for efficient
decoding of additional types not support natively
by the typed stream reader.
|
byte[] |
getElementAsBinary()
Convenience method that can be used similar to read binary content
instead of
TypedXMLStreamReader.readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant) , in cases where neither performance nor
memory usage is a big concern. |
byte[] |
getElementAsBinary(Base64Variant v)
Convenience method that can be used similar to read binary content
instead of
TypedXMLStreamReader.readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant) , in cases where neither performance nor
memory usage is a big concern. |
boolean |
getElementAsBoolean()
Read an element content as a boolean.
|
BigDecimal |
getElementAsDecimal() |
double |
getElementAsDouble()
Read an element content as a 64-bit floating point value.
|
float |
getElementAsFloat()
Read an element content as a 32-bit floating point value.
|
int |
getElementAsInt()
Read an element content as a 32-bit integer.
|
BigInteger |
getElementAsInteger() |
long |
getElementAsLong()
Read an element content as a 64-bit integer.
|
QName |
getElementAsQName() |
String |
getElementText()
From StAX specs:
Reads the content of a text-only element, an exception is thrown if
this is not a text-only element.
|
String |
getEncoding()
As per Stax (1.0) specs, needs to return whatever parser determined
the encoding was, if it was able to figure it out.
|
long |
getEndingByteOffset()
Method that can be used to get exact byte offset (number of bytes
read from the stream right before getting to this location) in the
stream that is pointed to by this reader, right after the end
of the current event.
|
long |
getEndingCharOffset()
Method that can be used to get exact character offset (number of chars
read from the stream right before getting to this location) in the
stream that is pointed to by this reader, right after the end
of the current event.
|
XMLStreamLocation2 |
getEndLocation()
An optional method that either returns the location object that points the
ending position of the current event, or null if implementation
does not keep track of it (some may return only start location; and
some no location at all).
|
protected Location |
getErrorLocation() |
int |
getEventType()
Returns type of the last event returned; or START_DOCUMENT before
any events has been explicitly returned.
|
Object |
getFeature(String name)
Method that can be used to get per-reader values; both generic
ones (names for which are defined as constants in this class),
and implementation dependant ones.
|
int |
getIdAttributeIndex()
Returns the index of the id attribute (attribute with any name,
type ID from DTD) of current (start) element, if any.
|
String |
getLocalName() |
Location |
getLocation() |
LocationInfo |
getLocationInfo()
Location information is always accessible, for this reader.
|
QName |
getName() |
NamespaceContext |
getNamespaceContext() |
int |
getNamespaceCount() |
String |
getNamespacePrefix(int index)
Alas, DOM does not expose any of information necessary for
determining actual declarations.
|
String |
getNamespaceURI() |
String |
getNamespaceURI(int index) |
String |
getNamespaceURI(String prefix) |
NamespaceContext |
getNonTransientNamespaceContext()
This method returns a namespace context object that contains
information identical to that returned by
XMLStreamReader.getNamespaceContext() ,
but one that is
not transient. |
int |
getNotationAttributeIndex()
Returns the index of the notation attribute (attribute with any name,
type NOTATION from DTD) of current (start) element, if any.
|
String |
getPIData() |
String |
getPITarget() |
String |
getPrefix() |
String |
getPrefix(String namespaceURI) |
String |
getPrefixedName()
This method returns "prefix-qualified" name of the current
element.
|
Iterator |
getPrefixes(String namespaceURI) |
Object |
getProcessedDTD() |
DTDValidationSchema |
getProcessedDTDSchema()
Method similar to
DTDInfo.getProcessedDTD() , but type-safe. |
abstract Object |
getProperty(String name) |
long |
getStartingByteOffset()
Method that can be used to get exact byte offset (number of bytes
read from the stream right before getting to this location) in the
stream that is pointed to by this reader, right before the start
of the current event.
|
long |
getStartingCharOffset()
Method that can be used to get exact character offset (number of chars
read from the stream right before getting to this location) in the
stream that is pointed to by this reader, right before the start
of the current event.
|
XMLStreamLocation2 |
getStartLocation()
An optional method that either returns the location object that points the
starting position of the current event, or null if implementation
does not keep track of it (some may return only end location; and
some no location at all).
|
String |
getText() |
int |
getText(Writer w,
boolean preserveContents)
Method similar to
getText() , except
that it just uses provided Writer to write all textual content. |
char[] |
getTextCharacters() |
int |
getTextCharacters(int sourceStart,
char[] target,
int targetStart,
int len) |
int |
getTextLength() |
int |
getTextStart() |
String |
getVersion() |
boolean |
hasName() |
boolean |
hasNext() |
boolean |
hasText() |
boolean |
isAttributeSpecified(int index) |
boolean |
isCharacters() |
boolean |
isEmptyElement()
Method that can be used to check whether current START_ELEMENT
event was created for an empty element (xml short-hand notation
where one tag implies start and end, ending with "/>"), or not.
|
boolean |
isEndElement() |
abstract boolean |
isPropertySupported(String name)
Method similar to
XMLInputFactory.isPropertySupported(java.lang.String) , used
to determine whether a property is supported by the Reader
instance. |
boolean |
isStandalone() |
boolean |
isStartElement() |
boolean |
isWhiteSpace() |
int |
next() |
int |
nextTag() |
int |
readElementAsArray(TypedArrayDecoder tad)
Read an element content as an array of tokens.
|
int |
readElementAsBinary(byte[] resultBuffer,
int offset,
int maxLength) |
int |
readElementAsBinary(byte[] resultBuffer,
int offset,
int maxLength,
Base64Variant v)
Read element content as decoded byte sequence; possibly only
reading a fragment of all element content.
|
int |
readElementAsDoubleArray(double[] value,
int from,
int length) |
int |
readElementAsFloatArray(float[] value,
int from,
int length) |
int |
readElementAsIntArray(int[] value,
int from,
int length)
Read an element content as an int array.
|
int |
readElementAsLongArray(long[] value,
int from,
int length) |
protected void |
reportParseProblem(int errorType) |
protected void |
reportWrongState(int errorType) |
void |
require(int type,
String nsUri,
String localName) |
void |
setFeature(String name,
Object value)
Method that can be used to set per-reader features such as configuration
settings; both generic
ones (names for which are defined as constants in this class),
and implementation dependant ones.
|
protected void |
setInternNames(boolean state) |
protected void |
setInternNsURIs(boolean state) |
abstract boolean |
setProperty(String name,
Object value)
Method that can be used to set per-reader properties; a subset of
properties one can set via matching
XMLInputFactory2
instance. |
ValidationProblemHandler |
setValidationProblemHandler(ValidationProblemHandler h)
Method that application can call to define a custom handler for
validation problems encountered during validation process.
|
void |
skipElement()
Method that will skip all the contents of the element that the
stream currently points to.
|
boolean |
standaloneSet() |
XMLValidator |
stopValidatingAgainst(XMLValidationSchema schema)
Method that can be called by application to stop validating
output against a schema, for which
Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema)
was called earlier. |
XMLValidator |
stopValidatingAgainst(XMLValidator validator)
Method that can be called by application to stop validating
output using specified validator.
|
protected void |
throwStreamException(String msg) |
protected abstract void |
throwStreamException(String msg,
Location loc) |
XMLValidator |
validateAgainst(XMLValidationSchema schema)
Method that will construct a
XMLValidator instance from the
given schema (unless a validator for that schema has already been
added),
initialize it if necessary, and make validatable object (reader,
writer)
call appropriate validation methods from this point on until the
end of the document (that is, it's not scoped with sub-trees), or until
validator is removed by an explicit call to
Validatable.stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema) . |
protected static final int INT_SPACE
protected static final int MASK_TYPED_ACCESS_BINARY
protected static final int ERR_STATE_NOT_START_ELEM
protected static final int ERR_STATE_NOT_ELEM
protected static final int ERR_STATE_NOT_PI
protected static final int ERR_STATE_NOT_TEXTUAL
protected static final int ERR_STATE_NOT_TEXTUAL_XXX
protected static final int ERR_STATE_NOT_TEXTUAL_OR_ELEM
protected static final int ERR_STATE_NO_LOCALNAME
protected final String _systemId
protected final Node _rootNode
protected final boolean _cfgNsAware
XMLInputFactory.IS_NAMESPACE_AWARE
) or notprotected final boolean _coalescing
XMLInputFactory.IS_COALESCING
) or notprotected boolean _cfgInternNames
protected boolean _cfgInternNsURIs
protected int _currEvent
protected Node _currNode
protected int _depth
protected String _coalescedText
protected Stax2Util.TextBuffer _textBuffer
protected List _attrList
Attr
instances.
protected List _nsDeclList
protected ValueDecoderFactory _decoderFactory
protected StringBase64Decoder _base64Decoder
protected DOMWrappingReader(DOMSource src, boolean nsAware, boolean coalescing) throws XMLStreamException
src
- Node that is the tree of the DOM document, or fragment.nsAware
- Whether resulting reader should operate in namespace
aware mode or not. Note that this should be compatible with
settings for the DOM builder that produced DOM tree or fragment
being operated on, otherwise results are not defined.coalescing
- Whether resulting reader should coalesce adjacent
text events or notXMLStreamException
protected void setInternNames(boolean state)
protected void setInternNsURIs(boolean state)
protected abstract void throwStreamException(String msg, Location loc) throws XMLStreamException
XMLStreamException
public String getCharacterEncodingScheme()
getCharacterEncodingScheme
in interface XMLStreamReader
public String getEncoding()
Reader
), it should return null.getEncoding
in interface XMLStreamReader
public String getVersion()
getVersion
in interface XMLStreamReader
public boolean isStandalone()
isStandalone
in interface XMLStreamReader
public boolean standaloneSet()
standaloneSet
in interface XMLStreamReader
public abstract Object getProperty(String name)
getProperty
in interface XMLStreamReader
public abstract boolean isPropertySupported(String name)
XMLStreamReader2
XMLInputFactory.isPropertySupported(java.lang.String)
, used
to determine whether a property is supported by the Reader
instance. This means that this method may return false
for some properties that the input factory does support: specifically,
it should only return true if the value is mutable on per-instance
basis. False means that either the property is not recognized, or
is not mutable via reader instance.isPropertySupported
in interface XMLStreamReader2
public abstract boolean setProperty(String name, Object value)
XMLStreamReader2
XMLInputFactory2
instance. Exactly which methods are mutable is implementation
specific.setProperty
in interface XMLStreamReader2
name
- Name of the property to setvalue
- Value to set property to.public int getAttributeCount()
getAttributeCount
in interface XMLStreamReader
getAttributeCount
in interface AttributeInfo
public String getAttributeLocalName(int index)
getAttributeLocalName
in interface XMLStreamReader
public QName getAttributeName(int index)
getAttributeName
in interface XMLStreamReader
public String getAttributeNamespace(int index)
getAttributeNamespace
in interface XMLStreamReader
public String getAttributePrefix(int index)
getAttributePrefix
in interface XMLStreamReader
public String getAttributeType(int index)
getAttributeType
in interface XMLStreamReader
public String getAttributeValue(int index)
getAttributeValue
in interface XMLStreamReader
public String getAttributeValue(String nsURI, String localName)
getAttributeValue
in interface XMLStreamReader
public String getElementText() throws XMLStreamException
Reads the content of a text-only element, an exception is thrown if this is not a text-only element. Regardless of value of javax.xml.stream.isCoalescing this method always returns coalesced content.
Precondition: the current event is START_ELEMENT.
Postcondition: the current event is the corresponding END_ELEMENT.
getElementText
in interface XMLStreamReader
XMLStreamException
public int getEventType()
getEventType
in interface XMLStreamReader
public String getLocalName()
getLocalName
in interface XMLStreamReader
public final Location getLocation()
getLocation
in interface XMLStreamReader
getLocation
in interface LocationInfo
public QName getName()
getName
in interface XMLStreamReader
public NamespaceContext getNamespaceContext()
getNamespaceContext
in interface XMLStreamReader
public int getNamespaceCount()
getNamespaceCount
in interface XMLStreamReader
public String getNamespacePrefix(int index)
getNamespacePrefix
in interface XMLStreamReader
public String getNamespaceURI()
getNamespaceURI
in interface XMLStreamReader
public String getNamespaceURI(int index)
getNamespaceURI
in interface XMLStreamReader
public String getPIData()
getPIData
in interface XMLStreamReader
public String getPITarget()
getPITarget
in interface XMLStreamReader
public String getPrefix()
getPrefix
in interface XMLStreamReader
public String getText()
getText
in interface XMLStreamReader
public char[] getTextCharacters()
getTextCharacters
in interface XMLStreamReader
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int len)
getTextCharacters
in interface XMLStreamReader
public int getTextLength()
getTextLength
in interface XMLStreamReader
public int getTextStart()
getTextStart
in interface XMLStreamReader
public boolean hasName()
hasName
in interface XMLStreamReader
public boolean hasNext()
hasNext
in interface XMLStreamReader
public boolean hasText()
hasText
in interface XMLStreamReader
public boolean isAttributeSpecified(int index)
isAttributeSpecified
in interface XMLStreamReader
public boolean isCharacters()
isCharacters
in interface XMLStreamReader
public boolean isEndElement()
isEndElement
in interface XMLStreamReader
public boolean isStartElement()
isStartElement
in interface XMLStreamReader
public boolean isWhiteSpace()
isWhiteSpace
in interface XMLStreamReader
public void require(int type, String nsUri, String localName) throws XMLStreamException
require
in interface XMLStreamReader
XMLStreamException
public int next() throws XMLStreamException
next
in interface XMLStreamReader
XMLStreamException
public int nextTag() throws XMLStreamException
nextTag
in interface XMLStreamReader
XMLStreamException
public void close() throws XMLStreamException
Note: as per StAX 1.0 specs, this method does NOT close the underlying
input reader. That is, unless the new StAX2 property
XMLInputFactory2.P_AUTO_CLOSE_INPUT
is
set to true.
close
in interface XMLStreamReader
XMLStreamException
public String getNamespaceURI(String prefix)
getNamespaceURI
in interface NamespaceContext
getNamespaceURI
in interface XMLStreamReader
public String getPrefix(String namespaceURI)
getPrefix
in interface NamespaceContext
public Iterator getPrefixes(String namespaceURI)
getPrefixes
in interface NamespaceContext
public boolean getElementAsBoolean() throws XMLStreamException
TypedXMLStreamReader
Read an element content as a boolean. The lexical representation of a boolean is defined by the XML Schema boolean data type. Whitespace MUST be collapsed according to the whiteSpace facet for the XML Schema boolean data type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema boolean data type. (note: allowed lexical values are canonicals "true" and "false", as well as non-canonical "0" and "1")
These are the pre- and post-conditions of calling this method:
getElementAsBoolean
in interface TypedXMLStreamReader
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.public int getElementAsInt() throws XMLStreamException
TypedXMLStreamReader
Read an element content as a 32-bit integer. The lexical representation of a integer is defined by the XML Schema integer data type. Whitespace MUST be collapsed according to the whiteSpace facet for the XML Schema integer data type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema integer data type.
These are the pre and post conditions of calling this method:
getElementAsInt
in interface TypedXMLStreamReader
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into a Java (32-bit) integer.public long getElementAsLong() throws XMLStreamException
TypedXMLStreamReader
Read an element content as a 64-bit integer. The lexical representation of a integer is defined by the XML Schema integer data type. Whitespace MUST be collapsed according to the whiteSpace facet for the XML Schema integer data type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema integer data type.
These are the pre and post conditions of calling this method:
getElementAsLong
in interface TypedXMLStreamReader
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into a Java (64-bit) integer.public float getElementAsFloat() throws XMLStreamException
TypedXMLStreamReader
Read an element content as a 32-bit floating point value.
The lexical representation is defined by the
XML Schema float data type. Whitespace MUST be
collapsed
according to the whiteSpace facet for the XML Schema float data type.
An exception is thrown if, after whitespace is
collapsed, the resulting sequence of characters is not in
the lexical space defined by the XML Schema integer data type.
Note that valid representations include basic Java textual
representations, as well as 3 special tokens: "INF", "-INF"
and "NaN"
These are the pre and post conditions of calling this method:
getElementAsFloat
in interface TypedXMLStreamReader
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into a Java floatpublic double getElementAsDouble() throws XMLStreamException
TypedXMLStreamReader
Read an element content as a 64-bit floating point value.
The lexical representation is defined by the
XML Schema double data type. Whitespace MUST be
collapsed
according to the whiteSpace facet for the XML Schema double data type.
An exception is thrown if, after whitespace is
collapsed, the resulting sequence of characters is not in
the lexical space defined by the XML Schema integer data type.
Note that valid representations include basic Java textual
representations, as well as 3 special tokens: "INF", "-INF"
and "NaN"
These are the pre and post conditions of calling this method:
getElementAsDouble
in interface TypedXMLStreamReader
XMLStreamException
- If unable to access contentTypedXMLStreamException
- If unable to convert the resulting
character sequence into a Java doublepublic BigInteger getElementAsInteger() throws XMLStreamException
getElementAsInteger
in interface TypedXMLStreamReader
XMLStreamException
public BigDecimal getElementAsDecimal() throws XMLStreamException
getElementAsDecimal
in interface TypedXMLStreamReader
XMLStreamException
public QName getElementAsQName() throws XMLStreamException
getElementAsQName
in interface TypedXMLStreamReader
XMLStreamException
public byte[] getElementAsBinary() throws XMLStreamException
TypedXMLStreamReader
TypedXMLStreamReader.readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant)
, in cases where neither performance nor
memory usage is a big concern.
Note: base64 variant defaults to Base64Variants.MIME
.
getElementAsBinary
in interface TypedXMLStreamReader
XMLStreamException
TypedXMLStreamReader.readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant)
public byte[] getElementAsBinary(Base64Variant v) throws XMLStreamException
TypedXMLStreamReader
TypedXMLStreamReader.readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant)
, in cases where neither performance nor
memory usage is a big concern.getElementAsBinary
in interface TypedXMLStreamReader
v
- Base64 variant content is in; needed to decode
alternative variants ("modified base64")XMLStreamException
TypedXMLStreamReader.readElementAsBinary(byte[], int, int, org.codehaus.stax2.typed.Base64Variant)
public void getElementAs(TypedValueDecoder tvd) throws XMLStreamException
TypedXMLStreamReader
XMLStreamReader.getElementText()
,
and then call one of decode methods defined in
TypedValueDecoder
. The only difference is that
passed value will be trimmed: that is, any leading or
trailing white space will be removed prior to calling
decode method.
After the call, passed
decoder object will have decoded and stored value
(if succesful) or thrown an exception (if not).
The main benefit of using this method (over just getting
all content by calling XMLStreamReader.getElementText()
is efficiency: the stream reader can efficiently gather all textual
content necessary and pass it to the decoder, often avoiding
construction of intemediate Strings.
These are the pre- and post-conditions of calling this method:
Note that caller has to know more specific type of decoder, since the base interface does not specify methods for accessing actual decoded value.
getElementAs
in interface TypedXMLStreamReader
XMLStreamException
public int readElementAsIntArray(int[] value, int from, int length) throws XMLStreamException
TypedXMLStreamReader
<xs:simpleType name="intArray"> <xs:list itemType="xs:int"/> </xs:simpleType>whose lexical space is a list of space-separated ints. Whitespace MUST be collapsed according to the whiteSpace facet for the
intArray
type shown above. An exception is thrown if, after whitespace is
collapsed, the resulting sequence of characters is not in
the lexical space defined by the intArray
data
type.
These are the pre and post conditions of calling this method:
readElementAsIntArray
in interface TypedXMLStreamReader
value
- The array in which to copy the ints.from
- The index in the array from which copying starts.length
- The maximun number of ints to copy. Minimum value
is 1; others an IllegalArgumentException
is thrownlength
, but
at least one if any ints found. If not, -1 is returned
to signal end of ints to parse.XMLStreamException
public int readElementAsLongArray(long[] value, int from, int length) throws XMLStreamException
readElementAsLongArray
in interface TypedXMLStreamReader
XMLStreamException
public int readElementAsFloatArray(float[] value, int from, int length) throws XMLStreamException
readElementAsFloatArray
in interface TypedXMLStreamReader
XMLStreamException
public int readElementAsDoubleArray(double[] value, int from, int length) throws XMLStreamException
readElementAsDoubleArray
in interface TypedXMLStreamReader
XMLStreamException
public int readElementAsArray(TypedArrayDecoder tad) throws XMLStreamException
TypedXMLStreamReader
These are the pre- and post-conditions of calling this method:
Note: passed decoder must accept at least one value, reader will not verify capacity before calling it with the first token.
readElementAsArray
in interface TypedXMLStreamReader
XMLStreamException
public int readElementAsBinary(byte[] resultBuffer, int offset, int maxLength) throws XMLStreamException
readElementAsBinary
in interface TypedXMLStreamReader
XMLStreamException
public int readElementAsBinary(byte[] resultBuffer, int offset, int maxLength, Base64Variant v) throws XMLStreamException
TypedXMLStreamReader
Each call will read at least one decoded byte (and no more than the specified maximum length), if there is any content remaining. If none is available and END_ELEMENT is encountered, -1 is returned.
These are the pre and post conditions of calling this method:
Additionally, caller MUST start decoding at START_ELEMENT; if the first decode calls is at CHARACTERS or CDATA event, results are not defined: result may be an exception, or invalid data being returned. Implementations are encouraged to throw an exception if possible, to make it easier to figure out the problem.
This method can be called multiple times until the cursor is positioned at the corresponding END_ELEMENT event. Stated differently, after the method is called for the first time, the cursor will move and remain in the CHARACTERS position while there are potentially more bytes available for reading.
readElementAsBinary
in interface TypedXMLStreamReader
resultBuffer
- Array in which to copy decoded bytes.offset
- Starting offset of the first decoded byte
within result buffermaxLength
- Maximun number of bytes to decode with this callmaxLength
Note that this value is not guaranteed to equal maxLength
even if enough content was available; that is, implementations
can return shorter sections if they choose to, down to and including
returning zero (0) if it was not possible to decode a full base64
triplet (3 output bytes from 4 input characters).XMLStreamException
public int getAttributeIndex(String namespaceURI, String localName)
TypedXMLStreamReader
localName
and URI is namespaceURI
or -1
if no such attribute exists.getAttributeIndex
in interface TypedXMLStreamReader
namespaceURI
- The attribute's namespace URI. Values of
null and "" are considered the same, i.e. "no namespace"
(or "empty" namespace)localName
- The attribute's local name.-1
if no
such attribute exists.public boolean getAttributeAsBoolean(int index) throws XMLStreamException
TypedXMLStreamReader
Read an attribute value as a boolean. The lexical representation of a boolean is defined by the XML Schema boolean data type. Whitespace MUST be collapsed according to the whiteSpace facet for the XML Schema boolean data type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema boolean data type.
getAttributeAsBoolean
in interface TypedXMLStreamReader
index
- The attribute's index as returned by TypedXMLStreamReader.getAttributeIndex(String, String)
XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.public int getAttributeAsInt(int index) throws XMLStreamException
TypedXMLStreamReader
Read an attribute value as a boolean. The lexical representation of a boolean is defined by the XML Schema integer data type. Whitespace MUST be collapsed according to the whiteSpace facet for the type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema integer data type.
getAttributeAsInt
in interface TypedXMLStreamReader
index
- The attribute's index as returned by TypedXMLStreamReader.getAttributeIndex(String, String)
XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.public long getAttributeAsLong(int index) throws XMLStreamException
TypedXMLStreamReader
Read an attribute value as a boolean. The lexical representation of a boolean is defined by the XML Schema long data type. Whitespace MUST be collapsed according to the whiteSpace facet for the type. An exception is thrown if, after whitespace is collapsed, the resulting sequence of characters is not in the lexical space defined by the XML Schema long data type.
getAttributeAsLong
in interface TypedXMLStreamReader
index
- The attribute's index as returned by TypedXMLStreamReader.getAttributeIndex(String, String)
XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.public float getAttributeAsFloat(int index) throws XMLStreamException
getAttributeAsFloat
in interface TypedXMLStreamReader
XMLStreamException
public double getAttributeAsDouble(int index) throws XMLStreamException
getAttributeAsDouble
in interface TypedXMLStreamReader
XMLStreamException
public BigInteger getAttributeAsInteger(int index) throws XMLStreamException
getAttributeAsInteger
in interface TypedXMLStreamReader
XMLStreamException
public BigDecimal getAttributeAsDecimal(int index) throws XMLStreamException
getAttributeAsDecimal
in interface TypedXMLStreamReader
XMLStreamException
public QName getAttributeAsQName(int index) throws XMLStreamException
getAttributeAsQName
in interface TypedXMLStreamReader
XMLStreamException
public final void getAttributeAs(int index, TypedValueDecoder tvd) throws XMLStreamException
TypedXMLStreamReader
As with TypedXMLStreamReader.getElementAs(org.codehaus.stax2.typed.TypedValueDecoder)
, value passed to a decode
method will be trimmed of any leading or trailing white space.
getAttributeAs
in interface TypedXMLStreamReader
XMLStreamException
public int[] getAttributeAsIntArray(int index) throws XMLStreamException
TypedXMLStreamReader
Read an attribute content as an int array. The lexical representation of a int array is defined by the following XML schema type:
<xs:simpleType name="intArray"> <xs:list itemType="xs:int"/> </xs:simpleType>whose lexical space is a list of space-separated ints. Whitespace MUST be collapsed according to the whiteSpace facet for the
intArray
type shown above. An exception is thrown if, after whitespace is
collapsed, the resulting sequence of characters is not in
the lexical space defined by the intArray
data
type.getAttributeAsIntArray
in interface TypedXMLStreamReader
index
- The attribute's index as returned by TypedXMLStreamReader.getAttributeIndex(String, String)
.XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.public long[] getAttributeAsLongArray(int index) throws XMLStreamException
getAttributeAsLongArray
in interface TypedXMLStreamReader
XMLStreamException
public float[] getAttributeAsFloatArray(int index) throws XMLStreamException
getAttributeAsFloatArray
in interface TypedXMLStreamReader
XMLStreamException
public double[] getAttributeAsDoubleArray(int index) throws XMLStreamException
getAttributeAsDoubleArray
in interface TypedXMLStreamReader
XMLStreamException
public int getAttributeAsArray(int index, TypedArrayDecoder tad) throws XMLStreamException
TypedXMLStreamReader
getAttributeAsArray
in interface TypedXMLStreamReader
XMLStreamException
protected int _getAttributeAsArray(TypedArrayDecoder tad, String attrValue) throws XMLStreamException
XMLStreamException
public byte[] getAttributeAsBinary(int index) throws XMLStreamException
TypedXMLStreamReader
getAttributeAsBinary
in interface TypedXMLStreamReader
index
- The attribute's index as returned by TypedXMLStreamReader.getAttributeIndex(String, String)
.XMLStreamException
- If unable to convert the resulting
character sequence into an XML Schema boolean value.public byte[] getAttributeAsBinary(int index, Base64Variant v) throws XMLStreamException
getAttributeAsBinary
in interface TypedXMLStreamReader
XMLStreamException
public Object getFeature(String name)
XMLStreamReader2
Note: although some feature names are shared with
XMLStreamReader2.setFeature(java.lang.String, java.lang.Object)
, not all are: some features are read-only,
some write-only
getFeature
in interface XMLStreamReader2
name
- Name of the feature of which value to getpublic void setFeature(String name, Object value)
XMLStreamReader2
Note: although some feature names are shared with
XMLStreamReader2.getFeature(java.lang.String)
, not all are: some features are read-only,
some write-only
setFeature
in interface XMLStreamReader2
name
- Name of the feature to setvalue
- Value to set feature to.public void skipElement() throws XMLStreamException
XMLStreamReader2
IllegalStateException
is thrown); after the call the stream will point to the matching
END_ELEMENT event, having skipped zero or more intervening events
for the contents.skipElement
in interface XMLStreamReader2
XMLStreamException
public AttributeInfo getAttributeInfo() throws XMLStreamException
XMLStreamReader2
IllegalStateException
will be thrown.getAttributeInfo
in interface XMLStreamReader2
XMLStreamException
public int findAttributeIndex(String nsURI, String localName)
findAttributeIndex
in interface AttributeInfo
public int getIdAttributeIndex()
AttributeInfo
getIdAttributeIndex
in interface AttributeInfo
public int getNotationAttributeIndex()
AttributeInfo
getNotationAttributeIndex
in interface AttributeInfo
public DTDInfo getDTDInfo() throws XMLStreamException
DTDInfo
, method can just
return this
.getDTDInfo
in interface XMLStreamReader2
XMLStreamException
public final LocationInfo getLocationInfo()
getLocationInfo
in interface XMLStreamReader2
public int getText(Writer w, boolean preserveContents) throws IOException, XMLStreamException
getText()
, except
that it just uses provided Writer to write all textual content.
For further optimization, it may also be allowed to do true
pass-through, thus possibly avoiding one temporary copy of the
data.
TODO: try to optimize to allow completely streaming pass-through: currently will still read all data in memory buffers before outputting
getText
in interface XMLStreamReader2
w
- Writer to use for writing textual contentspreserveContents
- If true, reader has to preserve contents
so that further calls to getText
will return
proper conntets. If false, reader is allowed to skip creation
of such copies: this can improve performance, but it also means
that further calls to getText
is not guaranteed to
return meaningful data.IOException
XMLStreamException
public int getDepth()
XMLStreamReader2
getDepth
in interface XMLStreamReader2
public boolean isEmptyElement() throws XMLStreamException
XMLStreamReader2
Note: method may need to read more data to know if the element
is an empty one, and as such may throw an i/o or parsing exception
(as XMLStreamException
); however, it won't throw exceptions
for non-START_ELEMENT event types.
isEmptyElement
in interface XMLStreamReader2
XMLStreamException
public NamespaceContext getNonTransientNamespaceContext()
XMLStreamReader2
XMLStreamReader.getNamespaceContext()
,
but one that is
not transient. That is, one that will remain valid and unchanged
after its creation. This allows the namespace context to be used
independent of its source documents life cycle. One possible use
case is to use this namespace context for 'initializing' writers
(especially ones that use repairing mode) with optimal/preferred name
space bindings.getNonTransientNamespaceContext
in interface XMLStreamReader2
public String getPrefixedName()
XMLStreamReader2
Note: implementations are encouraged to provide an implementation
that would be more efficient than calling getLocalName
and getPrefix
separately, but are not required to do
so. Nonetheless it is usually at least as efficient (if not more)
to call this method as to do it fully in calling code.
getPrefixedName
in interface XMLStreamReader2
public void closeCompletely() throws XMLStreamException
XMLStreamReader2
XMLStreamReader.close()
,
except that this method also does close the underlying input
source if it has not yet been closed. It is generally preferable
to call this method if the parsing ends in an exception;
and for some input sources (when passing
a File
or URL
for factory
method) it has to be called as the application does not have
access to the actually input source (InputStream
opened from a URL
and so on).closeCompletely
in interface XMLStreamReader2
XMLStreamException
public Object getProcessedDTD()
getProcessedDTD
in interface DTDInfo
public String getDTDRootName()
getDTDRootName
in interface DTDInfo
public String getDTDPublicId()
getDTDPublicId
in interface DTDInfo
public String getDTDSystemId()
getDTDSystemId
in interface DTDInfo
public String getDTDInternalSubset()
getDTDInternalSubset
in interface DTDInfo
public DTDValidationSchema getProcessedDTDSchema()
DTDInfo
DTDInfo.getProcessedDTD()
, but type-safe. Will
return the DTD schema instance that was read, if we are in mode
where it does get read (at least dtd-aware).getProcessedDTDSchema
in interface DTDInfo
public long getStartingByteOffset()
LocationInfo
Note: this value MAY be the same as the one returned by
LocationInfo.getStartingCharOffset()
, but usually only for single-byte
character streams (Ascii, ISO-Latin).
getStartingByteOffset
in interface LocationInfo
public long getStartingCharOffset()
LocationInfo
Note: this value MAY be the same as the one returned by
LocationInfo.getStartingByteOffset()
; this is the case for single-byte
character streams (Ascii, ISO-Latin), as well as for streams for
which byte offset information is not available (Readers, Strings).
getStartingCharOffset
in interface LocationInfo
public long getEndingByteOffset() throws XMLStreamException
LocationInfo
Note: this value MAY be the same as the one returned by
LocationInfo.getEndingCharOffset()
, but usually only for single-byte
character streams (Ascii, ISO-Latin).
Note: for lazy-loading implementations, calling this method may require the underlying stream to be advanced and contents parsed; this is why it is possible that an exception be thrown.
getEndingByteOffset
in interface LocationInfo
XMLStreamException
public long getEndingCharOffset() throws XMLStreamException
LocationInfo
Note: this value MAY be the same as the one returned by
LocationInfo.getEndingByteOffset()
; this is the case for single-byte
character streams (Ascii, ISO-Latin), as well as for streams for
which byte offset information is not available (Readers, Strings).
Note: for lazy-loading implementations, calling this method may require the underlying stream to be advanced and contents parsed; this is why it is possible that an exception be thrown.
getEndingCharOffset
in interface LocationInfo
XMLStreamException
public XMLStreamLocation2 getStartLocation()
LocationInfo
Note: since it is assumed that the start location must either have
been collected by now, or is not accessible (i.e. implementation
[always] returns null), no exception is allowed to be throws, as
no parsing should ever need to be done (unlike with
LocationInfo.getEndLocation()
).
getStartLocation
in interface LocationInfo
public XMLStreamLocation2 getCurrentLocation()
LocationInfo
Since this location information should always be accessible, no further parsing is to be done, and no exceptions can be thrown.
getCurrentLocation
in interface LocationInfo
public final XMLStreamLocation2 getEndLocation() throws XMLStreamException
LocationInfo
Note: since some implementations may not yet know the end location (esp. ones that do lazy loading), this call may require further parsing. As a result, this method may throw a parsing or I/O errors.
getEndLocation
in interface LocationInfo
XMLStreamException
- If the stream reader had to advance to
the end of the event (to find the location), it may encounter a
parsing (or I/O) error; if so, that gets thrownpublic XMLValidator validateAgainst(XMLValidationSchema schema) throws XMLStreamException
Validatable
XMLValidator
instance from the
given schema (unless a validator for that schema has already been
added),
initialize it if necessary, and make validatable object (reader,
writer)
call appropriate validation methods from this point on until the
end of the document (that is, it's not scoped with sub-trees), or until
validator is removed by an explicit call to
Validatable.stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema)
.
Note that while this method can be called at any point in output processing, validator instances are not required to be able to handle addition at other points than right before outputting the root element.
validateAgainst
in interface Validatable
XMLStreamException
public XMLValidator stopValidatingAgainst(XMLValidationSchema schema) throws XMLStreamException
Validatable
Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema)
was called earlier.stopValidatingAgainst
in interface Validatable
XMLStreamException
public XMLValidator stopValidatingAgainst(XMLValidator validator) throws XMLStreamException
Validatable
Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema)
.
Note: the specified validator is compared for identity with validators in use, not for equality.
stopValidatingAgainst
in interface Validatable
validator
)
if it was being used for validating current document; null if not.XMLStreamException
public ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
Validatable
setValidationProblemHandler
in interface Validatable
h
- Handler to install, if non null; if null, indicates that
the default (implementation-specific) handling should be usedprotected void coalesceText(int initialType)
protected void reportWrongState(int errorType)
protected void reportParseProblem(int errorType) throws XMLStreamException
XMLStreamException
protected void throwStreamException(String msg) throws XMLStreamException
XMLStreamException
protected Location getErrorLocation()
protected TypedXMLStreamException _constructTypeException(IllegalArgumentException iae, String lexicalValue)
TypedXMLStreamException
,iae
- Problem as reported by converterlexicalValue
- Lexical value (element content, attribute value)
that could not be converted succesfully.protected TypedXMLStreamException _constructTypeException(String msg, String lexicalValue)
protected ValueDecoderFactory _decoderFactory()
protected StringBase64Decoder _base64Decoder()
protected String findErrorDesc(int errorType, int currEvent)
findErrorDesc()
first, and only
if no message found, uses default messages defined here.protected String _internName(String name)
Copyright © 2015 fasterxml.com. All Rights Reserved.