Search in sources :

Example 1 with ReadableResourceString

use of com.helger.commons.io.resource.inmemory.ReadableResourceString in project ph-schematron by phax.

the class PSWriterTest method testReadAll.

@Test
public void testReadAll() throws Exception {
    final PSWriter aWriter = new PSWriter();
    for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
        // Parse the schema
        final PSSchema aSchema1 = new PSReader(aRes).readSchema();
        assertNotNull(aSchema1);
        final CollectingPSErrorHandler aLogger = new CollectingPSErrorHandler();
        assertTrue(aRes.getPath(), aSchema1.isValid(aLogger));
        assertTrue(aLogger.isEmpty());
        // Convert back to XML
        final String sXML1 = aWriter.getXMLStringNotNull(aSchema1);
        // Re-read the created XML and re-create it
        final PSSchema aSchema2 = new PSReader(new ReadableResourceString(sXML1, StandardCharsets.UTF_8)).readSchema();
        final String sXML2 = aWriter.getXMLStringNotNull(aSchema2);
        // Originally created XML and re-created-written XML must match
        assertEquals(sXML1, sXML2);
    }
}
Also used : ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) IReadableResource(com.helger.commons.io.resource.IReadableResource) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) PSSchema(com.helger.schematron.pure.model.PSSchema) CollectingPSErrorHandler(com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler) Test(org.junit.Test)

Example 2 with ReadableResourceString

use of com.helger.commons.io.resource.inmemory.ReadableResourceString 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 3 with ReadableResourceString

use of com.helger.commons.io.resource.inmemory.ReadableResourceString 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.xslt.SchematronResourceSCH) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) ReadableResourceString(com.helger.commons.io.resource.inmemory.ReadableResourceString) Test(org.junit.Test)

Aggregations

ReadableResourceString (com.helger.commons.io.resource.inmemory.ReadableResourceString)3 PSSchema (com.helger.schematron.pure.model.PSSchema)2 SchematronResourceSCH (com.helger.schematron.xslt.SchematronResourceSCH)2 Test (org.junit.Test)2 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)1 IReadableResource (com.helger.commons.io.resource.IReadableResource)1 ISchematronResource (com.helger.schematron.ISchematronResource)1 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)1 PSReader (com.helger.schematron.pure.exchange.PSReader)1 PSWriter (com.helger.schematron.pure.exchange.PSWriter)1 PSWriterSettings (com.helger.schematron.pure.exchange.PSWriterSettings)1 PSPreprocessor (com.helger.schematron.pure.preprocess.PSPreprocessor)1 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)1 XMLWriterSettings (com.helger.xml.serialize.write.XMLWriterSettings)1 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)1