/** * Throws a new IO exception with the given message and a context snippet with this reader's * content. */ private IOException syntaxError(String message) throws IOException { throw new IOException(message + " at path " + getPath()); }
/** * Returns the index of the last character before starting the CDATA closing tag "{@code ]]>}". * This method does not consume the closing CDATA tag. * * @return index of last character before closing tag. * @throws IOException */ private long indexOfClosingCDATA() throws IOException { long index = source.indexOf(CDATA_CLOSE); if (index == -1) { throw new EOFException("<![CDATA[ at " + getPath() + " has never been closed with ]]>"); } return index; }
/** * Consumes the next token from the JSON stream and asserts that it is the beginning of a new * object. */ public void beginElement() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_ELEMENT_BEGIN) { pushStack(XmlScope.ELEMENT_OPENING); peeked = PEEKED_NONE; } else { throw new XmlDataException("Expected " + XmlToken.ELEMENT_BEGIN + " but was " + peek() + " at path " + getPath()); } }
/** * Skip the value of an attribute if you don't want to read the value. {@link * #nextAttributeName()} must be called before invoking this method * * @throws IOException */ public void skipAttributeValue() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_DOUBLE_QUOTED || p == PEEKED_SINGLE_QUOTED) { peeked = PEEKED_NONE; pathNames[stackSize - 1] = null; // Remove attribute name from stack skipQuotedValue(p == PEEKED_DOUBLE_QUOTED ? DOUBLE_QUOTE : SINGLE_QUOTE); } else { throw new XmlDataException( "Expected xml element attribute value (in double quotes or single quotes) but was " + peek() + " at path " + getPath()); } }
/** * Consumes the next attribute's value. Assumes that {@link #nextAttributeName()} has been called * before invoking this method * * @return The value of the attribute as string */ public String nextAttributeValue() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_DOUBLE_QUOTED || p == PEEKED_SINGLE_QUOTED) { String attributeValue = nextQuotedValue(p == PEEKED_DOUBLE_QUOTED ? DOUBLE_QUOTE : SINGLE_QUOTE); peeked = PEEKED_NONE; pathNames[stackSize - 1] = null; // Remove attribute name from stack, do that after nextQuotedValue() to ensure that xpath is correctly in case that nextQuotedValue() fails return attributeValue; } else { throw new XmlDataException( "Expected xml element attribute value (in double quotes or single quotes) but was " + peek() + " at path " + getPath()); } }
+ attributeName + "' at path " + reader.getPath() + " to java class. Have you annotated such a field in your java class to map this xml attribute? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build()."); } else { + elementName + "' at path " + reader.getPath() + " to java class. Have you annotated such a field in your java class to map this xml element? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build()."); } else { if (config.exceptionOnUnreadXml()) { throw new IOException("Could not map the xml element's text content at path at path " + reader.getPath() + " to java class. Have you annotated such a field in your java class to map the xml element's text content? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build()."); } else {
+ attributeName + "' at path " + reader.getPath() + "to java class. Have you annotated such a field in your java class to map this xml attribute? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build()."); } else { + elementName + "' at path " + reader.getPath() + " to java class. Have you annotated such a field in your java class to map this xml element? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build()."); } else { if (config.exceptionOnUnreadXml()) { throw new IOException("Could not map the xml element's text content at path at path " + reader.getPath() + " to java class. Have you annotated such a field in your java class to map the xml element's text content? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build()."); } else {
reader.beginElement(); reader.nextElementName(); Assert.assertEquals("/element", reader.getPath()); Assert.assertEquals("/element[@a]", reader.getPath()); reader.nextAttributeValue(); Assert.assertEquals("/element", reader.getPath()); Assert.assertEquals("/element[@b]", reader.getPath()); Assert.assertEquals("/element", reader.getPath()); Assert.assertEquals("/element/text()", reader.getPath()); Assert.assertEquals("/element/bar", reader.getPath()); reader.nextAttributeName(); Assert.assertEquals("/element/bar[@a]", reader.getPath()); reader.nextAttributeValue(); Assert.assertEquals("/element/bar", reader.getPath()); reader.endElement(); Assert.assertEquals("/element/text()", reader.getPath()); reader.endElement(); Assert.assertEquals("/", reader.getPath()); } finally { reader.close();
case 'u': if (!fillBuffer(4)) { throw new EOFException("Unterminated escape sequence at path " + getPath());
/** * Skip the text content. Text content is {@code <element>text content</element>} * * @throws IOException */ public void skipTextContent() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_ELEMENT_TEXT_CONTENT) { peeked = PEEKED_NONE; // Read text until '<' found long index = source.indexOf(OPENING_XML_ELEMENT); if (index == -1L) { throw syntaxError("Unterminated element text content. Expected </" + pathNames[stackSize - 1] + "> but haven't found"); } buffer.skip(index); } else if (p == PEEKED_CDATA) { peeked = PEEKED_NONE; // Search index of closing CDATA tag ]]> long index = indexOfClosingCDATA(); buffer.skip(index + 3); // +3 because of consuming closing tag } else { throw new XmlDataException("Expected xml element text content but was " + peek() + " at path " + getPath()); } }
} else { throw new XmlDataException("Expected xml element text content but was " + peek() + " at path " + getPath());
throw new EOFException("Unexpected end of input at path " + getPath()); } else { return -1;