Class XmlTokenStream
java.lang.Object
com.fasterxml.jackson.dataformat.xml.deser.XmlTokenStream
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
FieldsModifier and TypeFieldDescriptionprotected int
protected boolean
protected boolean
protected int
protected ElementWrapper
Wrapping state, if any active (null if none)protected int
Bit flag composed of bits that indicate whichFromXmlParser.Feature
s are enabled.protected String
protected XmlNameProcessor
protected String
protected XmlNameProcessor.XmlName
Reusable internal value objectprotected int
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 returnprotected String
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
Marker flag set if caller wants to "push back" current token so that next call tonext()
should simply be given what was already read.protected int
Flag used to indicate that given element should be "replayed".protected final com.fasterxml.jackson.core.io.ContentReference
protected boolean
Flag set true if current event isXML_TEXT
and there is START_ELEMENTprotected String
Current text value for TEXT_VALUE returnedprotected final org.codehaus.stax2.XMLStreamReader2
protected boolean
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
static final int
static final int
static final int
static final int
static final int
static final int
static final int
private static final String
-
Constructor Summary
ConstructorsConstructorDescriptionXmlTokenStream
(XMLStreamReader xmlReader, com.fasterxml.jackson.core.io.ContentReference sourceRef, int formatFeatures, XmlNameProcessor nameProcessor) -
Method Summary
Modifier and TypeMethodDescriptionprotected static boolean
private final void
private final String
protected String
protected void
_decodeAttributeName
(String namespaceURI, String localName) protected void
_decodeElementName
(String namespaceURI, String localName) private com.fasterxml.jackson.core.JsonLocation
_extractLocation
(org.codehaus.stax2.XMLStreamLocation2 location) private final String
_getText
(org.codehaus.stax2.XMLStreamReader2 r) private final int
protected int
Method called to handle details of repeating "virtual" start/end elements, needed for handling 'unwrapped' lists.private final int
private final int
_next()
private final int
protected String
_stateDesc
(int state) void
close()
void
com.fasterxml.jackson.core.JsonLocation
int
Accessor for local name of current named event (that is,XML_START_ELEMENT
orXML_ATTRIBUTE_NAME
).getText()
com.fasterxml.jackson.core.JsonLocation
org.codehaus.stax2.XMLStreamReader2
boolean
int
Second part of initialization, to be called immediately after constructionint
next()
protected void
Method that can be called to ask stream to literally just return current token with the next call tonext()
, without more work.protected void
Method used to add virtual wrapping, which just duplicates START_ELEMENT stream points to, and its matching closing element.protected void
setFormatFeatures
(int f) protected void
Method called to skip any attributes current START_ELEMENT may have, so that they are not returned as token.void
-
Field Details
-
XML_START_ELEMENT
public static final int XML_START_ELEMENT- See Also:
-
XML_END_ELEMENT
public static final int XML_END_ELEMENT- See Also:
-
XML_ATTRIBUTE_NAME
public static final int XML_ATTRIBUTE_NAME- See Also:
-
XML_ATTRIBUTE_VALUE
public static final int XML_ATTRIBUTE_VALUE- See Also:
-
XML_TEXT
public static final int XML_TEXT- See Also:
-
XML_ROOT_TEXT
public static final int XML_ROOT_TEXT- See Also:
-
XML_END
public static final int XML_END- See Also:
-
REPLAY_START_DUP
private static final int REPLAY_START_DUP- See Also:
-
REPLAY_END
private static final int REPLAY_END- See Also:
-
REPLAY_START_DELAYED
private static final int REPLAY_START_DELAYED- See Also:
-
XSI_NAMESPACE
- See Also:
-
_xmlReader
protected final org.codehaus.stax2.XMLStreamReader2 _xmlReader -
_sourceReference
protected final com.fasterxml.jackson.core.io.ContentReference _sourceReference -
_formatFeatures
protected int _formatFeaturesBit flag composed of bits that indicate whichFromXmlParser.Feature
s are enabled. -
_cfgProcessXsiNil
protected boolean _cfgProcessXsiNil -
_cfgProcessXsiType
protected boolean _cfgProcessXsiType -
_nameProcessor
-
_currentState
protected int _currentState -
_attributeCount
protected int _attributeCount -
_xsiNilFound
protected boolean _xsiNilFoundMarker used to indicate presence of `xsi:nil="true"' in current START_ELEMENT.- Since:
- 2.10
-
_startElementAfterText
protected boolean _startElementAfterTextFlag set true if current event isXML_TEXT
and there is START_ELEMENT- Since:
- 2.12
-
_nextAttributeIndex
protected int _nextAttributeIndexIndex 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 -
_localName
-
_namespaceURI
-
_textValue
Current text value for TEXT_VALUE returned -
_repeatCurrentToken
protected boolean _repeatCurrentTokenMarker flag set if caller wants to "push back" current token so that next call tonext()
should simply be given what was already read.- Since:
- 2.12
-
_nameToDecode
Reusable internal value object- Since:
- 2.14
-
_repeatElement
protected int _repeatElementFlag used to indicate that given element should be "replayed". -
_currentWrapper
Wrapping state, if any active (null if none) -
_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. -
_nextNamespaceURI
-
-
Constructor Details
-
XmlTokenStream
public XmlTokenStream(XMLStreamReader xmlReader, com.fasterxml.jackson.core.io.ContentReference sourceRef, int formatFeatures, XmlNameProcessor nameProcessor)
-
-
Method Details
-
initialize
Second part of initialization, to be called immediately after construction- Throws:
XMLStreamException
- Since:
- 2.12
-
getXmlReader
public org.codehaus.stax2.XMLStreamReader2 getXmlReader() -
setFormatFeatures
protected void setFormatFeatures(int f) - Since:
- 2.9
-
next
- Throws:
XMLStreamException
-
skipEndElement
- Throws:
IOException
XMLStreamException
-
getCurrentToken
public int getCurrentToken() -
getText
-
getLocalName
Accessor for local name of current named event (that is,XML_START_ELEMENT
orXML_ATTRIBUTE_NAME
).NOTE: name NOT accessible on
XML_END_ELEMENT
-
getNamespaceURI
-
hasXsiNil
public boolean hasXsiNil() -
closeCompletely
- Throws:
XMLStreamException
-
close
- Throws:
XMLStreamException
-
getCurrentLocation
public com.fasterxml.jackson.core.JsonLocation getCurrentLocation() -
getTokenLocation
public com.fasterxml.jackson.core.JsonLocation getTokenLocation() -
repeatStartElement
protected void repeatStartElement()Method used to add virtual wrapping, which just duplicates START_ELEMENT stream points to, and its matching closing element. -
pushbackCurrentToken
protected void pushbackCurrentToken()Method that can be called to ask stream to literally just return current token with the next call tonext()
, without more work.- Since:
- 2.12
-
skipAttributes
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
-
_next
- Throws:
XMLStreamException
-
_collectUntilTag
- Returns:
- Collected text, if any, EXCEPT that if
FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL
AND empty element, returnsnull
- Throws:
XMLStreamException
-
_skipAndCollectTextUntilTag
- Throws:
XMLStreamException
-
_getText
- Throws:
XMLStreamException
-
_initStartElement
- Throws:
XMLStreamException
-
_checkXsiAttributes
private final void _checkXsiAttributes()- Since:
- 2.10
-
_decodeElementName
- Since:
- 2.14
-
_decodeAttributeName
- Since:
- 2.14
-
_handleRepeatElement
Method called to handle details of repeating "virtual" start/end elements, needed for handling 'unwrapped' lists.- Throws:
XMLStreamException
-
_handleEndElement
private final int _handleEndElement() -
_extractLocation
private com.fasterxml.jackson.core.JsonLocation _extractLocation(org.codehaus.stax2.XMLStreamLocation2 location) -
_allWs
-
_currentStateDesc
-
_stateDesc
-