All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thaiopensource.validate.jarv.VerifierValidator Maven / Gradle / Ivy

There is a newer version: 20151127.0.1
Show newest version
package com.thaiopensource.validate.jarv;

import com.thaiopensource.util.PropertyMap;
import com.thaiopensource.validate.ValidateProperty;
import com.thaiopensource.validate.Validator;
import org.iso_relax.verifier.Verifier;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class VerifierValidator implements Validator {
  private final Verifier verifier;
  private ContentHandler handler;

  private static class ExceptionReportHandler extends DefaultHandler {
    private final SAXException storedException;

    ExceptionReportHandler(SAXException storedException) {
      this.storedException = storedException;
    }

    public void startDocument()
            throws SAXException {
      throw storedException;
    }
  }

  public VerifierValidator(Verifier verifier, PropertyMap properties) {
    this.verifier = verifier;
    verifier.setErrorHandler(properties.get(ValidateProperty.ERROR_HANDLER));
    EntityResolver er = properties.get(ValidateProperty.ENTITY_RESOLVER);
    if (er != null)
      verifier.setEntityResolver(er);
    try {
      handler = verifier.getVerifierHandler();
    }
    catch (SAXException e) {
      handler = new ExceptionReportHandler(e);
    }
  }

  public void reset() {
    try {
      handler = verifier.getVerifierHandler();
    }
    catch (SAXException e) {
      handler = new ExceptionReportHandler(e);
    }
  }

  public ContentHandler getContentHandler() {
    return handler;
  }

  public DTDHandler getDTDHandler() {
    return null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy