1 16 package org.outerj.daisy.books.publisher.impl.dataretrieval; 17 18 import org.xml.sax.ContentHandler ; 19 import org.xml.sax.Attributes ; 20 import org.xml.sax.SAXException ; 21 import org.xml.sax.Locator ; 22 23 27 public class PreparedDocumentsExtractor implements ContentHandler { 28 private int elementNesting = 0; 29 private ContentHandler consumer; 30 31 public PreparedDocumentsExtractor(ContentHandler consumer) { 32 this.consumer = consumer; 33 } 34 35 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 36 elementNesting++; 37 38 if (elementNesting > 2) 39 consumer.startElement(namespaceURI, localName, qName, atts); 40 } 41 42 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 43 if (elementNesting > 2) 44 consumer.endElement(namespaceURI, localName, qName); 45 elementNesting--; 46 } 47 48 public void endDocument() throws SAXException { 49 consumer.endDocument(); 50 } 51 52 public void startDocument() throws SAXException { 53 consumer.startDocument(); 54 } 55 56 public void characters(char ch[], int start, int length) throws SAXException { 57 if (elementNesting > 3) 58 consumer.characters(ch, start, length); 59 } 60 61 public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { 62 if (elementNesting > 3) 63 consumer.characters(ch, start, length); 64 } 65 66 public void endPrefixMapping(String prefix) throws SAXException { 67 consumer.endPrefixMapping(prefix); 68 } 69 70 public void skippedEntity(String name) throws SAXException { 71 if (elementNesting > 3) 72 consumer.skippedEntity(name); 73 } 74 75 public void setDocumentLocator(Locator locator) { 76 consumer.setDocumentLocator(locator); 77 } 78 79 public void processingInstruction(String target, String data) throws SAXException { 80 if (elementNesting > 3) 81 consumer.processingInstruction(target, data); 82 } 83 84 public void startPrefixMapping(String prefix, String uri) throws SAXException { 85 consumer.startPrefixMapping(prefix, uri); 86 } 87 } 88 | Popular Tags |