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 ; 8 import org.xml.sax.DTDHandler ; 9 import org.xml.sax.EntityResolver ; 10 import org.xml.sax.SAXException ; 11 import org.xml.sax.helpers.DefaultHandler ; 12 13 public class VerifierValidator implements Validator { 14 private final Verifier verifier; 15 private ContentHandler handler; 16 17 private static class ExceptionReportHandler extends DefaultHandler { 18 private final SAXException storedException; 19 20 ExceptionReportHandler(SAXException storedException) { 21 this.storedException = storedException; 22 } 23 24 public void startDocument() 25 throws SAXException { 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 er = ValidateProperty.ENTITY_RESOLVER.get(properties); 34 if (er != null) 35 verifier.setEntityResolver(er); 36 try { 37 handler = verifier.getVerifierHandler(); 38 } 39 catch (SAXException e) { 40 handler = new ExceptionReportHandler(e); 41 } 42 } 43 44 public void reset() { 45 try { 46 handler = verifier.getVerifierHandler(); 47 } 48 catch (SAXException e) { 49 handler = new ExceptionReportHandler(e); 50 } 51 } 52 53 public ContentHandler getContentHandler() { 54 return handler; 55 } 56 57 public DTDHandler getDTDHandler() { 58 return null; 59 } 60 } 61 | Popular Tags |