Top Description Fields Constructors Methods
org.springframework.util.xml

pack-priv Class XMLEventStreamReader

extends AbstractXMLStreamReader
Class Inheritance
Imports
java.util.Iterator, javax.xml.namespace.NamespaceContext, .QName, javax.xml.stream.Location, .XMLEventReader, .XMLStreamConstants, .XMLStreamException, javax.xml.stream.events.Attribute, .Comment, .Namespace, .ProcessingInstruction, .StartDocument, .XMLEvent, org.springframework.lang.Nullable

Implementation of the javax.xml.stream.XMLStreamReader interface that wraps a XMLEventReader. Useful because the StAX javax.xml.stream.XMLInputFactory allows one to create an event reader from a stream reader, but not vice-versa.
Author
Arjen Poutsma
Since
3.0
See Also
StaxUtils#createEventStreamReader(javax.xml.stream.XMLEventReader)

Field Summary

Modifier and TypeField and Description
private XMLEvent
private final XMLEventReader

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements javax.xml.stream.XMLStreamReader.close.

Frees any resources associated with this Reader.

private static int
countIterator(Iterator<E> iterator)

private Attribute
getAttribute(int index)

public int
getAttributeCount()

Implements javax.xml.stream.XMLStreamReader.getAttributeCount.

Returns the count of attributes on this START_ELEMENT, this method is only valid on a START_ELEMENT or ATTRIBUTE.

public QName
getAttributeName(int
the position of the attribute
index
)

Implements javax.xml.stream.XMLStreamReader.getAttributeName.

Returns the qname of the attribute at the provided index

public String
getAttributeType(int
the position of the attribute
index
)

Implements javax.xml.stream.XMLStreamReader.getAttributeType.

Returns the XML type of the attribute at the provided index

public String
getAttributeValue(int
the position of the attribute
index
)

Implements javax.xml.stream.XMLStreamReader.getAttributeValue.

Returns the value of the attribute at the index

public String
getCharacterEncodingScheme()

Implements javax.xml.stream.XMLStreamReader.getCharacterEncodingScheme.

Returns the character encoding declared on the xml declaration Returns null if none was declared

public String
getEncoding()

Implements javax.xml.stream.XMLStreamReader.getEncoding.

Return input encoding if known or null if unknown.

public int
getEventType()

Implements javax.xml.stream.XMLStreamReader.getEventType.

Returns an integer code that indicates the type of the event the cursor is pointing to.

public Location
getLocation()

Implements javax.xml.stream.XMLStreamReader.getLocation.

Return the current location of the processor.

public QName
getName()

Implements javax.xml.stream.XMLStreamReader.getName.

Returns a QName for the current START_ELEMENT or END_ELEMENT event

private Namespace
getNamespace(int index)

public NamespaceContext
getNamespaceContext()

Implements javax.xml.stream.XMLStreamReader.getNamespaceContext.

Returns a read only namespace context for the current position.

public int
getNamespaceCount()

Implements javax.xml.stream.XMLStreamReader.getNamespaceCount.

Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT, this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE.

public String
getNamespacePrefix(int
the position of the namespace declaration
index
)

Implements javax.xml.stream.XMLStreamReader.getNamespacePrefix.

Returns the prefix for the namespace declared at the index.

public String
getNamespaceURI(int
the position of the namespace declaration
index
)

Implements javax.xml.stream.XMLStreamReader.getNamespaceURI.

Returns the uri for the namespace declared at the index.

public String
getPIData()

Implements javax.xml.stream.XMLStreamReader.getPIData.

Get the data section of a processing instruction

public String
getPITarget()

Implements javax.xml.stream.XMLStreamReader.getPITarget.

Get the target of a processing instruction

public Object
getProperty(String
The name of the property, may not be null
name
)

Implements javax.xml.stream.XMLStreamReader.getProperty.

Get the value of a feature/property from the underlying implementation

public String
getText()

Implements javax.xml.stream.XMLStreamReader.getText.

Returns the current value of the parse event as a string, this returns the string value of a CHARACTERS event, returns the value of a COMMENT, the replacement value for an ENTITY_REFERENCE, the string value of a CDATA section, the string value for a SPACE event, or the String value of the internal subset of the DTD.

public int
getTextStart()

Implements javax.xml.stream.XMLStreamReader.getTextStart.

Returns the offset into the text character array where the first character (of this text event) is stored.

public String
getVersion()

Implements javax.xml.stream.XMLStreamReader.getVersion.

Get the xml version declared on the xml declaration Returns null if none was declared

public boolean
isAttributeSpecified(int
the position of the attribute
index
)

Implements javax.xml.stream.XMLStreamReader.isAttributeSpecified.

Returns a boolean which indicates if this attribute was created by default

public boolean
isStandalone()

Implements javax.xml.stream.XMLStreamReader.isStandalone.

Get the standalone declaration from the xml declaration

public int
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 boolean
standaloneSet()

