Search in sources :

Example 1 with SchematronReportParser

use of eu.esdihumboldt.hale.io.schematron.util.SchematronReportParser in project hale by halestudio.

the class SchematronInstanceValidator method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    URI schematronLoc = getSchematronLocation();
    if (schematronLoc == null) {
        throw new IOProviderConfigurationException("Providing a schematron file is required");
    }
    progress.begin("Performing Schematron validation", ProgressIndicator.UNKNOWN);
    final InputStream sourceInput = this.getSource().getInput();
    if (sourceInput == null) {
        throw new RuntimeException("No input for Schematron validator");
    }
    final Source xmlSource = new StreamSource(sourceInput);
    final DefaultInputSupplier schematronInputSupplier = new DefaultInputSupplier(schematronLoc);
    final InputStream schematronInput = schematronInputSupplier.getInput();
    if (schematronInput == null) {
        throw new RuntimeException("No rules input for Schematron validator");
    }
    final Source schematronSource = new StreamSource(schematronInput);
    try {
        final SchematronValidator validator = new SchematronValidator(schematronSource);
        final Result result = validator.validate(xmlSource, /* svrlReport */
        true);
        final StringWriter reportWriter = new StringWriter();
        SchematronUtils.convertValidatorResult(result, reportWriter);
        reporter.setSuccess(!validator.ruleViolationsDetected());
        if (validator.ruleViolationsDetected()) {
            SchematronReportParser parser = new SchematronReportParser(reportWriter.toString());
            parser.reportFailedAssertions(reporter);
        }
    } catch (Exception e) {
        reporter.error(new IOMessageImpl("Error running schematron validation", e));
        reporter.setSuccess(false);
    } finally {
        schematronInput.close();
        progress.end();
    }
    return reporter;
}
Also used : SchematronReportParser(eu.esdihumboldt.hale.io.schematron.util.SchematronReportParser) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) URI(java.net.URI) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) Result(javax.xml.transform.Result) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) StringWriter(java.io.StringWriter) SchematronValidator(org.opengis.cite.validation.SchematronValidator)

Aggregations

IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)1 SchematronReportParser (eu.esdihumboldt.hale.io.schematron.util.SchematronReportParser)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 Result (javax.xml.transform.Result)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 SchematronValidator (org.opengis.cite.validation.SchematronValidator)1