KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > common > parsers > xml > TextExtractingContentHandler


1 /*
2  * Copyright 2005 Blandware (http://www.blandware.com)
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 com.blandware.atleap.common.parsers.xml;
17
18 import org.xml.sax.Attributes JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20 import org.xml.sax.helpers.DefaultHandler JavaDoc;
21
22 import java.io.IOException JavaDoc;
23 import java.io.Writer JavaDoc;
24
25 /**
26  * A content handler that is used for plain text extracting. On instantiation
27  * it is attached a <b>writer</b> that will accept the extracted text.
28  *
29  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
30  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
31  * @version $Revision: 1.2 $ $Date: 2005/07/26 14:02:00 $
32  */

33 class TextExtractingContentHandler extends DefaultHandler JavaDoc {
34     private Writer JavaDoc output;
35
36     private TextExtractingContentHandler() {}
37
38     TextExtractingContentHandler(Writer JavaDoc writer) {
39         this.output = writer;
40     }
41
42     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName,
43                              Attributes JavaDoc attributes) throws SAXException JavaDoc {
44         try {
45             output.write(' ');
46         } catch (IOException JavaDoc e) {
47             throw new SAXException JavaDoc(e);
48         }
49     }
50
51     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName)
52             throws SAXException JavaDoc {
53         try {
54             output.write(' ');
55         } catch (IOException JavaDoc e) {
56             throw new SAXException JavaDoc(e);
57         }
58     }
59
60     public void characters(char[] ch, int start, int length)
61             throws SAXException JavaDoc {
62         try {
63             output.write(ch, start, length);
64         } catch (IOException JavaDoc e) {
65             throw new SAXException JavaDoc(e);
66         }
67     }
68
69     public void ignorableWhitespace(char[] ch, int start, int length)
70             throws SAXException JavaDoc {
71         try {
72             output.write(ch, start, length);
73         } catch (IOException JavaDoc e) {
74             throw new SAXException JavaDoc(e);
75         }
76     }
77
78     public void skippedEntity(String JavaDoc name) throws SAXException JavaDoc {
79         try {
80             output.write(' ');
81         } catch (IOException JavaDoc e) {
82             throw new SAXException JavaDoc(e);
83         }
84     }
85
86     public void processingInstruction(String JavaDoc target, String JavaDoc data)
87             throws SAXException JavaDoc {
88         try {
89             output.write(' ');
90         } catch (IOException JavaDoc e) {
91             throw new SAXException JavaDoc(e);
92         }
93     }
94 }
95
Popular Tags