Search in sources :

Example 11 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType in project ph-schematron by phax.

the class Issue48Test method validateAndProduceSVRL.

public static void validateAndProduceSVRL(@Nonnull final File aSchematron, final File aXML) throws Exception {
    final PSSchema aSchema = new PSReader(new FileSystemResource(aSchematron)).readSchema();
    final PSPreprocessor aPreprocessor = new PSPreprocessor(PSXPathQueryBinding.getInstance());
    final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema(aSchema);
    final String sSCH = new PSWriter(new PSWriterSettings().setXMLWriterSettings(new XMLWriterSettings())).getXMLString(aPreprocessedSchema);
    if (false)
        System.out.println(sSCH);
    final SchematronResourceSCH aSCH = new SchematronResourceSCH(new ReadableResourceString(sSCH, StandardCharsets.UTF_8));
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
    if (false)
        System.out.println(new SVRLMarshaller().getAsString(aSVRL));
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) SchematronResourceSCH(com.helger.schematron.xslt.SchematronResourceSCH) PSWriter(com.helger.schematron.pure.exchange.PSWriter) PSWriterSettings(com.helger.schematron.pure.exchange.PSWriterSettings) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) PSReader(com.helger.schematron.pure.exchange.PSReader) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) PSPreprocessor(com.helger.schematron.pure.preprocess.PSPreprocessor) PSSchema(com.helger.schematron.pure.model.PSSchema)

Example 12 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType in project ph-schematron by phax.

the class AbstractSchematronXSLTBasedResource method getSchematronValidity.

@Nonnull
public EValidity getSchematronValidity(@Nonnull final Node aXMLNode, @Nullable final String sBaseURI) throws Exception {
    ValueEnforcer.notNull(aXMLNode, "XMLNode");
    // We don't have a short circuit here - apply the full validation
    final SchematronOutputType aSO = applySchematronValidationToSVRL(aXMLNode, sBaseURI);
    if (aSO == null)
        return EValidity.INVALID;
    // And now filter all elements that make the passed source invalid
    return m_aXSLTValidator.getSchematronValidity(aSO);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) Nonnull(javax.annotation.Nonnull)

Example 13 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType in project ph-schematron by phax.

the class SchematronHelperTest method testReadInvalidSchematronValidXML.

@Test
public void testReadInvalidSchematronValidXML() {
    final SchematronOutputType aSO = SchematronHelper.applySchematron(SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON + ".does.not.exist"), new ClassPathResource(VALID_XMLINSTANCE));
    assertNull("Invalid Schematron", aSO);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 14 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType in project ph-schematron by phax.

the class SchematronHelperTest method testReadValidSchematronValidXML.

@Test
public void testReadValidSchematronValidXML() {
    final ISchematronResource aSchematron = SchematronResourceSCH.fromClassPath(VALID_SCHEMATRON);
    final IReadableResource aXML = new ClassPathResource(VALID_XMLINSTANCE);
    final SchematronOutputType aSO = SchematronHelper.applySchematron(aSchematron, aXML);
    assertNotNull("Failed to parse Schematron output", aSO);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 15 with SchematronOutputType

use of org.oclc.purl.dsdl.svrl.SchematronOutputType in project ph-schematron by phax.

the class SchematronHelperTest method testReadValidSchematronValidXMLFromFile.

@Test
public void testReadValidSchematronValidXMLFromFile() {
    final ISchematronResource aSchematron = SchematronResourcePure.fromClassPath(VALID_SCHEMATRON);
    final SchematronOutputType aSO = SchematronHelper.applySchematron(aSchematron, TransformSourceFactory.create(new File("src/test/resources/xml-files/valid01.xml")));
    assertNotNull("Failed to parse Schematron output", aSO);
}
Also used : SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) File(java.io.File) Test(org.junit.Test)

Aggregations

SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)41 Test (org.junit.Test)20 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)18 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)17 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)15 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)14 IReadableResource (com.helger.commons.io.resource.IReadableResource)11 Document (org.w3c.dom.Document)8 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)6 LoggingPSErrorHandler (com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler)6 ISchematronResource (com.helger.schematron.ISchematronResource)5 SchematronResourceSCH (com.helger.schematron.xslt.SchematronResourceSCH)5 MapBasedXPathFunctionResolver (com.helger.xml.xpath.MapBasedXPathFunctionResolver)5 SVRLFailedAssert (com.helger.schematron.svrl.SVRLFailedAssert)4 File (java.io.File)4 XQueryAsXPathFunctionConverter (com.helger.schematron.xpath.XQueryAsXPathFunctionConverter)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)2 PSReader (com.helger.schematron.pure.exchange.PSReader)2