KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > htmlcleaner > MergeCharacterEventsHandler


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.htmlcleaner;
17
18 import org.xml.sax.ContentHandler JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20 import org.xml.sax.Locator JavaDoc;
21 import org.xml.sax.Attributes JavaDoc;
22
23 class MergeCharacterEventsHandler implements ContentHandler JavaDoc {
24     private ContentHandler JavaDoc consumer;
25     private char[] ch;
26     private int start = 0;
27     private int length = 0;
28
29     public MergeCharacterEventsHandler(ContentHandler JavaDoc consumer) {
30         this.consumer = consumer;
31     }
32
33     public void characters(char ch[], int start, int length) throws SAXException JavaDoc {
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 JavaDoc {
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 JavaDoc {
53         flushCharacters();
54         consumer.endDocument();
55     }
56
57     public void startDocument() throws SAXException JavaDoc {
58         flushCharacters();
59         consumer.startDocument();
60     }
61
62     public void ignorableWhitespace(char ch[], int start, int length) throws SAXException JavaDoc {
63         flushCharacters();
64         consumer.ignorableWhitespace(ch, start, length);
65     }
66
67     public void endPrefixMapping(String JavaDoc prefix) throws SAXException JavaDoc {
68         flushCharacters();
69         consumer.endPrefixMapping(prefix);
70     }
71
72     public void skippedEntity(String JavaDoc name) throws SAXException JavaDoc {
73         flushCharacters();
74         consumer.skippedEntity(name);
75     }
76
77     public void setDocumentLocator(Locator JavaDoc locator) {
78         consumer.setDocumentLocator(locator);
79     }
80
81     public void processingInstruction(String JavaDoc target, String JavaDoc data) throws SAXException JavaDoc {
82         flushCharacters();
83         consumer.processingInstruction(target, data);
84     }
85
86     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri) throws SAXException JavaDoc {
87         flushCharacters();
88         consumer.startPrefixMapping(prefix, uri);
89     }
90
91     public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
92         flushCharacters();
93         consumer.endElement(namespaceURI, localName, qName);
94     }
95
96     public void startElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts) throws SAXException JavaDoc {
97         flushCharacters();
98         consumer.startElement(namespaceURI, localName, qName, atts);
99     }
100 }
101
Popular Tags