Search in sources :

Example 6 with SchematronResourceSCH

use of com.helger.schematron.sch.SchematronResourceSCH in project ph-schematron by phax.

the class Issue085Test method validateAndProduceSVRL.

public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
    final SchematronResourceSCH aSCH = SchematronResourceSCH.fromFile(aSchematron);
    if (false)
        System.out.println(XMLWriter.getNodeAsString(aSCH.getXSLTProvider().getXSLTDocument()));
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
    if (false)
        System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) SchematronResourceSCH(com.helger.schematron.sch.SchematronResourceSCH) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) FileSystemResource(com.helger.commons.io.resource.FileSystemResource)

Example 7 with SchematronResourceSCH

use of com.helger.schematron.sch.SchematronResourceSCH in project ph-schematron by phax.

the class Issue126Test method _validateAndProduceSVRL.

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

Example 8 with SchematronResourceSCH

use of com.helger.schematron.sch.SchematronResourceSCH in project ph-schematron by phax.

the class IssueSO32784781Test method testBasic.

@Test
public void testBasic() {
    final String sSCH = "<schema xmlns=\"http://purl.oclc.org/dsdl/schematron\">\r\n" + "  <ns prefix=\"m\" uri=\"http://www.ociweb.com/movies\"/>\r\n" + "  <pattern name=\"all\">\r\n" + "    <rule context=\"m:actor\">\r\n" + "      <report test=\"@role=preceding-sibling::m:actor/@role\"\r\n" + "          diagnostics=\"duplicateActorRole\">\r\n" + "        Duplicate role!\r\n" + "      </report>\r\n" + "    </rule>\r\n" + "  </pattern>\r\n" + "  <diagnostics>\r\n" + "    <diagnostic id=\"duplicateActorRole\">\r\n" + "      More than one actor plays the role<value-of select=\"@role\"/>.\r\n" + "      A duplicate is named<value-of select=\"@name\"/>.\r\n" + "    </diagnostic>\r\n" + "  </diagnostics>\r\n" + "</schema>";
    final ISchematronResource isr = new SchematronResourceSCH(new ReadableResourceString(sSCH, StandardCharsets.UTF_8));
    assertTrue(isr.isValidSchematron());
}
Also used : ISchematronResource(com.helger.schematron.ISchematronResource) SchematronResourceSCH(com.helger.schematron.sch.SchematronResourceSCH) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) Test(org.junit.Test)

Example 9 with SchematronResourceSCH

use of com.helger.schematron.sch.SchematronResourceSCH in project phive by phax.

the class ValidationExecutorSchematron method _createSchematronResource.

@Nonnull
private AbstractSchematronResource _createSchematronResource(@Nullable final Locale aLocale, @Nonnull final ErrorList aErrorList, @Nonnull final Consumer<ESchematronOutput> aSpecialOutputHdl) {
    final IValidationArtefact aArtefact = getValidationArtefact();
    // get the Schematron resource to be used for this validation artefact
    final IReadableResource aSCHRes = aArtefact.getRuleResource();
    final IValidationType aVT = aArtefact.getValidationArtefactType();
    if (aVT == EValidationType.SCHEMATRON_PURE) {
        final SchematronResourcePure aPureSCH = new SchematronResourcePure(aSCHRes);
        aPureSCH.setErrorHandler(new WrappedCollectingPSErrorHandler(aErrorList));
        // consecutive calls!
        return aPureSCH;
    }
    if (aVT == EValidationType.SCHEMATRON_SCH) {
        final SchematronResourceSCH aSCHSCH = new SchematronResourceSCH(aSCHRes);
        aSCHSCH.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
        if (aLocale != null && StringHelper.hasText(aLocale.getLanguage()))
            aSCHSCH.setLanguageCode(aLocale.getLanguage());
        return aSCHSCH;
    }
    if (aVT == EValidationType.SCHEMATRON_SCHXSLT) {
        final SchematronResourceSchXslt_XSLT2 aSCHSCH = new SchematronResourceSchXslt_XSLT2(aSCHRes);
        aSCHSCH.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
        if (aLocale != null && StringHelper.hasText(aLocale.getLanguage()))
            aSCHSCH.setLanguageCode(aLocale.getLanguage());
        return aSCHSCH;
    }
    if (aVT == EValidationType.SCHEMATRON_XSLT) {
        final SchematronResourceXSLT aSCHXSLT = new SchematronResourceXSLT(aSCHRes);
        aSCHXSLT.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
        return aSCHXSLT;
    }
    if (aVT == EValidationType.SCHEMATRON_OIOUBL) {
        final SchematronResourceXSLT aSCHXSLT = new SchematronResourceXSLT(aSCHRes);
        aSCHXSLT.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
        // Special output layout
        aSpecialOutputHdl.accept(ESchematronOutput.OIOUBL);
        return aSCHXSLT;
    }
    throw new IllegalStateException("Unsupported Schematron validation type: " + aVT);
}
Also used : IValidationType(com.helger.phive.api.IValidationType) SchematronResourceXSLT(com.helger.schematron.xslt.SchematronResourceXSLT) SchematronResourceSCH(com.helger.schematron.sch.SchematronResourceSCH) IValidationArtefact(com.helger.phive.api.artefact.IValidationArtefact) SchematronResourceSchXslt_XSLT2(com.helger.schematron.schxslt.xslt2.SchematronResourceSchXslt_XSLT2) IReadableResource(com.helger.commons.io.resource.IReadableResource) WrappedCollectingTransformErrorListener(com.helger.xml.transform.WrappedCollectingTransformErrorListener) WrappedCollectingPSErrorHandler(com.helger.schematron.pure.errorhandler.WrappedCollectingPSErrorHandler) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) Nonnull(javax.annotation.Nonnull)

Example 10 with SchematronResourceSCH

use of com.helger.schematron.sch.SchematronResourceSCH in project ph-schematron by phax.

the class Issue006Test method validateAndProduceSVRL.

@SuppressFBWarnings("BC_IMPOSSIBLE_INSTANCEOF")
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 aSCH = new SchematronResourceSCH(aSchematron);
    if (aSCH instanceof SchematronResourcePure)
        ((SchematronResourcePure) aSCH).setErrorHandler(new LoggingPSErrorHandler());
    else
        System.out.println(XMLWriter.getNodeAsString(((SchematronResourceSCH) aSCH).getXSLTProvider().getXSLTDocument()));
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(anXMLSource);
    assertNotNull(aSVRL);
    if (false)
        System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) SchematronResourceSCH(com.helger.schematron.sch.SchematronResourceSCH) LoggingPSErrorHandler(com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler) 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) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SchematronResourceSCH (com.helger.schematron.sch.SchematronResourceSCH)14 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)12 SchematronOutputType (com.helger.schematron.svrl.jaxb.SchematronOutputType)12 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)11 IReadableResource (com.helger.commons.io.resource.IReadableResource)4 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)4 ISchematronResource (com.helger.schematron.ISchematronResource)3 SchematronResourceSchXslt_XSLT2 (com.helger.schematron.schxslt.xslt2.SchematronResourceSchXslt_XSLT2)3 SchematronResourceXSLT (com.helger.schematron.xslt.SchematronResourceXSLT)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 Nonnull (javax.annotation.Nonnull)3 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)2 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)2 IError (com.helger.commons.error.IError)2 EErrorLevel (com.helger.commons.error.level.EErrorLevel)2 IErrorList (com.helger.commons.error.list.IErrorList)2 StringHelper (com.helger.commons.string.StringHelper)2 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)2