Search in sources :

Example 11 with CollectingPSErrorHandler

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

the class PSXPathQueryBinding method bind.

@Nonnull
public IPSBoundSchema bind(@Nonnull final PSSchema aSchema, @Nullable final String sPhase, @Nullable final IPSErrorHandler aCustomErrorListener, @Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver) throws SchematronException {
    ValueEnforcer.notNull(aSchema, "Schema");
    final IPSErrorHandler aErrorHandler = aCustomErrorListener != null ? aCustomErrorListener : new CollectingPSErrorHandler();
    if (!aSchema.isValid(aErrorHandler))
        throw new SchematronBindException("The passed schema is not valid and can therefore not be bound" + (aErrorHandler == aCustomErrorListener ? ". Errors are in the provided error handler." : ": " + ((CollectingPSErrorHandler) aErrorHandler).getErrorList().toString()));
    PSSchema aSchemaToUse = aSchema;
    if (!aSchemaToUse.isPreprocessed()) {
        // Required for parameter resolution
        final PSPreprocessor aPreprocessor = PSPreprocessor.createPreprocessorWithoutInformationLoss(this);
        // Apply preprocessing
        aSchemaToUse = aPreprocessor.getForcedPreprocessedSchema(aSchema);
    }
    final PSXPathBoundSchema ret = new PSXPathBoundSchema(this, aSchemaToUse, sPhase, aCustomErrorListener, aVariableResolver, aFunctionResolver);
    ret.bind();
    return ret;
}
Also used : SchematronBindException(com.helger.schematron.pure.binding.SchematronBindException) IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) PSXPathBoundSchema(com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema) PSPreprocessor(com.helger.schematron.pure.preprocess.PSPreprocessor) PSSchema(com.helger.schematron.pure.model.PSSchema) CollectingPSErrorHandler(com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler) Nonnull(javax.annotation.Nonnull)

Aggregations

CollectingPSErrorHandler (com.helger.schematron.pure.errorhandler.CollectingPSErrorHandler)11 Test (org.junit.Test)8 PSSchema (com.helger.schematron.pure.model.PSSchema)6 IReadableResource (com.helger.commons.io.resource.IReadableResource)5 SchematronResourcePure (com.helger.schematron.pure.SchematronResourcePure)3 PSReader (com.helger.schematron.pure.exchange.PSReader)3 File (java.io.File)3 Nonnull (javax.annotation.Nonnull)3 SchematronOutputType (org.oclc.purl.dsdl.svrl.SchematronOutputType)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 IError (com.helger.commons.error.IError)2 EErrorLevel (com.helger.commons.error.level.EErrorLevel)2 IErrorList (com.helger.commons.error.list.IErrorList)2 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)2 StringHelper (com.helger.commons.string.StringHelper)2 ESchematronMode (com.helger.schematron.ESchematronMode)2 ISchematronResource (com.helger.schematron.ISchematronResource)2 IPSErrorHandler (com.helger.schematron.pure.errorhandler.IPSErrorHandler)2 SVRLHelper (com.helger.schematron.svrl.SVRLHelper)2 SVRLMarshaller (com.helger.schematron.svrl.SVRLMarshaller)2