Implements javax.xml.stream.XMLStreamReader.standaloneSet.

Checks if standalone was set in the document

Inherited from org.springframework.util.xml.AbstractXMLStreamReader:
getAttributeLocalNamegetAttributeNamespacegetAttributePrefixgetAttributeValuegetElementTextgetLocalNamegetNamespaceURIgetNamespaceURIgetPrefixgetTextCharactersgetTextCharactersgetTextLengthhasNamehasNexthasTextisCharactersisEndElementisStartElementisWhiteSpacenextTagrequire

Field Detail

eventback to summary
private XMLEvent event
eventReaderback to summary
private final XMLEventReader eventReader

Constructor Detail

XMLEventStreamReaderback to summary
public XMLEventStreamReader(XMLEventReader eventReader) throws XMLStreamException

Method Detail

closeback to summary
public void close() throws XMLStreamException

Implements javax.xml.stream.XMLStreamReader.close.

Doc from javax.xml.stream.XMLStreamReader.close.

Frees any resources associated with this Reader. This method does not close the underlying input source.

Annotations
@Override
Exceptions
XMLStreamException:
if there are errors freeing associated resources
countIteratorback to summary
private static int countIterator(Iterator<E> iterator)
Annotations
@SuppressWarnings:rawtypes
getAttributeback to summary
private Attribute getAttribute(int index)
Annotations
@SuppressWarnings:rawtypes
getAttributeCountback to summary
public int getAttributeCount()

Implements javax.xml.stream.XMLStreamReader.getAttributeCount.

Doc from javax.xml.stream.XMLStreamReader.getAttributeCount.

Returns the count of attributes on this START_ELEMENT, this method is only valid on a START_ELEMENT or ATTRIBUTE. This count excludes namespace definitions. Attribute indices are zero-based.

Returns:int

returns the number of attributes

