org.codehaus.stax2.ri
Class Stax2FilteredStreamReader

java.lang.Object
  extended byorg.codehaus.stax2.ri.Stax2FilteredStreamReader
All Implemented Interfaces:
Validatable, javax.xml.stream.XMLStreamConstants, javax.xml.stream.XMLStreamReader, XMLStreamReader2

public class Stax2FilteredStreamReader
extends java.lang.Object
implements XMLStreamReader2, javax.xml.stream.XMLStreamConstants

Simple straight-forward implementation of a filtering stream reader, which can fully adapt Stax2 stream reader (XMLStreamReader2).


Field Summary
 
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
Stax2FilteredStreamReader(javax.xml.stream.XMLStreamReader r, javax.xml.stream.StreamFilter f)
           
 
Method Summary
 void close()
           
 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 getAttributeCount()
           
 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.
 java.lang.String getAttributeLocalName(int index)
           
 javax.xml.namespace.QName getAttributeName(int index)
           
 java.lang.String getAttributeNamespace(int index)
           
 java.lang.String getAttributePrefix(int index)
           
 java.lang.String getAttributeType(int index)
           
 java.lang.String getAttributeValue(int index)
           
 java.lang.String getAttributeValue(java.lang.String nsURI, java.lang.String localName)
           
 java.lang.String getCharacterEncodingScheme()
           
 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 getElementText()
           
 java.lang.String getEncoding()
           
 int getEventType()
           
 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.
 java.lang.String getLocalName()
           
 javax.xml.stream.Location getLocation()
           
 LocationInfo getLocationInfo()
           
 javax.xml.namespace.QName getName()
           
 javax.xml.namespace.NamespaceContext getNamespaceContext()
           
 int getNamespaceCount()
           
 java.lang.String getNamespacePrefix(int index)
           
 java.lang.String getNamespaceURI()
           
 java.lang.String getNamespaceURI(int index)
           
 java.lang.String getNamespaceURI(java.lang.String prefix)
           
 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.
 java.lang.String getPIData()
           
 java.lang.String getPITarget()
           
 java.lang.String getPrefix()
           
 java.lang.String getPrefixedName()
          This method returns "prefix-qualified" name of the current element.
 java.lang.Object getProperty(java.lang.String name)
           
 java.lang.String getText()
           
 int getText(java.io.Writer w, boolean preserveContents)
          Method similar to getText(), except that it just uses provided Writer to write all textual content, and that it works for wider range of event types.
 char[] getTextCharacters()
           
 int getTextCharacters(int sourceStart, char[] target, int targetStart, int len)
           
 int getTextLength()
           
 int getTextStart()
           
 java.lang.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()
           
 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.
 boolean isStandalone()
           
 boolean isStartElement()
           
 boolean isWhiteSpace()
           
 int next()
           
 int nextTag()
           
 void require(int type, java.lang.String nsUri, java.lang.String localName)
           
 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.
 boolean standaloneSet()
           
 XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
          Method that can be called by application to stop validating output against a schema, for which 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.
 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 stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stax2FilteredStreamReader

public Stax2FilteredStreamReader(javax.xml.stream.XMLStreamReader r,
                                 javax.xml.stream.StreamFilter f)
Method Detail

next

public int next()
         throws javax.xml.stream.XMLStreamException
Specified by:
next in interface javax.xml.stream.XMLStreamReader
Throws:
javax.xml.stream.XMLStreamException

nextTag

public int nextTag()
            throws javax.xml.stream.XMLStreamException
Specified by:
nextTag in interface javax.xml.stream.XMLStreamReader
Throws:
javax.xml.stream.XMLStreamException

getCharacterEncodingScheme

public java.lang.String getCharacterEncodingScheme()
Specified by:
getCharacterEncodingScheme in interface javax.xml.stream.XMLStreamReader

getEncoding

public java.lang.String getEncoding()
Specified by:
getEncoding in interface javax.xml.stream.XMLStreamReader

getVersion

public java.lang.String getVersion()
Specified by:
getVersion in interface javax.xml.stream.XMLStreamReader

isStandalone

