Class XmlTokenStream
- java.lang.Object
-
- com.fasterxml.jackson.dataformat.xml.deser.XmlTokenStream
-
public class XmlTokenStream extends java.lang.Object
Simple helper class used on top of STAXXMLStreamReader
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
Fields Modifier and Type Field Description protected int
_attributeCount
protected boolean
_cfgProcessXsiNil
protected boolean
_cfgProcessXsiType
protected int
_currentState
protected ElementWrapper
_currentWrapper
Wrapping state, if any active (null if none)protected int
_formatFeatures
Bit flag composed of bits that indicate whichFromXmlParser.Feature
s are enabled.protected java.lang.String
_localName
protected XmlNameProcessor
_nameProcessor
protected java.lang.String
_namespaceURI
protected XmlNameProcessor.XmlName
_nameToDecode
Reusable internal value objectprotected 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 returnprotected java.lang.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 java.lang.String
_nextNamespaceURI
protected boolean
_repeatCurrentToken
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
_repeatElement
Flag used to indicate that given element should be "replayed".protected com.fasterxml.jackson.core.io.ContentReference
_sourceReference
protected boolean
_startElementAfterText
Flag set true if current event isXML_TEXT
and there is START_ELEMENTprotected java.lang.String
_textValue
Current text value for TEXT_VALUE returnedprotected org.codehaus.stax2.XMLStreamReader2
_xmlReader
protected boolean
_xsiNilFound
Marker used to indicate presence of `xsi:nil="true"' in current START_ELEMENT.private static int
REPLAY_END
private static int
REPLAY_START_DELAYED
private static int
REPLAY_START_DUP
static int
XML_ATTRIBUTE_NAME
static int
XML_ATTRIBUTE_VALUE
static int
XML_END
static int
XML_END_ELEMENT
static int
XML_ROOT_TEXT
static int
XML_START_ELEMENT
static int
XML_TEXT
private static java.lang.String
XSI_NAMESPACE
-
Constructor Summary
Constructors Constructor Description XmlTokenStream(javax.xml.stream.XMLStreamReader xmlReader, com.fasterxml.jackson.core.io.ContentReference sourceRef, int formatFeatures, XmlNameProcessor nameProcessor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static boolean
_allWs(java.lang.String str)
private void
_checkXsiAttributes()
private java.lang.String
_collectUntilTag()
protected java.lang.String
_currentStateDesc()
protected void
_decodeAttributeName(java.lang.String namespaceURI, java.lang.String localName)
protected void
_decodeElementName(java.lang.String namespaceURI, java.lang.String localName)
private com.fasterxml.jackson.core.JsonLocation
_extractLocation(org.codehaus.stax2.XMLStreamLocation2 location)
private java.lang.String
_getText(org.codehaus.stax2.XMLStreamReader2 r)
private int
_handleEndElement()
protected int
_handleRepeatElement()
Method called to handle details of repeating "virtual" start/end elements, needed for handling 'unwrapped' lists.private int
_initStartElement()
private int
_next()
private int
_skipAndCollectTextUntilTag()
protected java.lang.String
_stateDesc(int state)
void
close()
void
closeCompletely()
com.fasterxml.jackson.core.JsonLocation
getCurrentLocation()
int
getCurrentToken()
java.lang.String
getLocalName()
Accessor for local name of current named event (that is,XML_START_ELEMENT
orXML_ATTRIBUTE_NAME
).java.lang.String
getNamespaceURI()
java.lang.String
getText()
com.fasterxml.jackson.core.JsonLocation
getTokenLocation()
org.codehaus.stax2.XMLStreamReader2
getXmlReader()
boolean
hasXsiNil()
int
initialize()
Second part of initialization, to be called immediately after constructionint
next()
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.protected void
repeatStartElement()
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
skipAttributes()
Method called to skip any attributes current START_ELEMENT may have, so that they are not returned as token.void
skipEndElement()
-
-
-
Field Detail
-
XML_START_ELEMENT
public static final int XML_START_ELEMENT
- See Also:
- Constant Field Values
-
XML_END_ELEMENT
public static final int XML_END_ELEMENT
- See Also:
- Constant Field Values
-
XML_ATTRIBUTE_NAME
public static final int XML_ATTRIBUTE_NAME
- See Also:
- Constant Field Values
-
XML_ATTRIBUTE_VALUE
public static final int XML_ATTRIBUTE_VALUE
- See Also:
- Constant Field Values
-
XML_TEXT
public static final int XML_TEXT
- See Also:
- Constant Field Values
-
XML_ROOT_TEXT
public static final int XML_ROOT_TEXT
- See Also:
- Constant Field Values
-
XML_END
public static final int XML_END
- See Also:
- Constant Field Values
-
REPLAY_START_DUP
private static final int REPLAY_START_DUP
- See Also:
- Constant Field Values
-
REPLAY_END
private static final int REPLAY_END
- See Also:
- Constant Field Values
-
REPLAY_START_DELAYED
private static final int REPLAY_START_DELAYED
- See Also:
- Constant Field Values
-
XSI_NAMESPACE
private static final java.lang.String XSI_NAMESPACE
- See Also:
- Constant Field Values
-
_xmlReader
protected final org.codehaus.stax2.XMLStreamReader2 _xmlReader
-
_sourceReference
protected final com.fasterxml.jackson.core.io.ContentReference _sourceReference
-
_formatFeatures
protected int _formatFeatures
Bit flag composed of bits that indicate whichFromXmlParser.Feature
s are enabled.
-
_cfgProcessXsiNil
protected boolean _cfgProcessXsiNil
-
_cfgProcessXsiType
protected boolean _cfgProcessXsiType
-
_nameProcessor
protected XmlNameProcessor _nameProcessor
-
_currentState
protected int _currentState
-
_attributeCount
protected int _attributeCount
-
_xsiNilFound
protected boolean _xsiNilFound
Marker used to indicate presence of `xsi:nil="true"' in current START_ELEMENT.- Since:
- 2.10
-
_startElementAfterText
protected boolean _startElementAfterText
Flag set true if current event isXML_TEXT
and there is START_ELEMENT- Since:
- 2.12
-
_nextAttributeIndex
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
-
_localName
protected java.lang.String _localName
-
_namespaceURI
protected java.lang.String _namespaceURI
-
_textValue
protected java.lang.String _textValue
Current text value for TEXT_VALUE returned
-
_repeatCurrentToken
protected boolean _repeatCurrentToken
Marker 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
protected XmlNameProcessor.XmlName _nameToDecode
Reusable internal value object- Since:
- 2.14
-
_repeatElement
protected int _repeatElement
Flag used to indicate that given element should be "replayed".
-
_currentWrapper
protected ElementWrapper _currentWrapper
Wrapping state, if any active (null if none)
-
_nextLocalName
protected java.lang.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.
-
_nextNamespaceURI
protected java.lang.String _nextNamespaceURI
-
-
Constructor Detail
-
XmlTokenStream
public XmlTokenStream(javax.xml.stream.XMLStreamReader xmlReader, com.fasterxml.jackson.core.io.ContentReference sourceRef, int formatFeatures, XmlNameProcessor nameProcessor)
-
-
Method Detail
-
initialize
public int initialize() throws javax.xml.stream.XMLStreamException
Second part of initialization, to be called immediately after construction- Throws:
javax.xml.stream.XMLStreamException
- Since:
- 2.12
-
getXmlReader
public org.codehaus.stax2.XMLStreamReader2 getXmlReader()
-
setFormatFeatures
protected void setFormatFeatures(int f)
- Since:
- 2.9
-
next
public int next() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
skipEndElement
public void skipEndElement() throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
getCurrentToken
public int getCurrentToken()
-
getText
public java.lang.String getText()
-
getLocalName
public java.lang.String 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
public java.lang.String getNamespaceURI()
-
hasXsiNil
public boolean hasXsiNil()
-
closeCompletely
public void closeCompletely() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
close
public void close() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.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
private final int _next() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_collectUntilTag
private final java.lang.String _collectUntilTag() throws javax.xml.stream.XMLStreamException
- Returns:
- Collected text, if any, EXCEPT that if
FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL
AND empty element, returnsnull
- Throws:
javax.xml.stream.XMLStreamException
-
_skipAndCollectTextUntilTag
private final int _skipAndCollectTextUntilTag() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_getText
private final java.lang.String _getText(org.codehaus.stax2.XMLStreamReader2 r) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_initStartElement
private final int _initStartElement() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
_checkXsiAttributes
private final void _checkXsiAttributes()
- Since:
- 2.10
-
_decodeElementName
protected void _decodeElementName(java.lang.String namespaceURI, java.lang.String localName)
- Since:
- 2.14
-
_decodeAttributeName
protected void _decodeAttributeName(java.lang.String namespaceURI, java.lang.String localName)
- Since:
- 2.14
-
_handleRepeatElement
protected int _handleRepeatElement() throws javax.xml.stream.XMLStreamException
Method called to handle details of repeating "virtual" start/end elements, needed for handling 'unwrapped' lists.- Throws:
javax.xml.stream.XMLStreamException
-
_handleEndElement
private final int _handleEndElement()
-
_extractLocation
private com.fasterxml.jackson.core.JsonLocation _extractLocation(org.codehaus.stax2.XMLStreamLocation2 location)
-
_allWs
protected static boolean _allWs(java.lang.String str)
-
_currentStateDesc
protected java.lang.String _currentStateDesc()
-
_stateDesc
protected java.lang.String _stateDesc(int state)
-
-