KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > publisher > impl > dataretrieval > PreparedDocumentsExtractor


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.books.publisher.impl.dataretrieval;
17
18 import org.xml.sax.ContentHandler JavaDoc;
19 import org.xml.sax.Attributes JavaDoc;
20 import org.xml.sax.SAXException JavaDoc;
21 import org.xml.sax.Locator JavaDoc;
22
23 /**
24  * A handler whose purpose is to only let through the /p:publisherResponse/p:document/p:preparedDocuments element.
25  * Currently rather rough implemented, but should work just fine as long as the input format is OK.
26  */

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