public boolean isStandalone()
Specified by:
isStandalone in interface javax.xml.stream.XMLStreamReader

standaloneSet

public boolean standaloneSet()
Specified by:
standaloneSet in interface javax.xml.stream.XMLStreamReader

getProperty

public java.lang.Object getProperty(java.lang.String name)
Specified by:
getProperty in interface javax.xml.stream.XMLStreamReader

getAttributeCount

public int getAttributeCount()
Specified by:
getAttributeCount in interface javax.xml.stream.XMLStreamReader

getAttributeLocalName

public java.lang.String getAttributeLocalName(int index)
Specified by:
getAttributeLocalName in interface javax.xml.stream.XMLStreamReader

getAttributeName

public javax.xml.namespace.QName getAttributeName(int index)
Specified by:
getAttributeName in interface javax.xml.stream.XMLStreamReader

getAttributeNamespace

public java.lang.String getAttributeNamespace(int index)
Specified by:
getAttributeNamespace in interface javax.xml.stream.XMLStreamReader

getAttributePrefix

public java.lang.String getAttributePrefix(int index)
Specified by:
getAttributePrefix in interface javax.xml.stream.XMLStreamReader

getAttributeType

public java.lang.String getAttributeType(int index)
Specified by:
getAttributeType in interface javax.xml.stream.XMLStreamReader

getAttributeValue

public java.lang.String getAttributeValue(int index)
Specified by:
getAttributeValue in interface javax.xml.stream.XMLStreamReader

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String nsURI,
                                          java.lang.String localName)
Specified by:
getAttributeValue in interface javax.xml.stream.XMLStreamReader

getElementText

public java.lang.String getElementText()
                                throws javax.xml.stream.XMLStreamException
Specified by:
getElementText in interface javax.xml.stream.XMLStreamReader
Throws:
javax.xml.stream.XMLStreamException

getEventType

public int getEventType()
Specified by:
getEventType in interface javax.xml.stream.XMLStreamReader

getLocalName

public java.lang.String getLocalName()
Specified by:
getLocalName in interface javax.xml.stream.XMLStreamReader

getLocation

public javax.xml.stream.Location getLocation()
Specified by:
getLocation in interface javax.xml.stream.XMLStreamReader

getName

public javax.xml.namespace.QName getName()
Specified by:
getName in interface javax.xml.stream.XMLStreamReader

getNamespaceContext

public javax.xml.namespace.NamespaceContext getNamespaceContext()
Specified by:
getNamespaceContext in interface javax.xml.stream.XMLStreamReader

getNamespaceCount

public int getNamespaceCount()
Specified by:
getNamespaceCount in interface javax.xml.stream.XMLStreamReader

getNamespacePrefix

public java.lang.String getNamespacePrefix(int index)
Specified by:
getNamespacePrefix in interface javax.xml.stream.XMLStreamReader

getNamespaceURI

public java.lang.String getNamespaceURI()
Specified by:
getNamespaceURI in interface javax.xml.stream.XMLStreamReader

getNamespaceURI

public java.lang.String getNamespaceURI(int index)
Specified by:
getNamespaceURI in interface javax.xml.stream.XMLStreamReader

getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String prefix)
Specified by:
getNamespaceURI in interface javax.xml.stream.XMLStreamReader

getPIData

public java.lang.String getPIData()
Specified by:
getPIData in interface javax.xml.stream.XMLStreamReader

getPITarget

public java.lang.String getPITarget()
Specified by:
getPITarget in interface javax.xml.stream.XMLStreamReader

getPrefix

public java.lang.String getPrefix()
Specified by:
getPrefix in interface javax.xml.stream.XMLStreamReader

getText

public java.lang.String getText()
Specified by:
getText in interface javax.xml.stream.XMLStreamReader

getTextCharacters

public char[] getTextCharacters()
Specified by:
getTextCharacters in interface javax.xml.stream.XMLStreamReader

getTextCharacters

public int getTextCharacters(int sourceStart,
                             char[] target,
                             int targetStart,
                             int len)
                      throws javax.xml.stream.XMLStreamException
