Search in sources :

Example 6 with IReadableResource

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

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

the class Issue30Test method testOfSchematronPH.

@Test
public void testOfSchematronPH() throws Exception {
    final SchematronResourcePure aResPure = SchematronResourcePure.fromFile("src/test/resources/issues/github30/ph-test.sch");
    aResPure.setEntityResolver(DefaultEntityResolver.createOnDemand(aResPure.getResource()));
    final IPSErrorHandler aErrorHandler = new IPSErrorHandler() {

        @Override
        public void warn(final IReadableResource aRes, final IPSElement aSourceElement, final String sMessage) {
            s_aLogger.info(sMessage);
        }

        @Override
        public void error(final IReadableResource aRes, final IPSElement aSourceElement, final String sMessage, final Throwable t) {
            s_aLogger.info(sMessage);
        }

        @Override
        public void error(final IPSElement aSourceElement, final String sMessage) {
            s_aLogger.info(sMessage);
        }
    };
    aResPure.setErrorHandler(aErrorHandler);
    aResPure.validateCompletely();
    assertFalse(aResPure.isValidSchematron());
}
Also used : IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) IPSElement(com.helger.schematron.pure.model.IPSElement) IReadableResource(com.helger.commons.io.resource.IReadableResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) Test(org.junit.Test)

Example 8 with IReadableResource

use of com.helger.commons.io.resource.IReadableResource 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 9 with IReadableResource

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

the class IssueGC6Test 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)

Example 10 with IReadableResource

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

the class IssueGC7Test 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

IReadableResource (com.helger.commons.io.resource.IReadableResource)37 Test (org.junit.Test)25 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)18 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)12 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)12 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)11 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)9 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)8 CSSWriter (com.helger.css.writer.CSSWriter)8 PSSchema (com.helger.schematron.pure.model.PSSchema)7 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)7 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)6 AbstractSchematronResource (com.helger.schematron.AbstractSchematronResource)6 IMicroDocument (com.helger.xml.microdom.IMicroDocument)6 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)5 PSReader (com.helger.schematron.pure.exchange.PSReader)5 IPSErrorHandler (com.helger.schematron.pure.errorhandler.IPSErrorHandler)4 IMicroElement (com.helger.xml.microdom.IMicroElement)3 File (java.io.File)3 Nonnull (javax.annotation.Nonnull)3