1 16 package org.outerj.daisy.htmlcleaner; 17 18 import org.xml.sax.ContentHandler ; 19 import org.xml.sax.SAXException ; 20 import org.xml.sax.Locator ; 21 import org.xml.sax.Attributes ; 22 23 class MergeCharacterEventsHandler implements ContentHandler { 24 private ContentHandler consumer; 25 private char[] ch; 26 private int start = 0; 27 private int length = 0; 28 29 public MergeCharacterEventsHandler(ContentHandler consumer) { 30 this.consumer = consumer; 31 } 32 33 public void characters(char ch[], int start, int length) throws SAXException { 34 char[] newCh = new char[this.length + length]; 35 if (this.ch != null) 36 System.arraycopy(this.ch, this.start, newCh, 0, this.length); 37 System.arraycopy(ch, start, newCh, this.length, length); 38 this.start = 0; 39 this.length = newCh.length; 40 this.ch = newCh; 41 } 42 43 private void flushCharacters() throws SAXException { 44 if (ch != null) { 45 consumer.characters(ch, start, length); 46 ch = null; 47 start = 0; 48 length = 0; 49 } 50 } 51 52 public void endDocument() throws SAXException { 53 flushCharacters(); 54 consumer.endDocument(); 55 } 56 57 public void startDocument() throws SAXException { 58 flushCharacters(); 59 consumer.startDocument(); 60 } 61 62 public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { 63 flushCharacters(); 64 consumer.ignorableWhitespace(ch, start, length); 65 } 66 67 public void endPrefixMapping(String prefix) throws SAXException { 68 flushCharacters(); 69 consumer.endPrefixMapping(prefix); 70 } 71 72 public void skippedEntity(String name) throws SAXException { 73 flushCharacters(); 74 consumer.skippedEntity(name); 75 } 76 77 public void setDocumentLocator(Locator locator) { 78 consumer.setDocumentLocator(locator); 79 } 80 81 public void processingInstruction(String target, String data) throws SAXException { 82 flushCharacters(); 83 consumer.processingInstruction(target, data); 84 } 85 86 public void startPrefixMapping(String prefix, String uri) throws SAXException { 87 flushCharacters(); 88 consumer.startPrefixMapping(prefix, uri); 89 } 90 91 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 92 flushCharacters(); 93 consumer.endElement(namespaceURI, localName, qName); 94 } 95 96 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 97 flushCharacters(); 98 consumer.startElement(namespaceURI, localName, qName, atts); 99 } 100 } 101 | Popular Tags |