Specified by:
getTextCharacters in interface javax.xml.stream.XMLStreamReader
Throws:
javax.xml.stream.XMLStreamException

getTextLength

public int getTextLength()
Specified by:
getTextLength in interface javax.xml.stream.XMLStreamReader

getTextStart

public int getTextStart()
Specified by:
getTextStart in interface javax.xml.stream.XMLStreamReader

hasName

public boolean hasName()
Specified by:
hasName in interface javax.xml.stream.XMLStreamReader

hasNext

public boolean hasNext()
                throws javax.xml.stream.XMLStreamException
Specified by:
hasNext in interface javax.xml.stream.XMLStreamReader
Throws:
javax.xml.stream.XMLStreamException

hasText

public boolean hasText()
Specified by:
hasText in interface javax.xml.stream.XMLStreamReader

isAttributeSpecified

public boolean isAttributeSpecified(int index)
Specified by:
isAttributeSpecified in interface javax.xml.stream.XMLStreamReader

isCharacters

public boolean isCharacters()
Specified by:
isCharacters in interface javax.xml.stream.XMLStreamReader

isEndElement

public boolean isEndElement()
Specified by:
isEndElement in interface javax.xml.stream.XMLStreamReader

isStartElement

public boolean isStartElement()
Specified by:
isStartElement in interface javax.xml.stream.XMLStreamReader

isWhiteSpace

public boolean isWhiteSpace()
Specified by:
isWhiteSpace in interface javax.xml.stream.XMLStreamReader

require

public void require(int type,
                    java.lang.String nsUri,
                    java.lang.String localName)
             throws javax.xml.stream.XMLStreamException
Specified by:
require in interface javax.xml.stream.XMLStreamReader
Throws:
javax.xml.stream.XMLStreamException

close

public void close()
           throws javax.xml.stream.XMLStreamException
Specified by:
close in interface javax.xml.stream.XMLStreamReader
Throws:
javax.xml.stream.XMLStreamException

getFeature

public java.lang.Object getFeature(java.lang.String name)
Description copied from interface: XMLStreamReader2
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.

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

Specified by:
getFeature in interface XMLStreamReader2
Parameters:
name - Name of the feature of which value to get
Returns:
Value of the feature (possibly null), if supported; null otherwise

setFeature

public void setFeature(java.lang.String name,
                       java.lang.Object value)
Description copied from interface: XMLStreamReader2
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.

Note: although some feature names are shared with XMLStreamReader2.getFeature(java.lang.String), not all are: some features are read-only, some write-only

Specified by:
setFeature in interface XMLStreamReader2
Parameters:
name - Name of the feature to set
value - Value to set feature to.

isPropertySupported

public boolean isPropertySupported(java.lang.String name)
Description copied from interface: XMLStreamReader2
Method similar to 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.

Specified by:
isPropertySupported in interface XMLStreamReader2

setProperty

public boolean setProperty(java.lang.String name,
                           java.lang.Object value)
Description copied from interface: XMLStreamReader2
Method that can be used to set per-reader properties; a subset of properties one can set via matching XMLInputFactory2 instance. Exactly which methods are mutable is implementation specific.

Specified by:
setProperty in interface XMLStreamReader2
Parameters:
name - Name of the property to set
value - Value to set property to.
Returns:
True, if the specified property was succesfully set to specified value; false if its value was not changed

skipElement

public void skipElement()
                 throws javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamReader2
