1 // Copyright (C) 2004, 2015 Christian Jaekl
3 package net.jaekl.qd.xml;
5 import java.util.Stack;
7 import org.xml.sax.Attributes;
8 import org.xml.sax.ContentHandler;
9 import org.xml.sax.Locator;
10 import org.xml.sax.SAXException;
12 public class ParseHandler implements ContentHandler
14 Stack<ParseResult> m_stack;
16 public ParseHandler(ParseResult root) {
17 m_stack = new Stack<ParseResult>();
22 public void characters(char[] ch, int start, int length) throws SAXException
24 if (m_stack.isEmpty()) {
29 m_stack.peek().characters(ch, start, length);
31 catch (XmlParseException xpe) {
32 throw new SAXException(xpe);
37 public void endElement(String uri, String localName, String qName) throws SAXException
40 if (m_stack.isEmpty()) {
44 boolean pop = m_stack.peek().endElement(uri, localName, qName);
48 if (m_stack.isEmpty()) {
52 m_stack.peek().endExternal(uri, localName, qName);
55 catch (XmlParseException xpe) {
56 throw new SAXException(xpe);
61 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
64 ParseResult current = m_stack.peek();
65 ParseResult next = current.startElement(uri, localName, qName, attributes);
66 if (next != current) {
70 catch (XmlParseException xpe) {
71 throw new SAXException(xpe);
76 public void endDocument() throws SAXException {
77 if (! m_stack.isEmpty()) {
78 String missingTag = m_stack.peek().getTagName();
79 throw new SAXException(new MissingInfoException(missingTag));
84 public void endPrefixMapping(String prefix) throws SAXException {
89 public void ignorableWhitespace(char[] ch, int start, int length)
96 public void processingInstruction(String target, String data)
103 public void setDocumentLocator(Locator locator) {
108 public void skippedEntity(String name) throws SAXException {
113 public void startDocument() throws SAXException {
118 public void startPrefixMapping(String prefix, String uri)