Search in sources :

Example 11 with SchematronResourcePure

use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.

the class Issue29Test method validateXmlUsingSchematron.

@Nullable
static SchematronOutputType validateXmlUsingSchematron(@Nonnull final IReadableResource aRes) {
    SchematronOutputType ob = null;
    // Must use the XSLT based version, because of "key" usage
    final ISchematronResource aResSCH = new SchematronResourcePure(new ClassPathResource("issues/github29/pbs.sch"));
    if (!aResSCH.isValidSchematron())
        throw new IllegalArgumentException("Invalid Schematron!");
    try {
        final Document aDoc = aResSCH.applySchematronValidation(new ResourceStreamSource(aRes));
        if (aDoc != null) {
            final SVRLMarshaller marshaller = new SVRLMarshaller();
            ob = marshaller.read(aDoc);
        }
    } catch (final Exception pE) {
        pE.printStackTrace();
    }
    return ob;
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) ResourceStreamSource(com.helger.xml.transform.ResourceStreamSource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) Document(org.w3c.dom.Document) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Nullable(javax.annotation.Nullable)

Example 12 with SchematronResourcePure

use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.

the class Issue25Test method testIssue25Invalid.

@Test
public void testIssue25Invalid() throws Exception {
    final IReadableResource aSCH = new ClassPathResource("test-sch/xfront/example05/check-classifications.sch");
    final IReadableResource aXML = new ClassPathResource("test-sch/xfront/example05/invalid-document.xml");
    final SchematronOutputType aSOT = SchematronHelper.applySchematron(new SchematronResourcePure(aSCH), aXML);
    assertNotNull(aSOT);
    assertTrue(SVRLHelper.getAllFailedAssertions(aSOT).isNotEmpty());
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) Test(org.junit.Test)

Example 13 with SchematronResourcePure

use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.

the class Issue25Test method testIssue25Valid.

@Test
public void testIssue25Valid() throws Exception {
    final IReadableResource aSCH = new ClassPathResource("test-sch/xfront/example05/check-classifications.sch");
    final IReadableResource aXML = new ClassPathResource("test-sch/xfront/example05/valid-document.xml");
    final SchematronOutputType aSOT = SchematronHelper.applySchematron(new SchematronResourcePure(aSCH), aXML);
    assertNotNull(aSOT);
    assertTrue(SVRLHelper.getAllFailedAssertions(aSOT).isEmpty());
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) Test(org.junit.Test)

Example 14 with SchematronResourcePure

use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.

the class Issue6Test 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(org.oclc.purl.dsdl.svrl.SchematronOutputType) SchematronResourceSCH(com.helger.schematron.xslt.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)

Example 15 with SchematronResourcePure

use of com.helger.schematron.pure.SchematronResourcePure in project ph-schematron by phax.

the class IssueGC9Test 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(org.oclc.purl.dsdl.svrl.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)

Aggregations

SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)19 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)16 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)13 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)10 IReadableResource (com.helger.commons.io.resource.IReadableResource)9 Test (org.junit.Test)7 LoggingPSErrorHandler (com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler)6 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)5 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)3 ISchematronResource (com.helger.schematron.ISchematronResource)3 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)3 SchematronResourceSCH (com.helger.schematron.xslt.SchematronResourceSCH)3 File (java.io.File)3 Nullable (javax.annotation.Nullable)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)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 ESchematronMode (com.helger.schematron.ESchematronMode)2