001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.relaxng;
031:
032: import com.caucho.xml.Xml;
033:
034: import org.xml.sax.*;
035: import org.xml.sax.helpers.DefaultHandler;
036:
037: import java.io.IOException;
038:
039: /**
040: * JARV verifier implementation
041: */
042: public class VerifierFilter extends DefaultHandler {
043: private Xml _xml;
044:
045: private Verifier _verifier;
046: private VerifierHandler _verifierHandler;
047:
048: private ContentHandler _contentHandler;
049: private ErrorHandler _errorHandler;
050:
051: public VerifierFilter(Verifier verifier) {
052: _verifier = verifier;
053: _verifierHandler = verifier.getVerifierHandler();
054: }
055:
056: public void setParent(Xml xml) {
057: _xml = xml;
058: }
059:
060: public void setContentHandler(ContentHandler handler) {
061: _contentHandler = handler;
062: }
063:
064: public void setErrorHandler(ErrorHandler handler) {
065: _errorHandler = handler;
066:
067: _verifier.setErrorHandler(handler);
068: }
069:
070: public void parse(InputSource in) throws IOException, SAXException {
071: _xml.setContentHandler(this );
072: _xml.setErrorHandler(this );
073: _xml.parse(in);
074: }
075:
076: public void setDocumentLocator(Locator locator) {
077: _verifierHandler.setDocumentLocator(locator);
078:
079: if (_contentHandler != null)
080: _contentHandler.setDocumentLocator(locator);
081: }
082:
083: public void startDocument() throws SAXException {
084: _verifierHandler.startDocument();
085:
086: if (_contentHandler != null)
087: _contentHandler.startDocument();
088: }
089:
090: public void endDocument() throws SAXException {
091: _verifierHandler.endDocument();
092:
093: if (_contentHandler != null)
094: _contentHandler.endDocument();
095: }
096:
097: public void startPrefixMapping(String prefix, String uri)
098: throws SAXException {
099: _verifierHandler.startPrefixMapping(prefix, uri);
100:
101: if (_contentHandler != null)
102: _contentHandler.startPrefixMapping(prefix, uri);
103: }
104:
105: public void endPrefixMapping(String prefix) throws SAXException {
106: _verifierHandler.endPrefixMapping(prefix);
107:
108: if (_contentHandler != null)
109: _contentHandler.endPrefixMapping(prefix);
110: }
111:
112: public void startElement(String uri, String localName,
113: String qName, Attributes atts) throws SAXException {
114: _verifierHandler.startElement(uri, localName, qName, atts);
115:
116: if (_contentHandler != null)
117: _contentHandler.startElement(uri, localName, qName, atts);
118: }
119:
120: public void endElement(String uri, String localName, String qName)
121: throws SAXException {
122: _verifierHandler.endElement(uri, localName, qName);
123:
124: if (_contentHandler != null)
125: _contentHandler.endElement(uri, localName, qName);
126: }
127:
128: public void characters(char[] ch, int start, int length)
129: throws SAXException {
130: _verifierHandler.characters(ch, start, length);
131:
132: if (_contentHandler != null)
133: _contentHandler.characters(ch, start, length);
134: }
135:
136: public void ignorableWhitespace(char[] ch, int start, int length)
137: throws SAXException {
138: _verifierHandler.ignorableWhitespace(ch, start, length);
139:
140: if (_contentHandler != null)
141: _contentHandler.ignorableWhitespace(ch, start, length);
142: }
143:
144: public void processingInstruction(String target, String data)
145: throws SAXException {
146: _verifierHandler.processingInstruction(target, data);
147:
148: if (_contentHandler != null)
149: _contentHandler.processingInstruction(target, data);
150: }
151:
152: public void skippedEntity(String name) throws SAXException {
153: _verifierHandler.skippedEntity(name);
154:
155: if (_contentHandler != null)
156: _contentHandler.skippedEntity(name);
157: }
158:
159: public void error(SAXParseException e) throws SAXException {
160: if (_errorHandler != null)
161: _errorHandler.error(e);
162: else
163: _verifierHandler.error(e);
164: }
165:
166: public void fatalError(SAXParseException e) throws SAXException {
167: if (_errorHandler != null)
168: _errorHandler.fatalError(e);
169: else
170: _verifierHandler.fatalError(e);
171: }
172:
173: public void warning(SAXParseException e) throws SAXException {
174: if (_errorHandler != null)
175: _errorHandler.warning(e);
176: else
177: _verifierHandler.warning(e);
178: }
179: }
|