|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.xml.stream.util.StreamReaderDelegate
org.codehaus.stax2.ri.Stax2ReaderAdapter
public class Stax2ReaderAdapter
This adapter implements parts of XMLStreamReader2, the
extended stream reader defined by Stax2 extension, by wrapping
a vanilla Stax 1.0 XMLStreamReader implementation.
Note: the implementation is incomplete as-is, since not all features needed are accessible via basic Stax 1.0 interface. As such, two main use cases for this wrapper are:
| Field Summary | |
|---|---|
protected int |
mDepth
Number of open (start) elements currently. |
| Fields inherited from interface org.codehaus.stax2.XMLStreamReader2 |
|---|
FEATURE_DTD_OVERRIDE |
| 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 | |
|---|---|
protected |
Stax2ReaderAdapter(javax.xml.stream.XMLStreamReader sr)
|
| Method Summary | |
|---|---|
void |
closeCompletely()
Method similar to XMLStreamReader.getNamespaceContext(),
except that this method also does close the underlying input
source if it has not yet been closed. |
int |
findAttributeIndex(java.lang.String nsURI,
java.lang.String localName)
|
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. |
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 and so on. |
DTDInfo |
getDTDInfo()
Method that can be called to get information about DOCTYPE declaration that the reader is currently pointing to, if the reader has parsed it. |
java.lang.String |
getDTDInternalSubset()
|
java.lang.String |
getDTDPublicId()
|
java.lang.String |
getDTDRootName()
|
java.lang.String |
getDTDSystemId()
|
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). |
java.lang.Object |
getFeature(java.lang.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. |
LocationInfo |
getLocationInfo()
Location information is always accessible, for this reader. |
javax.xml.namespace.NamespaceContext |
getNonTransientNamespaceContext()
This method returns a namespace contenxt 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. |
java.lang.String |
getPrefixedName()
This method returns "prefix-qualified" name of the current element. |
java.lang.Object |
getProcessedDTD()
|
DTDValidationSchema |
getProcessedDTDSchema()
Method similar to DTDInfo.getProcessedDTD(), but type-safe. |
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). |
int |
getText(java.io.Writer w,
boolean preserveContents)
Method similar to XMLStreamReader.getText(), except
that it just uses provided Writer to write all textual content,
and that it works for wider range of event types. |
boolean |
isEmptyElement()
Alas, there is no way to find this out via Stax 1.0, so this implementation always returns false. |
boolean |
isPropertySupported(java.lang.String name)
Method similar to XMLInputFactory.isPropertySupported(java.lang.String), used
to determine whether a property is supported by the Reader
instance. |
int |
next()
|
void |
setFeature(java.lang.String name,
java.lang.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. |
boolean |
setProperty(java.lang.String name,
java.lang.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. |
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 |
throwNotStartElem()
|
protected void |
throwUnsupported()
|
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). |
static XMLStreamReader2 |
wrapIfNecessary(javax.xml.stream.XMLStreamReader sr)
Method that should be used to add dynamic support for XMLStreamReader2. |
| Methods inherited from class javax.xml.stream.util.StreamReaderDelegate |
|---|
close, getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getParent, getPIData, getPITarget, getPrefix, getProperty, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, nextTag, require, setParent, standaloneSet |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface javax.xml.stream.XMLStreamReader |
|---|
close, getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getPIData, getPITarget, getPrefix, getProperty, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, nextTag, require, standaloneSet |
| Methods inherited from interface org.codehaus.stax2.AttributeInfo |
|---|
getAttributeCount |
| Methods inherited from interface org.codehaus.stax2.LocationInfo |
|---|
getLocation |
| Field Detail |
|---|
protected int mDepth
| Constructor Detail |
|---|
protected Stax2ReaderAdapter(javax.xml.stream.XMLStreamReader sr)
| Method Detail |
|---|
public static XMLStreamReader2 wrapIfNecessary(javax.xml.stream.XMLStreamReader sr)
XMLStreamReader2. Method will check whether the
stream reader passed happens to be a XMLStreamReader2;
and if it is, return it properly cast. If not, it will create
necessary wrapper to support features needed by StaxMate,
using vanilla Stax 1.0 interface.
public int next()
throws javax.xml.stream.XMLStreamException
next in interface javax.xml.stream.XMLStreamReadernext in class javax.xml.stream.util.StreamReaderDelegatejavax.xml.stream.XMLStreamExceptionpublic java.lang.Object getFeature(java.lang.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 XMLStreamReader2name - Name of the feature of which value to get
public void setFeature(java.lang.String name,
java.lang.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 XMLStreamReader2name - Name of the feature to setvalue - Value to set feature to.public boolean isPropertySupported(java.lang.String name)
XMLStreamReader2XMLInputFactory.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 boolean setProperty(java.lang.String name,
java.lang.Object value)
XMLStreamReader2XMLInputFactory2
instance. Exactly which methods are mutable is implementation
specific.
setProperty in interface XMLStreamReader2name - Name of the property to setvalue - Value to set property to.
public void skipElement()
throws javax.xml.stream.XMLStreamException
XMLStreamReader2IllegalStateException
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 XMLStreamReader2javax.xml.stream.XMLStreamException
public AttributeInfo getAttributeInfo()
throws javax.xml.stream.XMLStreamException
XMLStreamReader2IllegalStateException will be thrown.
getAttributeInfo in interface XMLStreamReader2javax.xml.stream.XMLStreamException
public DTDInfo getDTDInfo()
throws javax.xml.stream.XMLStreamException
XMLStreamReader2
getDTDInfo in interface XMLStreamReader2javax.xml.stream.XMLStreamExceptionpublic final LocationInfo getLocationInfo()
getLocationInfo in interface XMLStreamReader2
public int getText(java.io.Writer w,
boolean preserveContents)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
XMLStreamReader2XMLStreamReader.getText(), except
that it just uses provided Writer to write all textual content,
and that it works for wider range of event types.
For further optimization, it may also be allowed to do true
pass-through, thus possibly avoiding one temporary copy of the
data. Finally, note that this method is also guaranteed NOT
to return fragments, even when coalescing is not enabled and
a parser is otherwised allowed to return partial segments: this
requirement is due to there being little benefit in returning
such short chunks when streaming. Coalescing property is still
honored normally.
Method can only be called on states CDATA, CHARACTERS, COMMENT,
DTD, ENTITY_REFERENCE, SPACE and PROCESSING_INSTRUCTION; if called
when reader is in another state,
IllegalStateException will be thrown. Content written
for elements is same as with XMLStreamReader.getText().
getText in interface XMLStreamReader2w - 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.
java.io.IOException
javax.xml.stream.XMLStreamExceptionpublic int getDepth()
XMLStreamReader2
getDepth in interface XMLStreamReader2
public boolean isEmptyElement()
throws javax.xml.stream.XMLStreamException
isEmptyElement in interface XMLStreamReader2javax.xml.stream.XMLStreamExceptionpublic javax.xml.namespace.NamespaceContext getNonTransientNamespaceContext()
XMLStreamReader2XMLStreamReader.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 XMLStreamReader2public java.lang.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 javax.xml.stream.XMLStreamException
XMLStreamReader2XMLStreamReader.getNamespaceContext(),
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 XMLStreamReader2javax.xml.stream.XMLStreamException
public int findAttributeIndex(java.lang.String nsURI,
java.lang.String localName)
findAttributeIndex in interface AttributeInfopublic int getIdAttributeIndex()
AttributeInfo
getIdAttributeIndex in interface AttributeInfopublic int getNotationAttributeIndex()
AttributeInfo
getNotationAttributeIndex in interface AttributeInfopublic java.lang.Object getProcessedDTD()
getProcessedDTD in interface DTDInfopublic java.lang.String getDTDRootName()
getDTDRootName in interface DTDInfopublic java.lang.String getDTDPublicId()
getDTDPublicId in interface DTDInfopublic java.lang.String getDTDSystemId()
getDTDSystemId in interface DTDInfopublic java.lang.String getDTDInternalSubset()
getDTDInternalSubset in interface DTDInfopublic DTDValidationSchema getProcessedDTDSchema()
DTDInfoDTDInfo.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 DTDInfopublic 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 LocationInfopublic 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 javax.xml.stream.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 LocationInfojavax.xml.stream.XMLStreamException
public long getEndingCharOffset()
throws javax.xml.stream.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 LocationInfojavax.xml.stream.XMLStreamExceptionpublic 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 LocationInfopublic XMLStreamLocation2 getCurrentLocation()
LocationInfoSince 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 javax.xml.stream.XMLStreamException
LocationInfoNote: 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 LocationInfojavax.xml.stream.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 thrown
public XMLValidator validateAgainst(XMLValidationSchema schema)
throws javax.xml.stream.XMLStreamException
ValidatableXMLValidator 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 Validatablejavax.xml.stream.XMLStreamException
public XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
throws javax.xml.stream.XMLStreamException
ValidatableValidatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema)
was called earlier.
stopValidatingAgainst in interface Validatablejavax.xml.stream.XMLStreamException
public XMLValidator stopValidatingAgainst(XMLValidator validator)
throws javax.xml.stream.XMLStreamException
ValidatableValidatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema).
Note: the specified validator is compared for identity with validators in use, not for equality.
stopValidatingAgainst in interface Validatablevalidator)
if it was being used for validating current document; null if not.
javax.xml.stream.XMLStreamExceptionpublic ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
Validatable
setValidationProblemHandler in interface Validatableh - Handler to install, if non null; if null, indicates that
the default (implementation-specific) handling should be used
protected void throwUnsupported()
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamExceptionprotected void throwNotStartElem()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||