KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > validate > jarv > VerifierValidator


1 package com.thaiopensource.validate.jarv;
2
3 import com.thaiopensource.util.PropertyMap;
4 import com.thaiopensource.validate.ValidateProperty;
5 import com.thaiopensource.validate.Validator;
6 import org.iso_relax.verifier.Verifier;
7 import org.xml.sax.ContentHandler JavaDoc;
8 import org.xml.sax.DTDHandler JavaDoc;
9 import org.xml.sax.EntityResolver JavaDoc;
10 import org.xml.sax.SAXException JavaDoc;
11 import org.xml.sax.helpers.DefaultHandler JavaDoc;
12
13 public class VerifierValidator implements Validator {
14   private final Verifier verifier;
15   private ContentHandler JavaDoc handler;
16
17   private static class ExceptionReportHandler extends DefaultHandler JavaDoc {
18     private final SAXException JavaDoc storedException;
19
20     ExceptionReportHandler(SAXException JavaDoc storedException) {
21       this.storedException = storedException;
22     }
23
24     public void startDocument()
25             throws SAXException JavaDoc {
26       throw storedException;
27     }
28   }
29
30   public VerifierValidator(Verifier verifier, PropertyMap properties) {
31     this.verifier = verifier;
32     verifier.setErrorHandler(ValidateProperty.ERROR_HANDLER.get(properties));
33     EntityResolver JavaDoc er = ValidateProperty.ENTITY_RESOLVER.get(properties);
34     if (er != null)
35       verifier.setEntityResolver(er);
36     try {
37       handler = verifier.getVerifierHandler();
38     }
39     catch (SAXException JavaDoc e) {
40       handler = new ExceptionReportHandler(e);
41     }
42   }
43
44   public void reset() {
45     try {
46       handler = verifier.getVerifierHandler();
47     }
48     catch (SAXException JavaDoc e) {
49       handler = new ExceptionReportHandler(e);
50     }
51   }
52
53   public ContentHandler JavaDoc getContentHandler() {
54     return handler;
55   }
56
57   public DTDHandler JavaDoc getDTDHandler() {
58     return null;
59   }
60 }
61
Popular Tags