Method that will skip all the contents of the element that the stream currently points to. Current event when calling the method has to be START_ELEMENT (or otherwise 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.

Specified by:
skipElement in interface XMLStreamReader2
Throws:
javax.xml.stream.XMLStreamException

getDTDInfo

public DTDInfo getDTDInfo()
                   throws javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamReader2
Method that can be called to get information about DOCTYPE declaration that the reader is currently pointing to, if the reader has parsed it. Implementations can also choose to return null to indicate they do not provide extra information; but they should not throw any exceptions beyond normal parsing exceptions.

Specified by:
getDTDInfo in interface XMLStreamReader2
Returns:
Information object for accessing further DOCTYPE information, iff the reader currently points to DTD event, AND is operating in mode that parses such information (DTD-aware at least, and usually also validating)
Throws:
javax.xml.stream.XMLStreamException

getAttributeInfo

public AttributeInfo getAttributeInfo()
                               throws javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamReader2
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. Note that the reader has to currently point to START_ELEMENT; if not, a IllegalStateException will be thrown.

Specified by:
getAttributeInfo in interface XMLStreamReader2
Throws:
javax.xml.stream.XMLStreamException

getText

public int getText(java.io.Writer w,
                   boolean preserveContents)
            throws java.io.IOException,
                   javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamReader2
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. 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().

Specified by:
getText in interface XMLStreamReader2
Parameters:
w - Writer to use for writing textual contents
preserveContents - 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.
Returns:
Number of characters written to the reader
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

getLocationInfo

public LocationInfo getLocationInfo()
Specified by:
getLocationInfo in interface XMLStreamReader2

isEmptyElement

public boolean isEmptyElement()
                       throws javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamReader2
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.

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.

Specified by:
isEmptyElement in interface XMLStreamReader2
Returns:
True, if current event is START_ELEMENT and is based on a parsed empty element; otherwise false
Throws:
javax.xml.stream.XMLStreamException

getDepth

public int getDepth()
Description copied from interface: XMLStreamReader2
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. Depth is same for matching start/end elements, as well as for the immediate non-element children of the element.

Specified by:
getDepth in interface XMLStreamReader2
Returns:
Number of open elements currently in the reader's stack

getNonTransientNamespaceContext

public javax.xml.namespace.NamespaceContext getNonTransientNamespaceContext()
Description copied from interface: XMLStreamReader2
This method returns a namespace contenxt object that contains information identical to that returned by 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.

Specified by:
getNonTransientNamespaceContext in interface XMLStreamReader2
Returns:
Non-transient namespace context as explained above.

getPrefixedName

public java.lang.String getPrefixedName()
Description copied from interface: XMLStreamReader2
This method returns "prefix-qualified" name of the current element. In general, this means character-by-character exact name of the element in XML content, and may be useful in informational purposes, as well as when interacting with packages and APIs that use such names (such as what SAX may use as qnames).

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.

Specified by:
getPrefixedName in interface XMLStreamReader2
Returns:
Prefix-qualified name of the current element; essentially 'prefix:localName' if the element has a prefix, or 'localName' if it does not have one (belongs to the default namespace)

closeCompletely

public void closeCompletely()
                     throws javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamReader2
Method similar to XMLStreamReader.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).

Specified by:
closeCompletely in interface XMLStreamReader2
Throws:
javax.xml.stream.XMLStreamException

validateAgainst

public XMLValidator validateAgainst(XMLValidationSchema schema)
                             throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
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).

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.

Specified by:
validateAgainst in interface Validatable
Returns:
Validator instance constructed, if validator was added, or null if a validator for the schema has already been constructed.
Throws:
javax.xml.stream.XMLStreamException

stopValidatingAgainst

public XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
                                   throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
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.

Specified by:
stopValidatingAgainst in interface Validatable
Returns:
Validator instance created from the schema that was removed, if one was in use; null if no such schema in use.
Throws:
javax.xml.stream.XMLStreamException

stopValidatingAgainst

public XMLValidator stopValidatingAgainst(XMLValidator validator)
                                   throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
Method that can be called by application to stop validating output using specified validator. The validator passed should be an earlier return value for a call to Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema).

Note: the specified validator is compared for identity with validators in use, not for equality.

Specified by:
stopValidatingAgainst in interface Validatable
Returns:
Validator instance found (ie. argument validator) if it was being used for validating current document; null if not.
Throws:
javax.xml.stream.XMLStreamException

setValidationProblemHandler

public ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
Description copied from interface: Validatable
Method that application can call to define a custom handler for validation problems encountered during validation process.

Specified by:
setValidationProblemHandler in interface Validatable
Parameters:
h - Handler to install, if non null; if null, indicates that the default (implementation-specific) handling should be used
Returns:
Previously set validation problem handler, if any; null if none was set