KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > resolver > readers > SAXParserHandler


1 // SAXParserHandler.java - An entity-resolving DefaultHandler
2

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

19
20 package com.sun.org.apache.xml.internal.resolver.readers;
21
22 import java.io.IOException JavaDoc;
23
24 import org.xml.sax.*;
25 import org.xml.sax.helpers.*;
26
27 /**
28  * An entity-resolving DefaultHandler.
29  *
30  * <p>This class provides a SAXParser DefaultHandler that performs
31  * entity resolution.
32  * </p>
33  *
34  * @author Norman Walsh
35  * <a HREF="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
36  * @version 1.0
37  */

38 public class SAXParserHandler extends DefaultHandler {
39   private EntityResolver er = null;
40   private ContentHandler ch = null;
41
42   public SAXParserHandler() {
43     super();
44   }
45
46   public void setEntityResolver(EntityResolver er) {
47     this.er = er;
48   }
49
50   public void setContentHandler(ContentHandler ch) {
51     this.ch = ch;
52   }
53
54   // Entity Resolver
55
public InputSource resolveEntity(String JavaDoc publicId, String JavaDoc systemId)
56     throws SAXException {
57
58     if (er != null) {
59       try {
60     return er.resolveEntity(publicId, systemId);
61       } catch (IOException JavaDoc e) {
62       System.out.println("resolveEntity threw IOException!");
63       return null;
64       }
65     } else {
66       return null;
67     }
68   }
69
70   // Content Handler
71
public void characters(char[] ch, int start, int length)
72     throws SAXException {
73     if (this.ch != null) {
74       this.ch.characters(ch, start, length);
75     }
76   }
77
78   public void endDocument()
79     throws SAXException {
80     if (ch != null) {
81       ch.endDocument();
82     }
83   }
84
85   public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName)
86     throws SAXException {
87     if (ch != null) {
88       ch.endElement(namespaceURI, localName, qName);
89     }
90   }
91
92   public void endPrefixMapping(String JavaDoc prefix)
93     throws SAXException {
94     if (ch != null) {
95       ch.endPrefixMapping(prefix);
96     }
97   }
98
99   public void ignorableWhitespace(char[] ch, int start, int length)
100     throws SAXException {
101     if (this.ch != null) {
102       this.ch.ignorableWhitespace(ch, start, length);
103     }
104   }
105
106   public void processingInstruction(String JavaDoc target, String JavaDoc data)
107     throws SAXException {
108     if (ch != null) {
109       ch.processingInstruction(target, data);
110     }
111   }
112
113   public void setDocumentLocator(Locator locator) {
114     if (ch != null) {
115       ch.setDocumentLocator(locator);
116     }
117   }
118
119   public void skippedEntity(String JavaDoc name)
120     throws SAXException {
121     if (ch != null) {
122       ch.skippedEntity(name);
123     }
124   }
125
126   public void startDocument()
127     throws SAXException {
128     if (ch != null) {
129       ch.startDocument();
130     }
131   }
132
133   public void startElement(String JavaDoc namespaceURI, String JavaDoc localName,
134                String JavaDoc qName, Attributes atts)
135     throws SAXException {
136     if (ch != null) {
137       ch.startElement(namespaceURI, localName, qName, atts);
138     }
139   }
140
141   public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri)
142     throws SAXException {
143     if (ch != null) {
144       ch.startPrefixMapping(prefix, uri);
145     }
146   }
147 }
148
Popular Tags