Skip to content

Commit

Permalink
Minor clean up, preparing to test #405
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 24, 2020
1 parent 1fdd65b commit 3001862
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public int next() throws XMLStreamException
System.out.printf(" XmlTokenStream.next(): XML_START_ELEMENT '%s' %s\n", _localName, _loc());
break;
case XML_END_ELEMENT:
System.out.printf(" XmlTokenStream.next(): XML_END_ELEMENT '%s' %s\n", _localName, _loc());
// 24-May-2020, tatu: no name available for end element so do not print
System.out.printf(" XmlTokenStream.next(): XML_END_ELEMENT %s\n", _loc());
break;
case XML_ATTRIBUTE_NAME:
System.out.printf(" XmlTokenStream.next(): XML_ATTRIBUTE_NAME '%s' %s\n", _localName, _loc());
Expand Down Expand Up @@ -219,7 +220,15 @@ public void skipEndElement() throws IOException, XMLStreamException
public int getCurrentToken() { return _currentState; }

public String getText() { return _textValue; }

/**
* Accessor for local name of current named event (that is,
* {@code XML_START_ELEMENT} or {@code XML_ATTRIBUTE_NAME}).
*<p>
* NOTE: name NOT accessible on {@code XML_END_ELEMENT}
*/
public String getLocalName() { return _localName; }

public String getNamespaceURI() { return _namespaceURI; }

public boolean hasXsiNil() {
Expand Down Expand Up @@ -509,27 +518,17 @@ private final String _getText(XMLStreamReader2 r) throws XMLStreamException
/**********************************************************************
*/

/*
_xmlReader = Stax2ReaderAdapter.wrapIfNecessary(xmlReader);
_currentState = XML_START_ELEMENT;
_localName = _xmlReader.getLocalName();
_namespaceURI = _xmlReader.getNamespaceURI();
_attributeCount = _xmlReader.getAttributeCount();
_formatFeatures = formatFeatures;
*/

private final int _initStartElement() throws XMLStreamException
{
final String ns = _xmlReader.getNamespaceURI();
final String localName = _xmlReader.getLocalName();

_checkXsiAttributes();

/* Support for virtual wrapping: in wrapping, may either
* create a new wrapper scope (if in sub-tree, or matches
* wrapper element itself), or implicitly close existing
* scope.
*/
// Support for virtual wrapping: in wrapping, may either create a new
// wrapper scope (if in sub-tree, or matches wrapper element itself),
// or implicitly close existing scope.

if (_currentWrapper != null) {
if (_currentWrapper.matchesWrapper(localName, ns)) {
_currentWrapper = _currentWrapper.intermediateWrapper();
Expand Down Expand Up @@ -631,11 +630,21 @@ private final int _handleEndElement()
//System.out.println(" XMLTokenStream._handleEndElement(): IMPLICIT requestRepeat of END_ELEMENT '"+_localName);
} else {
_currentWrapper = _currentWrapper.getParent();
// 23-May-2020, tatu: Let's clear _localName since it's value is unlikely
// to be correct and we may or may not be able to get real one (for
// END_ELEMENT could) -- FromXmlParser does NOT use this info
_localName = "";
_namespaceURI = "";

}
} else {
// Not (necessarily) known, as per above, so:
_localName = "";
_namespaceURI = "";
}
return (_currentState = XML_END_ELEMENT);
}

private JsonLocation _extractLocation(XMLStreamLocation2 location)
{
if (location == null) { // just for impls that might pass null...
Expand All @@ -647,7 +656,6 @@ private JsonLocation _extractLocation(XMLStreamLocation2 location)
location.getColumnNumber());
}


protected boolean _allWs(String str)
{
final int len = (str == null) ? 0 : str.length();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.dataformat.xml.deser;
package com.fasterxml.jackson.dataformat.xml.stream;

import java.io.*;

Expand Down Expand Up @@ -31,7 +31,10 @@ public void testSimple() throws Exception
assertEquals(XmlTokenStream.XML_TEXT, tokens.next());
assertEquals("abc", tokens.getText());
assertEquals(XmlTokenStream.XML_END_ELEMENT, tokens.next());
// 23-May-2020, tatu: Not known for END_ELEMENT, alas, so:
assertEquals("", tokens.getLocalName());
assertEquals(XmlTokenStream.XML_END_ELEMENT, tokens.next());
assertEquals("", tokens.getLocalName());
assertEquals(XmlTokenStream.XML_END, tokens.next());
}

Expand Down Expand Up @@ -124,5 +127,42 @@ public void testNested() throws Exception
assertEquals(XmlTokenStream.XML_END_ELEMENT, tokens.next());
assertEquals(XmlTokenStream.XML_END, tokens.next());
}


// For [dataformat-xml#402]
/* public void testMixedContent() throws Exception
{
String XML = "<root>first<a>123</a> and second <b>abc</b>last &amp; final</root>";
XMLStreamReader sr = _staxInputFactory.createXMLStreamReader(new StringReader(XML));
sr.nextTag();
XmlTokenStream tokens = new XmlTokenStream(sr, XML, FromXmlParser.Feature.collectDefaults());
assertEquals(XmlTokenStream.XML_START_ELEMENT, tokens.getCurrentToken());
assertEquals("root", tokens.getLocalName());
assertEquals(XmlTokenStream.XML_TEXT, tokens.next());
assertEquals("first", tokens.getText());
assertEquals(XmlTokenStream.XML_START_ELEMENT, tokens.next());
assertEquals("a", tokens.getLocalName());
assertEquals(XmlTokenStream.XML_TEXT, tokens.next());
assertEquals("123", tokens.getText());
assertEquals(XmlTokenStream.XML_END_ELEMENT, tokens.next());
assertEquals(XmlTokenStream.XML_TEXT, tokens.next());
assertEquals(" and second ", tokens.getText());
assertEquals(XmlTokenStream.XML_START_ELEMENT, tokens.next());
assertEquals("b", tokens.getLocalName());
assertEquals(XmlTokenStream.XML_TEXT, tokens.next());
assertEquals("abc", tokens.getText());
assertEquals(XmlTokenStream.XML_END_ELEMENT, tokens.next());
assertEquals(XmlTokenStream.XML_TEXT, tokens.next());
assertEquals("last & final", tokens.getText());
assertEquals(XmlTokenStream.XML_END_ELEMENT, tokens.next());
assertEquals(XmlTokenStream.XML_END, tokens.next());
sr.close();
}
*/
}

0 comments on commit 3001862

Please sign in to comment.