/** * Indicate that we're finished parsing. * * @throws SAXException if the xml is incomplete */ /*package*/ void finish() throws SAXException { try { appendString(this.pointer, "", true); } catch (ExpatException e) { throw new ParseException(e.getMessage(), this.locator); } }
/** * Parses an XML Document from the given reader. */ /*package*/ void parseDocument(Reader in) throws IOException, SAXException { startDocument(); parseFragment(in); finish(); endDocument(); }
private void parse(Reader in, String publicId, String systemId) throws IOException, SAXException { ExpatParser parser = new ExpatParser( ExpatParser.CHARACTER_ENCODING, this, processNamespaces, publicId, systemId ); parser.parseDocument(in); }
public String getURI(int index) { if (index < 0 || index >= getLength()) { return null; } return getURI(getParserPointer(), getPointer(), index); }
public String getQName(int index) { return (index < 0 || index >= getLength()) ? null : getQName(getParserPointer(), getPointer(), index); }
public String getLocalName(int index) { return (index < 0 || index >= getLength()) ? null : getLocalName(getParserPointer(), getPointer(), index); }
/** * Appends part of an XML document. This parser will parse the given XML to * the extent possible and dispatch to the appropriate methods. * * @param xml a whole or partial snippet of XML * @param offset into the char[] * @param length of characters to use * @throws SAXException if an error occurs during parsing */ /*package*/ void append(char[] xml, int offset, int length) throws SAXException { try { appendChars(this.pointer, xml, offset, length); } catch (ExpatException e) { throw new ParseException(e.getMessage(), this.locator); } }
/** * Appends part of an XML document. This parser will parse the given XML to * the extent possible and dispatch to the appropriate methods. * * @param xml a whole or partial snippet of XML * @param offset into the byte[] * @param length of bytes to use * @throws SAXException if an error occurs during parsing */ /*package*/ void append(byte[] xml, int offset, int length) throws SAXException { try { appendBytes(this.pointer, xml, offset, length); } catch (ExpatException e) { throw new ParseException(e.getMessage(), this.locator); } }
public String getValue(int index) { return (index < 0 || index >= getLength()) ? null : getValueByIndex(getPointer(), index); }
@Override public String toString() { return "Locator[publicId: " + publicId + ", systemId: " + systemId + ", line: " + getLineNumber() + ", column: " + getColumnNumber() + "]"; } }
@Override void endElement(String uri, String localName, String qName) throws SAXException { if (--depth > 0) { super.endElement(uri, localName, qName); } }
/** * Appends part of an XML document. This parser will parse the given XML to * the extent possible and dispatch to the appropriate methods. * * @param xml a whole or partial snippet of XML * @throws SAXException if an error occurs during parsing */ /*package*/ void append(byte[] xml) throws SAXException { append(xml, 0, xml.length); }
@Override void startElement(String uri, String localName, String qName, long attributePointer, int attributeCount) throws SAXException { /* * Skip topmost element generated by our workaround in * {@link #handleExternalEntity}. */ if (depth++ > 0) { super.startElement(uri, localName, qName, attributePointer, attributeCount); } }
public String getType(int index) { return (index < 0 || index >= getLength()) ? null : CDATA; }
public String getType(String qName) { return getIndex(qName) == -1 ? null : CDATA; }
/** * Parses an XML document from the given input stream. */ /*package*/ void parseDocument(InputStream in) throws IOException, SAXException { startDocument(); parseFragment(in); finish(); endDocument(); }
/** * Appends part of an XML document. This parser will parse the given XML to * the extent possible and dispatch to the appropriate methods. * * @param xml a whole or partial snippet of XML * @throws SAXException if an error occurs during parsing */ /*package*/ void append(String xml) throws SAXException { try { appendString(this.pointer, xml, false); } catch (ExpatException e) { throw new ParseException(e.getMessage(), this.locator); } }
/** * Parses XML from the given Reader. */ private void parseFragment(Reader in) throws IOException, SAXException { char[] buffer = new char[BUFFER_SIZE / 2]; int length; while ((length = in.read(buffer)) != -1) { try { appendChars(this.pointer, buffer, 0, length); } catch (ExpatException e) { throw new ParseException(e.getMessage(), locator); } } }
/** * Parses XML from the given input stream. */ private void parseFragment(InputStream in) throws IOException, SAXException { byte[] buffer = new byte[BUFFER_SIZE]; int length; while ((length = in.read(buffer)) != -1) { try { appendBytes(this.pointer, buffer, 0, length); } catch (ExpatException e) { throw new ParseException(e.getMessage(), this.locator); } } }
private void parse(InputStream in, String charsetName, String publicId, String systemId) throws IOException, SAXException { ExpatParser parser = new ExpatParser(charsetName, this, processNamespaces, publicId, systemId); parser.parseDocument(in); }