KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > relaxng > VerifierFilter


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.relaxng;
31
32 import com.caucho.xml.Xml;
33
34 import org.xml.sax.*;
35 import org.xml.sax.helpers.DefaultHandler JavaDoc;
36
37 import java.io.IOException JavaDoc;
38
39 /**
40  * JARV verifier implementation
41  */

42 public class VerifierFilter extends DefaultHandler JavaDoc {
43   private Xml _xml;
44   
45   private Verifier _verifier;
46   private VerifierHandler _verifierHandler;
47   
48   private ContentHandler _contentHandler;
49   private ErrorHandler _errorHandler;
50
51   public VerifierFilter(Verifier verifier)
52   {
53     _verifier = verifier;
54     _verifierHandler = verifier.getVerifierHandler();
55   }
56
57   public void setParent(Xml xml)
58   {
59     _xml = xml;
60   }
61
62   public void setContentHandler(ContentHandler handler)
63   {
64     _contentHandler = handler;
65   }
66
67   public void setErrorHandler(ErrorHandler handler)
68   {
69     _errorHandler = handler;
70
71     _verifier.setErrorHandler(handler);
72   }
73
74
75   public void parse(InputSource in)
76     throws IOException JavaDoc, SAXException
77   {
78     _xml.setContentHandler(this);
79     _xml.setErrorHandler(this);
80     _xml.parse(in);
81   }
82
83   public void setDocumentLocator(Locator locator)
84   {
85     _verifierHandler.setDocumentLocator(locator);
86
87     if (_contentHandler != null)
88       _contentHandler.setDocumentLocator(locator);
89   }
90
91   public void startDocument()
92     throws SAXException
93   {
94     _verifierHandler.startDocument();
95
96     if (_contentHandler != null)
97       _contentHandler.startDocument();
98   }
99
100   public void endDocument()
101     throws SAXException
102   {
103     _verifierHandler.endDocument();
104
105     if (_contentHandler != null)
106       _contentHandler.endDocument();
107   }
108
109   public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri)
110     throws SAXException
111   {
112     _verifierHandler.startPrefixMapping(prefix, uri);
113
114     if (_contentHandler != null)
115       _contentHandler.startPrefixMapping(prefix, uri);
116   }
117
118   public void endPrefixMapping(String JavaDoc prefix)
119     throws SAXException
120   {
121     _verifierHandler.endPrefixMapping(prefix);
122
123     if (_contentHandler != null)
124       _contentHandler.endPrefixMapping(prefix);
125   }
126
127   public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName,
128                Attributes atts)
129     throws SAXException
130   {
131     _verifierHandler.startElement(uri, localName, qName, atts);
132
133     if (_contentHandler != null)
134       _contentHandler.startElement(uri, localName, qName, atts);
135   }
136
137   public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName)
138     throws SAXException
139   {
140     _verifierHandler.endElement(uri, localName, qName);
141
142     if (_contentHandler != null)
143       _contentHandler.endElement(uri, localName, qName);
144   }
145
146   public void characters(char []ch, int start, int length)
147     throws SAXException
148   {
149     _verifierHandler.characters(ch, start, length);
150
151     if (_contentHandler != null)
152       _contentHandler.characters(ch, start, length);
153   }
154
155   public void ignorableWhitespace(char []ch, int start, int length)
156     throws SAXException
157   {
158     _verifierHandler.ignorableWhitespace(ch, start, length);
159
160     if (_contentHandler != null)
161       _contentHandler.ignorableWhitespace(ch, start, length);
162   }
163
164   public void processingInstruction(String JavaDoc target, String JavaDoc data)
165     throws SAXException
166   {
167     _verifierHandler.processingInstruction(target, data);
168
169     if (_contentHandler != null)
170       _contentHandler.processingInstruction(target, data);
171   }
172
173   public void skippedEntity(String JavaDoc name)
174     throws SAXException
175   {
176     _verifierHandler.skippedEntity(name);
177
178     if (_contentHandler != null)
179       _contentHandler.skippedEntity(name);
180   }
181
182   public void error(SAXParseException e)
183     throws SAXException
184   {
185     if (_errorHandler != null)
186       _errorHandler.error(e);
187     else
188       _verifierHandler.error(e);
189   }
190
191   public void fatalError(SAXParseException e)
192     throws SAXException
193   {
194     if (_errorHandler != null)
195       _errorHandler.fatalError(e);
196     else
197       _verifierHandler.fatalError(e);
198   }
199
200   public void warning(SAXParseException e)
201     throws SAXException
202   {
203     if (_errorHandler != null)
204       _errorHandler.warning(e);
205     else
206       _verifierHandler.warning(e);
207   }
208 }
209
Popular Tags