01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.xml.impl;
17:
18: import org.geotools.xml.Configuration;
19: import org.xml.sax.SAXException;
20:
21: public class StreamingParserHandler extends ParserHandler {
22:
23: /** stream buffer **/
24: Buffer buffer;
25:
26: public StreamingParserHandler(Configuration config) {
27: super (config);
28:
29: buffer = new Buffer();
30: }
31:
32: protected void endElementInternal(ElementHandler handler) {
33: super .endElementInternal(handler);
34:
35: if (stream(handler)) {
36: //throw value into buffer
37: buffer.put(handler.getParseNode().getValue());
38:
39: //remove this node from parse tree
40: if (handler.getParentHandler() instanceof ElementHandler) {
41: ElementHandler parent = (ElementHandler) handler
42: .getParentHandler();
43: ((NodeImpl) parent.getParseNode()).removeChild(handler
44: .getParseNode());
45: //parent.endChildHandler(handler);
46: }
47: }
48: }
49:
50: protected boolean stream(ElementHandler handler) {
51: return false;
52: }
53:
54: public void endDocument() throws SAXException {
55: super .endDocument();
56: buffer.close();
57: }
58:
59: public Buffer getBuffer() {
60: return buffer;
61: }
62: }
|