Top Description Fields Constructors Methods
com.fasterxml.jackson.dataformat.xml.deser

public Class XmlTokenStream

extends Object
Class Inheritance
Imports
java.io.IOException, javax.xml.XMLConstants, javax.xml.stream.*, org.codehaus.stax2.XMLStreamLocation2, .XMLStreamReader2, com.fasterxml.jackson.core.JsonLocation, com.fasterxml.jackson.core.io.ContentReference, com.fasterxml.jackson.dataformat.xml.XmlNameProcessor, com.fasterxml.jackson.dataformat.xml.util.Stax2JacksonReaderAdapter

Simple helper class used on top of STAX XMLStreamReader to further abstract out all irrelevant details, and to expose equivalent of flat token stream with no "fluff" tokens (comments, processing instructions, mixed content) all of which is just to simplify actual higher-level conversion to JSON tokens.

Beyond initial idea there are also couple of other detours like ability to "replay" some tokens, add virtual wrappers (ironically to support "unwrapped" array values), and to unroll "Objects" into String values in some cases.

Field Summary

Modifier and TypeField and Description
protected int
protected boolean
protected boolean
protected int
protected ElementWrapper
_currentWrapper

Wrapping state, if any active (null if none)

protected int
_formatFeatures

Bit flag composed of bits that indicate which FromXmlParser.Features are enabled.

protected String
protected XmlNameProcessor
protected String
protected XmlNameProcessor.XmlName
_nameToDecode

Reusable internal value object

protected int
_nextAttributeIndex

Index of the next attribute of the current START_ELEMENT to return (as field name and value pair), if any; -1 when no attributes to return

protected String
_nextLocalName

In cases where we need to 'inject' a virtual END_ELEMENT, we may also need to restore START_ELEMENT afterwards; if so, this is where names are held.

protected String
protected boolean
_repeatCurrentToken

Marker flag set if caller wants to "push back" current token so that next call to next() should simply be given what was already read.

protected int
_repeatElement

Flag used to indicate that given element should be "replayed".

protected final ContentReference
protected boolean
_startElementAfterText

Flag set true if current event is XML_TEXT and there is START_ELEMENT

protected String
_textValue

Current text value for TEXT_VALUE returned

protected final XMLStreamReader2
protected boolean
_xsiNilFound

Marker used to indicate presence of `xsi:nil="true"' in current START_ELEMENT.

private static final int
private static final int
private static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
private static final String

Constructor Summary

AccessConstructor and Description
public
XmlTokenStream(XMLStreamReader xmlReader, ContentReference sourceRef, int formatFeatures, XmlNameProcessor nameProcessor)

Method Summary

Modifier and TypeMethod and Description
protected static boolean
private final void
private final String

Returns:

Collected text, if any, EXCEPT that if FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL AND empty element, returns null
_collectUntilTag
()

protected String
protected void
_decodeAttributeName(String namespaceURI, String localName)

protected void
_decodeElementName(String namespaceURI, String localName)

private JsonLocation
private final String
private final int
protected int
_handleRepeatElement()

Method called to handle details of repeating "virtual" start/end elements, needed for handling 'unwrapped' lists.

private final int
private final int
private final int
protected String
_stateDesc(int state)

public void
public void
public JsonLocation
public int
public String
getLocalName()

Accessor for local name of current named event (that is, XML_START_ELEMENT or XML_ATTRIBUTE_NAME).

public String
public String
public JsonLocation
public XMLStreamReader2
public boolean
public int
initialize()

Second part of initialization, to be called immediately after construction

public int
next()

protected void
pushbackCurrentToken()

Method that can be called to ask stream to literally just return current token with the next call to next(), without more work.

protected void
repeatStartElement()

Method used to add virtual wrapping, which just duplicates START_ELEMENT stream points to, and its matching closing element.

protected void
protected void
skipAttributes()

Method called to skip any attributes current START_ELEMENT may have, so that they are not returned as token.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_attributeCountback to summary
protected int _attributeCount
_cfgProcessXsiNilback to summary
protected boolean _cfgProcessXsiNil
_cfgProcessXsiTypeback to summary
protected boolean _cfgProcessXsiType
_currentStateback to summary
protected int _currentState
_currentWrapperback to summary
protected ElementWrapper _currentWrapper

Wrapping state, if any active (null if none)

_formatFeaturesback to summary
protected int _formatFeatures

Bit flag composed of bits that indicate which FromXmlParser.Features are enabled.

_localNameback to summary
protected String _localName
_nameProcessorback to summary
protected XmlNameProcessor _nameProcessor
_namespaceURIback to summary
protected String _namespaceURI
_nameToDecodeback to summary
protected XmlNameProcessor.XmlName _nameToDecode

Reusable internal value object

Since
2.14
_nextAttributeIndexback to summary
protected int _nextAttributeIndex

Index of the next attribute of the current START_ELEMENT to return (as field name and value pair), if any; -1 when no attributes to return

_nextLocalNameback to summary
protected String _nextLocalName

In cases where we need to 'inject' a virtual END_ELEMENT, we may also need to restore START_ELEMENT afterwards; if so, this is where names are held.

_nextNamespaceURIback to summary
protected String _nextNamespaceURI
_repeatCurrentTokenback to summary
protected boolean _repeatCurrentToken

Marker flag set if caller wants to "push back" current token so that next call to next() should simply be given what was already read.

Since
2.12
_repeatElementback to summary
protected int _repeatElement

Flag used to indicate that given element should be "replayed".

_sourceReferenceback to summary
protected final ContentReference _sourceReference
_startElementAfterTextback to summary
protected boolean _startElementAfterText

Flag set true if current event is XML_TEXT and there is START_ELEMENT

Since
2.12
_textValueback to summary
protected String _textValue

Current text value for TEXT_VALUE returned

_xmlReaderback to summary
protected final XMLStreamReader2 _xmlReader
_xsiNilFoundback to summary
protected boolean _xsiNilFound

Marker used to indicate presence of `xsi:nil="true"' in current START_ELEMENT.

