Search in sources :

Example 6 with PSReader

use of com.helger.schematron.pure.exchange.PSReader 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 7 with PSReader

use of com.helger.schematron.pure.exchange.PSReader 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 8 with PSReader

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

the class DocumentationExamples method readModifyAndWrite.

public static boolean readModifyAndWrite(@Nonnull final File aSchematronFile) throws Exception {
    final PSSchema aSchema = new PSReader(new FileSystemResource(aSchematronFile)).readSchema();
    final PSTitle aTitle = new PSTitle();
    aTitle.addText("Created by ph-schematron");
    aSchema.setTitle(aTitle);
    return MicroWriter.writeToFile(aSchema.getAsMicroElement(), aSchematronFile).isSuccess();
}
Also used : PSTitle(com.helger.schematron.pure.model.PSTitle) PSReader(com.helger.schematron.pure.exchange.PSReader) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) PSSchema(com.helger.schematron.pure.model.PSSchema)

Example 9 with PSReader

use of com.helger.schematron.pure.exchange.PSReader 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)

Aggregations

PSReader (com.helger.schematron.pure.exchange.PSReader)9 PSSchema (com.helger.schematron.pure.model.PSSchema)9 IReadableResource (com.helger.commons.io.resource.IReadableResource)5 Test (org.junit.Test)5 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)4 IPSBoundSchema (com.helger.schematron.pure.bound.IPSBoundSchema)3 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)3 PSPreprocessor (com.helger.schematron.pure.preprocess.PSPreprocessor)3 IMicroDocument (com.helger.xml.microdom.IMicroDocument)3 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)2 DoNothingPSErrorHandler (com.helger.schematron.pure.errorhandler.DoNothingPSErrorHandler)2 IPSErrorHandler (com.helger.schematron.pure.errorhandler.IPSErrorHandler)2 PSWriter (com.helger.schematron.pure.exchange.PSWriter)2 PSWriterSettings (com.helger.schematron.pure.exchange.PSWriterSettings)2 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)2 XMLWriterSettings (com.helger.xml.serialize.write.XMLWriterSettings)2 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)2 ReadableResourceString (com.helger.commons.io.resource.inmemory.ReadableResourceString)1 SchematronException (com.helger.schematron.SchematronException)1 IPSQueryBinding (com.helger.schematron.pure.binding.IPSQueryBinding)1