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;
}
Aggregations