001: // SAXParserHandler.java - An entity-resolving DefaultHandler
002:
003: /*
004: * Copyright 2001-2004 The Apache Software Foundation or its licensors,
005: * as applicable.
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: package com.sun.org.apache.xml.internal.resolver.readers;
021:
022: import java.io.IOException;
023:
024: import org.xml.sax.*;
025: import org.xml.sax.helpers.*;
026:
027: /**
028: * An entity-resolving DefaultHandler.
029: *
030: * <p>This class provides a SAXParser DefaultHandler that performs
031: * entity resolution.
032: * </p>
033: *
034: * @author Norman Walsh
035: * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
036: * @version 1.0
037: */
038: public class SAXParserHandler extends DefaultHandler {
039: private EntityResolver er = null;
040: private ContentHandler ch = null;
041:
042: public SAXParserHandler() {
043: super ();
044: }
045:
046: public void setEntityResolver(EntityResolver er) {
047: this .er = er;
048: }
049:
050: public void setContentHandler(ContentHandler ch) {
051: this .ch = ch;
052: }
053:
054: // Entity Resolver
055: public InputSource resolveEntity(String publicId, String systemId)
056: throws SAXException {
057:
058: if (er != null) {
059: try {
060: return er.resolveEntity(publicId, systemId);
061: } catch (IOException e) {
062: System.out.println("resolveEntity threw IOException!");
063: return null;
064: }
065: } else {
066: return null;
067: }
068: }
069:
070: // Content Handler
071: public void characters(char[] ch, int start, int length)
072: throws SAXException {
073: if (this .ch != null) {
074: this .ch.characters(ch, start, length);
075: }
076: }
077:
078: public void endDocument() throws SAXException {
079: if (ch != null) {
080: ch.endDocument();
081: }
082: }
083:
084: public void endElement(String namespaceURI, String localName,
085: String qName) throws SAXException {
086: if (ch != null) {
087: ch.endElement(namespaceURI, localName, qName);
088: }
089: }
090:
091: public void endPrefixMapping(String prefix) throws SAXException {
092: if (ch != null) {
093: ch.endPrefixMapping(prefix);
094: }
095: }
096:
097: public void ignorableWhitespace(char[] ch, int start, int length)
098: throws SAXException {
099: if (this .ch != null) {
100: this .ch.ignorableWhitespace(ch, start, length);
101: }
102: }
103:
104: public void processingInstruction(String target, String data)
105: throws SAXException {
106: if (ch != null) {
107: ch.processingInstruction(target, data);
108: }
109: }
110:
111: public void setDocumentLocator(Locator locator) {
112: if (ch != null) {
113: ch.setDocumentLocator(locator);
114: }
115: }
116:
117: public void skippedEntity(String name) throws SAXException {
118: if (ch != null) {
119: ch.skippedEntity(name);
120: }
121: }
122:
123: public void startDocument() throws SAXException {
124: if (ch != null) {
125: ch.startDocument();
126: }
127: }
128:
129: public void startElement(String namespaceURI, String localName,
130: String qName, Attributes atts) throws SAXException {
131: if (ch != null) {
132: ch.startElement(namespaceURI, localName, qName, atts);
133: }
134: }
135:
136: public void startPrefixMapping(String prefix, String uri)
137: throws SAXException {
138: if (ch != null) {
139: ch.startPrefixMapping(prefix, uri);
140: }
141: }
142: }
|