001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.outerj.daisy.htmlcleaner;
017:
018: import org.xml.sax.ContentHandler;
019: import org.xml.sax.SAXException;
020: import org.xml.sax.Locator;
021: import org.xml.sax.Attributes;
022:
023: class MergeCharacterEventsHandler implements ContentHandler {
024: private ContentHandler consumer;
025: private char[] ch;
026: private int start = 0;
027: private int length = 0;
028:
029: public MergeCharacterEventsHandler(ContentHandler consumer) {
030: this .consumer = consumer;
031: }
032:
033: public void characters(char ch[], int start, int length)
034: throws SAXException {
035: char[] newCh = new char[this .length + length];
036: if (this .ch != null)
037: System
038: .arraycopy(this .ch, this .start, newCh, 0,
039: this .length);
040: System.arraycopy(ch, start, newCh, this .length, length);
041: this .start = 0;
042: this .length = newCh.length;
043: this .ch = newCh;
044: }
045:
046: private void flushCharacters() throws SAXException {
047: if (ch != null) {
048: consumer.characters(ch, start, length);
049: ch = null;
050: start = 0;
051: length = 0;
052: }
053: }
054:
055: public void endDocument() throws SAXException {
056: flushCharacters();
057: consumer.endDocument();
058: }
059:
060: public void startDocument() throws SAXException {
061: flushCharacters();
062: consumer.startDocument();
063: }
064:
065: public void ignorableWhitespace(char ch[], int start, int length)
066: throws SAXException {
067: flushCharacters();
068: consumer.ignorableWhitespace(ch, start, length);
069: }
070:
071: public void endPrefixMapping(String prefix) throws SAXException {
072: flushCharacters();
073: consumer.endPrefixMapping(prefix);
074: }
075:
076: public void skippedEntity(String name) throws SAXException {
077: flushCharacters();
078: consumer.skippedEntity(name);
079: }
080:
081: public void setDocumentLocator(Locator locator) {
082: consumer.setDocumentLocator(locator);
083: }
084:
085: public void processingInstruction(String target, String data)
086: throws SAXException {
087: flushCharacters();
088: consumer.processingInstruction(target, data);
089: }
090:
091: public void startPrefixMapping(String prefix, String uri)
092: throws SAXException {
093: flushCharacters();
094: consumer.startPrefixMapping(prefix, uri);
095: }
096:
097: public void endElement(String namespaceURI, String localName,
098: String qName) throws SAXException {
099: flushCharacters();
100: consumer.endElement(namespaceURI, localName, qName);
101: }
102:
103: public void startElement(String namespaceURI, String localName,
104: String qName, Attributes atts) throws SAXException {
105: flushCharacters();
106: consumer.startElement(namespaceURI, localName, qName, atts);
107: }
108: }
|