Annotations
@Override
@SuppressWarnings:rawtypes
getAttributeNameback to summary
public QName getAttributeName(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributeName.

Doc from javax.xml.stream.XMLStreamReader.getAttributeName.

Returns the qname of the attribute at the provided index

Parameters
index:int

the position of the attribute

Returns:QName

the QName of the attribute

Annotations
@Override
getAttributeTypeback to summary
public String getAttributeType(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributeType.

Doc from javax.xml.stream.XMLStreamReader.getAttributeType.

Returns the XML type of the attribute at the provided index

Parameters
index:int

the position of the attribute

Returns:String

the XML type of the attribute

Annotations
@Override
getAttributeValueback to summary
public String getAttributeValue(int index)

Implements javax.xml.stream.XMLStreamReader.getAttributeValue.

Doc from javax.xml.stream.XMLStreamReader.getAttributeValue.

Returns the value of the attribute at the index

Parameters
index:int

the position of the attribute

Returns:String

the attribute value

Annotations
@Override
getCharacterEncodingSchemeback to summary
public String getCharacterEncodingScheme()

Implements javax.xml.stream.XMLStreamReader.getCharacterEncodingScheme.

Doc from javax.xml.stream.XMLStreamReader.getCharacterEncodingScheme.

Returns the character encoding declared on the xml declaration Returns null if none was declared

Returns:String

the encoding declared in the document or null

Annotations
@Override
@Nullable
getEncodingback to summary
public String getEncoding()

Implements javax.xml.stream.XMLStreamReader.getEncoding.

Doc from javax.xml.stream.XMLStreamReader.getEncoding.

Return input encoding if known or null if unknown.

Returns:String

the encoding of this instance or null

Annotations
@Override
@Nullable
getEventTypeback to summary
public int getEventType()

Implements javax.xml.stream.XMLStreamReader.getEventType.

Doc from javax.xml.stream.XMLStreamReader.getEventType.

Returns an integer code that indicates the type of the event the cursor is pointing to. The initial event type is START_DOCUMENT.

Returns:int

the type of the current event

Annotations
@Override
getLocationback to summary
public Location getLocation()

Implements javax.xml.stream.XMLStreamReader.getLocation.

Doc from javax.xml.stream.XMLStreamReader.getLocation.

Return the current location of the processor. If the Location is unknown the processor should return an implementation of Location that returns -1 for the location and null for the publicId and systemId. The location information is only valid until next() is called.

Returns:Location

the location of the cursor

Annotations
@Override
getNameback to summary
public QName getName()

Implements javax.xml.stream.XMLStreamReader.getName.

Doc from javax.xml.stream.XMLStreamReader.getName.

Returns a QName for the current START_ELEMENT or END_ELEMENT event

Returns:QName

the QName for the current START_ELEMENT or END_ELEMENT event

Annotations
@Override
getNamespaceback to summary
private Namespace getNamespace(int index)
Annotations
@SuppressWarnings:rawtypes
getNamespaceContextback to summary
public NamespaceContext getNamespaceContext()

Implements javax.xml.stream.XMLStreamReader.getNamespaceContext.

Doc from javax.xml.stream.XMLStreamReader.getNamespaceContext.

Returns a read only namespace context for the current position. The context is transient and only valid until a call to next() changes the state of the reader.

Returns:NamespaceContext

return a namespace context

Annotations
@Override
getNamespaceCountback to summary
public int getNamespaceCount()

Implements javax.xml.stream.XMLStreamReader.getNamespaceCount.

Doc from javax.xml.stream.XMLStreamReader.getNamespaceCount.

Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT, this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE. On an END_ELEMENT the count is of the namespaces that are about to go out of scope. This is the equivalent of the information reported by SAX callback for an end element event.

Returns:int

returns the number of namespace declarations on this specific element

Annotations
@Override
@SuppressWarnings:rawtypes
getNamespacePrefixback to summary
public String getNamespacePrefix(int index)

Implements javax.xml.stream.XMLStreamReader.getNamespacePrefix.

Doc from javax.xml.stream.XMLStreamReader.getNamespacePrefix.

Returns the prefix for the namespace declared at the index. Returns null if this is the default namespace declaration

Parameters
index:int

the position of the namespace declaration

Returns:String

returns the namespace prefix

Annotations
@Override
getNamespaceURIback to summary
public String getNamespaceURI(int index)

Implements javax.xml.stream.XMLStreamReader.getNamespaceURI.

Doc from javax.xml.stream.XMLStreamReader.getNamespaceURI.

Returns the uri for the namespace declared at the index.

Parameters
index:int

the position of the namespace declaration

Returns:String

returns the namespace uri

Annotations
@Override
getPIDataback to summary
public String getPIData()

Implements javax.xml.stream.XMLStreamReader.getPIData.

Doc from javax.xml.stream.XMLStreamReader.getPIData.

Get the data section of a processing instruction

Returns:String

the data or null

Annotations
@Override
getPITargetback to summary
public String getPITarget()

Implements javax.xml.stream.XMLStreamReader.getPITarget.

Doc from javax.xml.stream.XMLStreamReader.getPITarget.

Get the target of a processing instruction

Returns:String

the target or null

Annotations
@Override
getPropertyback to summary
public Object getProperty(String name) throws IllegalArgumentException

Implements javax.xml.stream.XMLStreamReader.getProperty.

Doc from javax.xml.stream.XMLStreamReader.getProperty.

Get the value of a feature/property from the underlying implementation

Parameters
name:String

The name of the property, may not be null

Returns:Object

The value of the property

Annotations
@Override
Exceptions
IllegalArgumentException:
if name is null
getTextback to summary
public String getText()

Implements javax.xml.stream.XMLStreamReader.getText.

Doc from javax.xml.stream.XMLStreamReader.getText.

Returns the current value of the parse event as a string, this returns the string value of a CHARACTERS event, returns the value of a COMMENT, the replacement value for an ENTITY_REFERENCE, the string value of a CDATA section, the string value for a SPACE event, or the String value of the internal subset of the DTD. If an ENTITY_REFERENCE has been resolved, any character data will be reported as CHARACTERS events.

Returns:String

the current text or null

Annotations
@Override
getTextStartback to summary
public int getTextStart()

Implements javax.xml.stream.XMLStreamReader.getTextStart.

Doc from javax.xml.stream.XMLStreamReader.getTextStart.

Returns the offset into the text character array where the first character (of this text event) is stored.

Returns:int

the starting position of the text in the character array

Annotations
@Override
getVersionback to summary
public String getVersion()

Implements javax.xml.stream.XMLStreamReader.getVersion.

Doc from javax.xml.stream.XMLStreamReader.getVersion.

Get the xml version declared on the xml declaration Returns null if none was declared

Returns:String

the XML version or null

Annotations
@Override
@Nullable
isAttributeSpecifiedback to summary
public boolean isAttributeSpecified(int index)

Implements javax.xml.stream.XMLStreamReader.isAttributeSpecified.

Doc from javax.xml.stream.XMLStreamReader.isAttributeSpecified.

Returns a boolean which indicates if this attribute was created by default

Parameters
index:int

the position of the attribute

Returns:boolean

true if this is a default attribute

Annotations
@Override
isStandaloneback to summary
public boolean isStandalone()

Implements javax.xml.stream.XMLStreamReader.isStandalone.

Doc from javax.xml.stream.XMLStreamReader.isStandalone.

Get the standalone declaration from the xml declaration

Returns:boolean

true if this is standalone, or false otherwise

Annotations
@Override
nextback to summary
public int next() throws XMLStreamException

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
standaloneSetback to summary
public boolean standaloneSet()

Implements javax.xml.stream.XMLStreamReader.standaloneSet.

Doc from javax.xml.stream.XMLStreamReader.standaloneSet.

Checks if standalone was set in the document

Returns:boolean

true if standalone was set in the document, or false otherwise

Annotations
@Override