| 1 | |
|
| 2 | |
package org.galagosearch.tupleflow.execution; |
| 3 | |
|
| 4 | |
import org.xml.sax.Attributes; |
| 5 | |
import org.xml.sax.SAXException; |
| 6 | |
import org.xml.sax.helpers.DefaultHandler; |
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | 0 | public class StackHandler extends DefaultHandler { |
| 13 | 0 | int levels = 0; |
| 14 | |
StackHandler handler; |
| 15 | |
|
| 16 | |
public void startHandler(String uri, String localName, String qName, Attributes attributes) throws SAXException { |
| 17 | 0 | } |
| 18 | |
|
| 19 | |
public void endHandler(String uri, String localName, String qName) throws SAXException { |
| 20 | 0 | } |
| 21 | |
|
| 22 | |
public void endChild(StackHandler handler, String uri, String localName, String qName) throws SAXException { |
| 23 | 0 | } |
| 24 | |
|
| 25 | |
public void unhandledStartElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { |
| 26 | 0 | } |
| 27 | |
|
| 28 | |
public void unhandledEndElement(String uri, String localName, String qName) throws SAXException { |
| 29 | 0 | } |
| 30 | |
|
| 31 | |
public void unhandledCharacters(char[] buffer, int offset, int length) throws SAXException { |
| 32 | 0 | } |
| 33 | |
|
| 34 | |
public void addHandler(StackHandler hand, String uri, String localName, String qName, Attributes attributes) throws SAXException { |
| 35 | 0 | levels = 1; |
| 36 | 0 | this.handler = hand; |
| 37 | 0 | handler.startHandler(uri, localName, qName, attributes); |
| 38 | 0 | } |
| 39 | |
|
| 40 | |
public void addHandler(StackHandler hand) throws SAXException { |
| 41 | 0 | levels = 1; |
| 42 | 0 | this.handler = hand; |
| 43 | 0 | handler.startHandler(null, null, null, null); |
| 44 | 0 | } |
| 45 | |
|
| 46 | |
public void characters(char[] buffer, int offset, int length) throws SAXException { |
| 47 | 0 | if (handler != null) { |
| 48 | 0 | handler.characters(buffer, offset, length); |
| 49 | |
} else { |
| 50 | 0 | unhandledCharacters(buffer, offset, length); |
| 51 | |
} |
| 52 | 0 | } |
| 53 | |
|
| 54 | |
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { |
| 55 | 0 | if (handler != null) { |
| 56 | 0 | levels++; |
| 57 | 0 | handler.startElement(uri, localName, qName, attributes); |
| 58 | |
} else { |
| 59 | 0 | unhandledStartElement(uri, localName, qName, attributes); |
| 60 | |
} |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
public void endElement(String uri, String localName, String qName) throws SAXException { |
| 64 | 0 | if (handler != null) { |
| 65 | 0 | levels--; |
| 66 | 0 | handler.endElement(uri, localName, qName); |
| 67 | |
|
| 68 | 0 | if (levels == 0) { |
| 69 | 0 | handler.endHandler(uri, localName, qName); |
| 70 | 0 | endChild(handler, uri, localName, qName); |
| 71 | 0 | handler = null; |
| 72 | |
} |
| 73 | |
} else { |
| 74 | 0 | unhandledEndElement(uri, localName, qName); |
| 75 | |
} |
| 76 | 0 | } |
| 77 | |
} |