Since
2.10
REPLAY_ENDback to summary
private static final int REPLAY_END
REPLAY_START_DELAYEDback to summary
private static final int REPLAY_START_DELAYED
REPLAY_START_DUPback to summary
private static final int REPLAY_START_DUP
XML_ATTRIBUTE_NAMEback to summary
public static final int XML_ATTRIBUTE_NAME
XML_ATTRIBUTE_VALUEback to summary
public static final int XML_ATTRIBUTE_VALUE
XML_ENDback to summary
public static final int XML_END
XML_END_ELEMENTback to summary
public static final int XML_END_ELEMENT
XML_ROOT_TEXTback to summary
public static final int XML_ROOT_TEXT
XML_START_ELEMENTback to summary
public static final int XML_START_ELEMENT
XML_TEXTback to summary
public static final int XML_TEXT
XSI_NAMESPACEback to summary
private static final String XSI_NAMESPACE

Constructor Detail

XmlTokenStreamback to summary
public XmlTokenStream(XMLStreamReader xmlReader, ContentReference sourceRef, int formatFeatures, XmlNameProcessor nameProcessor)

Method Detail

_allWsback to summary
protected static boolean _allWs(String str)
_checkXsiAttributesback to summary
private final void _checkXsiAttributes()
Since
2.10
_collectUntilTagback to summary
private final String _collectUntilTag() throws XMLStreamException
Returns:String

Collected text, if any, EXCEPT that if FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL AND empty element, returns null

_currentStateDescback to summary
protected String _currentStateDesc()
_decodeAttributeNameback to summary
protected void _decodeAttributeName(String namespaceURI, String localName)
Since
2.14
_decodeElementNameback to summary
protected void _decodeElementName(String namespaceURI, String localName)
Since
2.14
_extractLocationback to summary
private JsonLocation _extractLocation(XMLStreamLocation2 location)
_getTextback to summary
private final String _getText(XMLStreamReader2 r) throws XMLStreamException
_handleEndElementback to summary
private final int _handleEndElement()
_handleRepeatElementback to summary
protected int _handleRepeatElement() throws XMLStreamException

Method called to handle details of repeating "virtual" start/end elements, needed for handling 'unwrapped' lists.

_initStartElementback to summary
private final int _initStartElement() throws XMLStreamException
_nextback to summary
private final int _next() throws XMLStreamException
_skipAndCollectTextUntilTagback to summary
private final int _skipAndCollectTextUntilTag() throws XMLStreamException
_stateDescback to summary
protected String _stateDesc(int state)
closeback to summary
public void close() throws XMLStreamException
closeCompletelyback to summary
public void closeCompletely() throws XMLStreamException
getCurrentLocationback to summary
public JsonLocation getCurrentLocation()
getCurrentTokenback to summary
public int getCurrentToken()
getLocalNameback to summary
public String getLocalName()

Accessor for local name of current named event (that is, XML_START_ELEMENT or XML_ATTRIBUTE_NAME).

Note

name NOT accessible on XML_END_ELEMENT

getNamespaceURIback to summary
public String getNamespaceURI()
getTextback to summary
public String getText()
getTokenLocationback to summary
public JsonLocation getTokenLocation()
getXmlReaderback to summary
public XMLStreamReader2 getXmlReader()
hasXsiNilback to summary
public boolean hasXsiNil()
initializeback to summary
public int initialize() throws XMLStreamException

Second part of initialization, to be called immediately after construction

Since
2.12
nextback to summary
public int next() throws XMLStreamException
pushbackCurrentTokenback to summary
protected void pushbackCurrentToken()

Method that can be called to ask stream to literally just return current token with the next call to next(), without more work.

Since
2.12
repeatStartElementback to summary
protected void repeatStartElement()

Method used to add virtual wrapping, which just duplicates START_ELEMENT stream points to, and its matching closing element.

setFormatFeaturesback to summary
protected void setFormatFeatures(int f)
Since
2.9
skipAttributesback to summary
protected void skipAttributes()

Method called to skip any attributes current START_ELEMENT may have, so that they are not returned as token.

Since
2.1
skipEndElementback to summary
public void skipEndElement() throws IOException, XMLStreamException