1 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 ; 36 37 import java.io.IOException ; 38 39 42 public class VerifierFilter extends DefaultHandler { 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 , 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 prefix, String 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 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 uri, String localName, String 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 uri, String localName, String 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 target, String 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 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 |