Search in sources :

Example 1 with IPSErrorHandler

use of com.helger.schematron.pure.errorhandler.IPSErrorHandler in project ph-schematron by phax.

the class PSXPathBoundSchemaTest method testSchematronValidation.

@Test
public void testSchematronValidation() throws SAXException, SchematronException {
    for (int i = 0; i < SCH.length; ++i) {
        final IReadableResource aSchRes = new ClassPathResource("test-sch/" + SCH[i]);
        final IReadableResource aXmlRes = new ClassPathResource("test-xml/" + XML[i]);
        // Resolve all includes
        final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aSchRes);
        assertNotNull(aDoc);
        // Read to domain object
        final PSReader aReader = new PSReader(aSchRes);
        final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
        assertNotNull(aSchema);
        // Create a compiled schema
        final String sPhaseID = null;
        final IPSErrorHandler aErrorHandler = null;
        final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema, sPhaseID, aErrorHandler);
        // Validate completely
        final SchematronOutputType aSVRL = aBoundSchema.validateComplete(DOMReader.readXMLDOM(aXmlRes), aXmlRes.getAsURL().toExternalForm());
        assertNotNull(aSVRL);
        if (false)
            System.out.println(new SVRLMarshaller().getAsString(aSVRL));
    }
}
Also used : IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) IPSBoundSchema(com.helger.schematron.pure.bound.IPSBoundSchema) IReadableResource(com.helger.commons.io.resource.IReadableResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) 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 2 with IPSErrorHandler

use of com.helger.schematron.pure.errorhandler.IPSErrorHandler 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 3 with IPSErrorHandler

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

Example 4 with IPSErrorHandler

use of com.helger.schematron.pure.errorhandler.IPSErrorHandler in project ph-schematron by phax.

the class SchematronResourcePure method validateCompletely.

/**
 * Use the internal error handler to validate all elements in the schematron.
 * It tries to catch as many errors as possible.
 */
public void validateCompletely() {
    // Use the provided error handler (if any)
    final IPSErrorHandler aErrorHandler = m_aErrorHandler != null ? m_aErrorHandler : new DoNothingPSErrorHandler();
    validateCompletely(aErrorHandler);
}
Also used : IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) DoNothingPSErrorHandler(com.helger.schematron.pure.errorhandler.DoNothingPSErrorHandler)

Example 5 with IPSErrorHandler

use of com.helger.schematron.pure.errorhandler.IPSErrorHandler 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

IPSErrorHandler (com.helger.schematron.pure.errorhandler.IPSErrorHandler)6 IReadableResource (com.helger.commons.io.resource.IReadableResource)4 PSSchema (com.helger.schematron.pure.model.PSSchema)3 Test (org.junit.Test)3 IPSBoundSchema (com.helger.schematron.pure.bound.IPSBoundSchema)2 CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)2 PSReader (com.helger.schematron.pure.exchange.PSReader)2 Nonnull (javax.annotation.Nonnull)2 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)1 AbstractMemoryReadableResource (com.helger.commons.io.resource.inmemory.AbstractMemoryReadableResource)1 SchematronException (com.helger.schematron.SchematronException)1 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)1 SchematronBindException (com.helger.schematron.pure.binding.SchematronBindException)1 PSBoundSchemaCacheKey (com.helger.schematron.pure.bound.PSBoundSchemaCacheKey)1 PSXPathBoundSchema (com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema)1 DoNothingPSErrorHandler (com.helger.schematron.pure.errorhandler.DoNothingPSErrorHandler)1 IPSElement (com.helger.schematron.pure.model.IPSElement)1 PSPreprocessor (com.helger.schematron.pure.preprocess.PSPreprocessor)1 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)1 IMicroDocument (com.helger.xml.microdom.IMicroDocument)1