Search in sources :

Example 26 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class Issue044Test method validateAndProduceSVRL.

public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
    // SchematronResourcePure fails!
    ISchematronResource aSCH = SchematronResourcePure.fromFile(aSchematron);
    // Parsing Schematron works!
    aSCH = SchematronResourceSCH.fromFile(aSchematron);
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
    if (false)
        System.out.println(new SVRLMarshaller().getAsString(aSVRL));
    assertEquals(3, SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).size());
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource)

Example 27 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class Issue064Test method validateAndProduceSVRL.

public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
    final SchematronResourcePure aSCH = SchematronResourcePure.fromFile(aSchematron);
    aSCH.setErrorHandler(new LoggingPSErrorHandler());
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) LoggingPSErrorHandler(com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure)

Example 28 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class Issue088Test method _validateAndProduceSVRL.

private static void _validateAndProduceSVRL(@Nonnull final File aSchematron, @Nonnull final File aXML) throws Exception {
    final SchematronResourcePure aSCH = SchematronResourcePure.fromFile(aSchematron);
    aSCH.setCustomValidationHandler(new LoggingPSValidationHandler());
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
    final String sSVRL = new SVRLMarshaller().getAsString(aSVRL);
    assertNotNull(sSVRL);
    if (false)
        LOGGER.info("SVRL:\n" + sSVRL);
    assertTrue(SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).isEmpty());
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) LoggingPSValidationHandler(com.helger.schematron.pure.validation.LoggingPSValidationHandler) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure)

Example 29 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project ph-schematron by phax.

the class Issue20140523Test method validateAndProduceSVRL.

public static void validateAndProduceSVRL(final File schematron, final File xml) throws Exception {
    final IReadableResource aSchematron = new FileSystemResource(schematron.getAbsoluteFile());
    final IReadableResource anXMLSource = new FileSystemResource(xml.getAbsoluteFile());
    final AbstractSchematronResource pure = new SchematronResourcePure(aSchematron);
    final SchematronOutputType aSVRL = pure.applySchematronValidationToSVRL(anXMLSource);
    assertNotNull(aSVRL);
    if (false)
        System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) IReadableResource(com.helger.commons.io.resource.IReadableResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) AbstractSchematronResource(com.helger.schematron.AbstractSchematronResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure)

Example 30 with SchematronOutputType

use of com.helger.schematron.svrl.jaxb.SchematronOutputType in project mustangproject by ZUGFeRD.

the class XMLValidator method validateSchematron.

/**
 * validate using a xslt file generated from a schematron in the build preparation of this software
 * @param xml the xml to be checked
 * @param xsltFilename the filename of the intermediate XSLT file
 * @param section the error type code, if one arises
 * @param severity how serious a error should be treated - may only be notice
 * @throws IrrecoverableValidationError if anything happened that prevents further checks
 */
public void validateSchematron(String xml, String xsltFilename, int section, ESeverity severity) throws IrrecoverableValidationError {
    ISchematronResource aResSCH = null;
    aResSCH = SchematronResourceXSLT.fromClassPath(xsltFilename);
    if (aResSCH != null) {
        if (!aResSCH.isValidSchematron()) {
            throw new IllegalArgumentException(xsltFilename + " is invalid Schematron!");
        }
        final SchematronOutputType sout;
        try {
            sout = aResSCH.applySchematronValidationToSVRL(new StreamSource(new StringReader(xml)));
        } catch (final Exception e) {
            throw new IrrecoverableValidationError(e.getMessage());
        }
        final List<Object> failedAsserts = sout.getActivePatternAndFiredRuleAndFailedAssert();
        if (failedAsserts.size() > 0) {
            for (final Object object : failedAsserts) {
                if (object instanceof FailedAssert) {
                    final FailedAssert failedAssert = (FailedAssert) object;
                    LOGGER.info("FailedAssert ", failedAssert);
                    context.addResultItem(new ValidationResultItem(severity, SVRLHelper.getAsString(failedAssert.getText()) + " (From " + xsltFilename + ")").setLocation(failedAssert.getLocation()).setCriterion(failedAssert.getTest()).setSection(section).setPart(EPart.fx));
                    failedRules++;
                } else if (object instanceof FiredRule) {
                    firedRules++;
                }
            }
        }
        if (firedRules == 0) {
            context.addResultItem(new ValidationResultItem(ESeverity.error, "No rules matched, XML to minimal?").setSection(26).setPart(EPart.fx));
        }
    // for (String currentString : sout.getText()) {
    // schematronValidationString += "<output>" + currentString + "</output>";
    // }
    // schematronValidationString += new SVRLMarshaller ().getAsString (sout);
    // returns the complete SVRL
    }
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) FiredRule(com.helger.schematron.svrl.jaxb.FiredRule) StreamSource(javax.xml.transform.stream.StreamSource) FailedAssert(com.helger.schematron.svrl.jaxb.FailedAssert) StringReader(java.io.StringReader) IOException(java.io.IOException)

Aggregations

SchematronOutputType (com.helger.schematron.svrl.jaxb.SchematronOutputType)56 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)31 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)30 Test (org.junit.Test)21 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)18 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)15 IReadableResource (com.helger.commons.io.resource.IReadableResource)13 ISchematronResource (com.helger.schematron.ISchematronResource)10 SchematronResourceSCH (com.helger.schematron.sch.SchematronResourceSCH)10 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)9 Document (org.w3c.dom.Document)9 LoggingPSErrorHandler (com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler)7 IXPathConfig (com.helger.schematron.pure.xpath.IXPathConfig)6 XPathConfigBuilder (com.helger.schematron.pure.xpath.XPathConfigBuilder)6 SVRLFailedAssert (com.helger.schematron.svrl.SVRLFailedAssert)4 MapBasedXPathFunctionResolver (com.helger.xml.xpath.MapBasedXPathFunctionResolver)4 File (java.io.File)4 Nonnull (javax.annotation.Nonnull)4 LoggingPSValidationHandler (com.helger.schematron.pure.validation.LoggingPSValidationHandler)3 XQueryAsXPathFunctionConverter (com.helger.schematron.pure.xpath.XQueryAsXPathFunctionConverter)3