Search in sources :

Example 21 with IReadableResource

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

the class PSPreprocessorTest method testWithTitle.

@Test
public void testWithTitle() throws SchematronException {
    final PSPreprocessor aPreprocessor = new PSPreprocessor(PSXPathQueryBinding.getInstance()).setKeepTitles(true).setKeepDiagnostics(true);
    final IReadableResource aRes = new ClassPathResource("test-sch/example-3-5.sch");
    final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aRes);
    final PSReader aReader = new PSReader(aRes);
    final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
    final PSSchema aPreprocessedSchema = aPreprocessor.getAsPreprocessedSchema(aSchema);
    assertNotNull(aPreprocessedSchema);
    assertTrue(aPreprocessedSchema.isValid(new DoNothingPSErrorHandler()));
    // Because titles are not in minimal mode
    assertFalse(aPreprocessedSchema.isMinimal());
}
Also used : DoNothingPSErrorHandler(com.helger.schematron.pure.errorhandler.DoNothingPSErrorHandler) IReadableResource(com.helger.commons.io.resource.IReadableResource) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PSReader(com.helger.schematron.pure.exchange.PSReader) PSSchema(com.helger.schematron.pure.model.PSSchema) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 22 with IReadableResource

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

the class PSPreprocessorTest method testBasic.

@Test
public void testBasic() throws Exception {
    final PSPreprocessor aPreprocessor = new PSPreprocessor(PSXPathQueryBinding.getInstance());
    for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
        // Resolve all includes
        final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aRes);
        assertNotNull(aDoc);
        // Read to domain object
        final PSReader aReader = new PSReader(aRes);
        final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
        assertNotNull(aSchema);
        // Ensure the schema is valid
        final CollectingPSErrorHandler aErrHdl = new CollectingPSErrorHandler();
        assertTrue(aRes.getPath(), aSchema.isValid(aErrHdl));
        assertTrue(aErrHdl.isEmpty());
        // Convert to minified schema if not-yet minimal
        final PSSchema aPreprocessedSchema = aPreprocessor.getAsMinimalSchema(aSchema);
        assertNotNull(aPreprocessedSchema);
        if (false) {
            final String sXML = MicroWriter.getNodeAsString(aPreprocessedSchema.getAsMicroElement());
            SimpleFileIO.writeFile(new File("test-minified", FilenameHelper.getWithoutPath(aRes.getPath()) + ".min-pure.sch"), sXML, XMLWriterSettings.DEFAULT_XML_CHARSET_OBJ);
        }
        // Ensure it is still valid and minimal
        assertTrue(aRes.getPath(), aPreprocessedSchema.isValid(aErrHdl));
        assertTrue(aRes.getPath(), aPreprocessedSchema.isMinimal());
    }
}
Also used : IReadableResource(com.helger.commons.io.resource.IReadableResource) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PSReader(com.helger.schematron.pure.exchange.PSReader) PSSchema(com.helger.schematron.pure.model.PSSchema) File(java.io.File) CollectingPSErrorHandler(com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler) Test(org.junit.Test)

Example 23 with IReadableResource

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

the class Issue20140523Test 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 24 with IReadableResource

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

the class PSXPathBoundSchemaTest method testBindAllValidSchematrons.

@Test
public void testBindAllValidSchematrons() throws SchematronException {
    for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
        // Parse the schema
        final PSSchema aSchema = new PSReader(aRes).readSchema();
        assertNotNull(aSchema);
        CommonsTestHelper.testToStringImplementation(aSchema);
        final CollectingPSErrorHandler aLogger = new CollectingPSErrorHandler();
        assertTrue(aRes.getPath(), aSchema.isValid(aLogger));
        assertTrue(aLogger.isEmpty());
        // Create a compiled schema
        final String sPhaseID = null;
        final IPSErrorHandler aErrorHandler = null;
        final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema, sPhaseID, aErrorHandler);
        assertNotNull(aBoundSchema);
    }
}
Also used : IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) IPSBoundSchema(com.helger.schematron.pure.bound.IPSBoundSchema) IReadableResource(com.helger.commons.io.resource.IReadableResource) PSReader(com.helger.schematron.pure.exchange.PSReader) PSSchema(com.helger.schematron.pure.model.PSSchema) CollectingPSErrorHandler(com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler) Test(org.junit.Test)

Example 25 with IReadableResource

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

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