Search in sources :

Example 1 with SchematronException

use of com.helger.schematron.SchematronException in project ph-schematron by phax.

the class PSXPathBoundSchemaTest method testBindAllInvalidSchematrons.

@Test
public void testBindAllInvalidSchematrons() {
    for (final IReadableResource aRes : SchematronTestHelper.getAllInvalidSchematronFiles()) {
        System.out.println(aRes);
        try {
            // Parse the schema
            final PSSchema aSchema = new PSReader(aRes).readSchema();
            final CollectingPSErrorHandler aCEH = new CollectingPSErrorHandler();
            PSXPathQueryBinding.getInstance().bind(aSchema, null, aCEH);
            // Either an ERROR was collected or an exception was thrown
            assertTrue(aCEH.getErrorList().getMostSevereErrorLevel().isGE(EErrorLevel.ERROR));
        } catch (final SchematronException ex) {
            System.out.println("  " + ex.getMessage());
        }
    }
}
Also used : SchematronException(com.helger.schematron.SchematronException) 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 2 with SchematronException

use of com.helger.schematron.SchematronException in project ph-schematron by phax.

the class SchematronResourcePure method createBoundSchema.

@Nonnull
protected IPSBoundSchema createBoundSchema() {
    final IReadableResource aResource = getResource();
    final IPSErrorHandler aErrorHandler = getErrorHandler();
    final PSBoundSchemaCacheKey aCacheKey = new PSBoundSchemaCacheKey(aResource, getPhase(), aErrorHandler, getVariableResolver(), getFunctionResolver(), getEntityResolver());
    if (aResource instanceof AbstractMemoryReadableResource || !isUseCache()) {
        // No need to cache anything for memory resources
        try {
            return aCacheKey.createBoundSchema();
        } catch (final SchematronException ex) {
            // Convert to runtime exception
            throw new IllegalStateException("Failed to bind Schematron", ex);
        }
    }
    // happens
    return PSBoundSchemaCache.getInstance().getFromCache(aCacheKey);
}
Also used : PSBoundSchemaCacheKey(com.helger.schematron.pure.bound.PSBoundSchemaCacheKey) AbstractMemoryReadableResource(com.helger.commons.io.resource.inmemory.AbstractMemoryReadableResource) SchematronException(com.helger.schematron.SchematronException) IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) IReadableResource(com.helger.commons.io.resource.IReadableResource) Nonnull(javax.annotation.Nonnull)

Aggregations

IReadableResource (com.helger.commons.io.resource.IReadableResource)2 SchematronException (com.helger.schematron.SchematronException)2 AbstractMemoryReadableResource (com.helger.commons.io.resource.inmemory.AbstractMemoryReadableResource)1 PSBoundSchemaCacheKey (com.helger.schematron.pure.bound.PSBoundSchemaCacheKey)1 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)1 IPSErrorHandler (com.helger.schematron.pure.errorhandler.IPSErrorHandler)1 PSReader (com.helger.schematron.pure.exchange.PSReader)1 PSSchema (com.helger.schematron.pure.model.PSSchema)1 Nonnull (javax.annotation.Nonnull)1 Test (org.junit.Test)1