1 8 9 package javax.xml.parsers; 10 11 import java.io.File ; 12 import java.io.IOException ; 13 import java.io.InputStream ; 14 15 import javax.xml.validation.Schema ; 16 17 import org.xml.sax.HandlerBase ; 18 import org.xml.sax.InputSource ; 19 import org.xml.sax.Parser ; 20 import org.xml.sax.SAXException ; 21 import org.xml.sax.SAXNotRecognizedException ; 22 import org.xml.sax.SAXNotSupportedException ; 23 import org.xml.sax.XMLReader ; 24 import org.xml.sax.helpers.DefaultHandler ; 25 26 27 63 public abstract class SAXParser { 64 65 69 protected SAXParser () { 70 71 } 72 73 87 public void reset() { 88 89 throw new UnsupportedOperationException ( 91 "This SAXParser, \"" + this.getClass().getName() + "\", does not support the reset functionality." 92 + " Specification \"" + this.getClass().getPackage().getSpecificationTitle() + "\"" 93 + " version \"" + this.getClass().getPackage().getSpecificationVersion() + "\"" 94 ); 95 } 96 97 113 public void parse(InputStream is, HandlerBase hb) 114 throws SAXException , IOException { 115 if (is == null) { 116 throw new IllegalArgumentException ("InputStream cannot be null"); 117 } 118 119 InputSource input = new InputSource (is); 120 this.parse(input, hb); 121 } 122 123 141 public void parse( 142 InputStream is, 143 HandlerBase hb, 144 String systemId) 145 throws SAXException , IOException { 146 if (is == null) { 147 throw new IllegalArgumentException ("InputStream cannot be null"); 148 } 149 150 InputSource input = new InputSource (is); 151 input.setSystemId(systemId); 152 this.parse(input, hb); 153 } 154 155 169 public void parse(InputStream is, DefaultHandler dh) 170 throws SAXException , IOException { 171 if (is == null) { 172 throw new IllegalArgumentException ("InputStream cannot be null"); 173 } 174 175 InputSource input = new InputSource (is); 176 this.parse(input, dh); 177 } 178 179 194 public void parse( 195 InputStream is, 196 DefaultHandler dh, 197 String systemId) 198 throws SAXException , IOException { 199 if (is == null) { 200 throw new IllegalArgumentException ("InputStream cannot be null"); 201 } 202 203 InputSource input = new InputSource (is); 204 input.setSystemId(systemId); 205 this.parse(input, dh); 206 } 207 208 224 public void parse(String uri, HandlerBase hb) 225 throws SAXException , IOException { 226 if (uri == null) { 227 throw new IllegalArgumentException ("uri cannot be null"); 228 } 229 230 InputSource input = new InputSource (uri); 231 this.parse(input, hb); 232 } 233 234 248 public void parse(String uri, DefaultHandler dh) 249 throws SAXException , IOException { 250 if (uri == null) { 251 throw new IllegalArgumentException ("uri cannot be null"); 252 } 253 254 InputSource input = new InputSource (uri); 255 this.parse(input, dh); 256 } 257 258 273 public void parse(File f, HandlerBase hb) 274 throws SAXException , IOException { 275 if (f == null) { 276 throw new IllegalArgumentException ("File cannot be null"); 277 } 278 279 String uri = "file:" + f.getAbsolutePath(); 280 if (File.separatorChar == '\\') { 281 uri = uri.replace('\\', '/'); 282 } 283 InputSource input = new InputSource (uri); 284 this.parse(input, hb); 285 } 286 287 300 public void parse(File f, DefaultHandler dh) 301 throws SAXException , IOException { 302 if (f == null) { 303 throw new IllegalArgumentException ("File cannot be null"); 304 } 305 306 String uri = "file:" + f.getAbsolutePath(); 307 if (File.separatorChar == '\\') { 308 uri = uri.replace('\\', '/'); 309 } 310 InputSource input = new InputSource (uri); 311 this.parse(input, dh); 312 } 313 314 331 public void parse(InputSource is, HandlerBase hb) 332 throws SAXException , IOException { 333 if (is == null) { 334 throw new IllegalArgumentException ("InputSource cannot be null"); 335 } 336 337 Parser parser = this.getParser(); 338 if (hb != null) { 339 parser.setDocumentHandler(hb); 340 parser.setEntityResolver(hb); 341 parser.setErrorHandler(hb); 342 parser.setDTDHandler(hb); 343 } 344 parser.parse(is); 345 } 346 347 362 public void parse(InputSource is, DefaultHandler dh) 363 throws SAXException , IOException { 364 if (is == null) { 365 throw new IllegalArgumentException ("InputSource cannot be null"); 366 } 367 368 XMLReader reader = this.getXMLReader(); 369 if (dh != null) { 370 reader.setContentHandler(dh); 371 reader.setEntityResolver(dh); 372 reader.setErrorHandler(dh); 373 reader.setDTDHandler(dh); 374 } 375 reader.parse(is); 376 } 377 378 387 public abstract org.xml.sax.Parser getParser() throws SAXException ; 388 389 398 399 public abstract org.xml.sax.XMLReader getXMLReader() throws SAXException ; 400 401 408 409 public abstract boolean isNamespaceAware(); 410 411 418 419 public abstract boolean isValidating(); 420 421 438 public abstract void setProperty(String name, Object value) 439 throws SAXNotRecognizedException , SAXNotSupportedException ; 440 441 455 public abstract Object getProperty(String name) 456 throws SAXNotRecognizedException , SAXNotSupportedException ; 457 458 462 467 468 483 public Schema getSchema() { 484 throw new UnsupportedOperationException ( 485 "This parser does not support specification \"" 486 + this.getClass().getPackage().getSpecificationTitle() 487 + "\" version \"" 488 + this.getClass().getPackage().getSpecificationVersion() 489 + "\"" 490 ); 491 } 492 493 510 public boolean isXIncludeAware() { 511 throw new UnsupportedOperationException ( 512 "This parser does not support specification \"" 513 + this.getClass().getPackage().getSpecificationTitle() 514 + "\" version \"" 515 + this.getClass().getPackage().getSpecificationVersion() 516 + "\"" 517 ); 518 } 519 } 520 | Popular Tags |