Top Description Fields Constructors Methods
org.codehaus.stax2.ri

public Class Stax2FilteredStreamReader

extends StreamReader2Delegate
implements XMLStreamConstants
Class Inheritance
All Implemented Interfaces
javax.xml.stream.XMLStreamConstants
Imports
javax.xml.stream.*, org.codehaus.stax2.*, org.codehaus.stax2.util.StreamReader2Delegate

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

Field Summary

Modifier and TypeField and Description
pack-priv final StreamFilter
Inherited from org.codehaus.stax2.util.StreamReader2Delegate:
_delegate2

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
next()

Overrides javax.xml.stream.util.StreamReaderDelegate.next.

Implements javax.xml.stream.XMLStreamReader.next.

Get next parsing event - a processor may return all contiguous character data in a single chunk, or it may split it into several chunks.
public int
nextTag()

Overrides javax.xml.stream.util.StreamReaderDelegate.nextTag.

Implements javax.xml.stream.XMLStreamReader.nextTag.

Skips any white space (isWhiteSpace() returns true), COMMENT, or PROCESSING_INSTRUCTION, until a START_ELEMENT or END_ELEMENT is reached.
Inherited from org.codehaus.stax2.util.StreamReader2Delegate:
closeCompletelygetAttributeAsgetAttributeAsArraygetAttributeAsBinarygetAttributeAsBinarygetAttributeAsBooleangetAttributeAsDecimalgetAttributeAsDoublegetAttributeAsDoubleArraygetAttributeAsFloatgetAttributeAsFloatArraygetAttributeAsIntgetAttributeAsIntArraygetAttributeAsIntegergetAttributeAsLonggetAttributeAsLongArraygetAttributeAsQNamegetAttributeIndexgetAttributeInfogetDepthgetDTDInfogetElementAsgetElementAsBinarygetElementAsBinarygetElementAsBooleangetElementAsDecimalgetElementAsDoublegetElementAsFloatgetElementAsIntgetElementAsIntegergetElementAsLonggetElementAsQNamegetFeaturegetLocationInfogetNonTransientNamespaceContextgetPrefixedNamegetTextisEmptyElementisPropertySupportedreadElementAsArrayreadElementAsBinaryreadElementAsBinaryreadElementAsDoubleArrayreadElementAsFloatArrayreadElementAsIntArrayreadElementAsLongArraysetFeaturesetParentsetPropertysetValidationProblemHandlerskipElementstopValidatingAgainststopValidatingAgainstvalidateAgainst

Field Detail

mFilterback to summary
pack-priv final StreamFilter mFilter

Constructor Detail

Stax2FilteredStreamReaderback to summary
public Stax2FilteredStreamReader(XMLStreamReader r, StreamFilter f)

Method Detail

nextback to summary
public int next() throws XMLStreamException

Overrides javax.xml.stream.util.StreamReaderDelegate.next.

Implements javax.xml.stream.XMLStreamReader.next.

Doc from javax.xml.stream.XMLStreamReader.next.

Get next parsing event - a processor may return all contiguous character data in a single chunk, or it may split it into several chunks. If the property javax.xml.stream.isCoalescing is set to true element content must be coalesced and only one CHARACTERS event must be returned for contiguous element content or CDATA Sections. By default entity references must be expanded and reported transparently to the application. An exception will be thrown if an entity reference cannot be expanded. If element content is empty (i.e. content is "") then no CHARACTERS event will be reported.

Given the following XML:
<foo><!--description-->content text<![CDATA[<greeting>Hello>/greeting>]]>other content>/foo>
The behavior of calling next() when being on foo will be:
1- the comment (COMMENT)
2- then the characters section (CHARACTERS)
3- then the CDATA section (another CHARACTERS)
4- then the next characters section (another CHARACTERS)
5- then the END_ELEMENT

Note

empty element (such as <tag/>) will be reported with two separate events: START_ELEMENT, END_ELEMENT - This preserves parsing equivalency of empty element to <tag></tag>.

Returns:int

the integer code corresponding to the current parse event

Annotations
@Override
Exceptions
XMLStreamException:
if there is an error processing the underlying XML source
nextTagback to summary
public int nextTag() throws XMLStreamException

Overrides javax.xml.stream.util.StreamReaderDelegate.nextTag.

Implements javax.xml.stream.XMLStreamReader.nextTag.

Doc from javax.xml.stream.XMLStreamReader.nextTag.

Skips any white space (isWhiteSpace() returns true), COMMENT, or PROCESSING_INSTRUCTION, until a START_ELEMENT or END_ELEMENT is reached. If other than white space characters, COMMENT, PROCESSING_INSTRUCTION, START_ELEMENT, END_ELEMENT are encountered, an exception is thrown. This method should be used when processing element-only content separated by white space.
Precondition: none
Postcondition: the current event is START_ELEMENT or END_ELEMENT and cursor may have moved over any whitespace event.
Essentially it does the following (implementations are free to optimized but must do equivalent processing):

 int eventType = next();
while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
|| (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
// skip whitespace
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT
) {
    eventType = next();
}
if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
    throw new String XMLStreamException("expected start or end tag", getLocation());
}
return eventType; 
Returns:int

the event type of the element read (START_ELEMENT or END_ELEMENT)

Annotations
@Override
Exceptions
XMLStreamException:
if the current event is not white space, PROCESSING_INSTRUCTION, START_ELEMENT or END_ELEMENT