Class SchematronResourcePure

java.lang.Object
com.helger.schematron.AbstractSchematronResource
com.helger.schematron.pure.SchematronResourcePure
All Implemented Interfaces:
com.helger.commons.id.IHasID<String>, com.helger.schematron.ISchematronResource

@NotThreadSafe public class SchematronResourcePure extends com.helger.schematron.AbstractSchematronResource
A Schematron resource that is not XSLT based but using the pure (native Java) implementation. This class itself is not thread safe, but the underlying cache is thread safe. So once you configured this object fully (with all the setter), it can be considered thread safe.
Important: This class can only handle XPath expressions but no XSLT functions in Schematron asserts and reports! If your Schematrons use XSLT functionality you're better off using the com.helger.schematron.sch.SchematronResourceSCH or com.helger.schematron.xslt.SchematronResourceXSLT classes instead!
Author:
Philip Helger
  • Constructor Details

    • SchematronResourcePure

      public SchematronResourcePure(@Nonnull com.helger.commons.io.resource.IReadableResource aResource)
    • SchematronResourcePure

      public SchematronResourcePure(@Nonnull com.helger.commons.io.resource.IReadableResource aResource, boolean bLenient)
    • SchematronResourcePure

      public SchematronResourcePure(@Nonnull com.helger.commons.io.resource.IReadableResource aResource, @Nullable String sPhase, @Nullable IPSErrorHandler aErrorHandler)
    • SchematronResourcePure

      public SchematronResourcePure(@Nonnull com.helger.commons.io.resource.IReadableResource aResource, @Nullable String sPhase, @Nullable IPSErrorHandler aErrorHandler, boolean bLenient)
  • Method Details

    • getPhase

      @Nullable public final String getPhase()
      Returns:
      The phase to be used. May be null.
    • setPhase

      @Nonnull public final SchematronResourcePure setPhase(@Nullable String sPhase)
      Set the Schematron phase to be evaluated. Changing the phase will result in a newly bound schema!
      Parameters:
      sPhase - The name of the phase to use. May be null which means all phases.
      Returns:
      this
    • getErrorHandler

      @Nullable public final IPSErrorHandler getErrorHandler()
      Returns:
      The error handler to be used to bind the schema. May be null.
    • setErrorHandler

      @Nonnull public final SchematronResourcePure setErrorHandler(@Nullable IPSErrorHandler aErrorHandler)
      Set the error handler to be used during binding.
      Parameters:
      aErrorHandler - The error handler. May be null.
      Returns:
      this
    • getCustomValidationHandler

      @Nullable public final IPSValidationHandler getCustomValidationHandler()
      Returns:
      The custom validation handler to be used to bind the schema. May be null.
      Since:
      5.3.0
    • setCustomValidationHandler

      @Nonnull public final SchematronResourcePure setCustomValidationHandler(@Nullable IPSValidationHandler aCustomValidationHandler)
      Set the custom validation handler to be used during binding.
      Parameters:
      aCustomValidationHandler - The validation handler. May be null.
      Returns:
      this
      Since:
      5.3.0
    • getVariableResolver

      @Nullable public final XPathVariableResolver getVariableResolver()
      Returns:
      The variable resolver to be used. May be null.
    • getFunctionResolver

      @Nullable public final XPathFunctionResolver getFunctionResolver()
      Returns:
      The function resolver to be used. May be null.
    • setXPathConfig

      @Nonnull public final SchematronResourcePure setXPathConfig(@Nonnull IXPathConfig aXPathConfig)
      Set the XPathConfig to be used in the XPath statements. This can only be set before the Schematron is bound. If it is already bound an exception is thrown to indicate the unnecessity of the call.
      Parameters:
      aXPathConfig - The XPath config to set. May be null.
      Returns:
      this
    • setEntityResolver

      @Nonnull public SchematronResourcePure setEntityResolver(@Nullable EntityResolver aEntityResolver)
      Set the XML entity resolver to be used when reading the Schematron or the XML to be validated. This can only be set before the Schematron is bound. If it is already bound an exception is thrown to indicate the unnecessity of the call.
      Parameters:
      aEntityResolver - The entity resolver to set. May be null.
      Returns:
      this
      Since:
      4.1.1
    • createBoundSchema

      @Nonnull protected IPSBoundSchema createBoundSchema()
    • getOrCreateBoundSchema

      @Nonnull public IPSBoundSchema getOrCreateBoundSchema()
      Get the cached bound schema or create a new one.
      Returns:
      The bound schema. Never null.
    • isValidSchematron

      public boolean isValidSchematron()
    • validateCompletely

      public void validateCompletely()
      Use the internal error handler to validate all elements in the schematron. It tries to catch as many errors as possible.
    • validateCompletely

      public void validateCompletely(@Nonnull IPSErrorHandler aErrorHandler)
      Use the provided error handler to validate all elements in the schematron. It tries to catch as many errors as possible.
      Parameters:
      aErrorHandler - The error handler to use. May not be null.
    • getSchematronValidity

      @Nonnull public com.helger.commons.state.EValidity getSchematronValidity(@Nonnull Node aXMLNode, @Nullable String sBaseURI) throws Exception
      Throws:
      Exception
    • applySchematronValidationToSVRL

      @Nonnull public com.helger.schematron.svrl.jaxb.SchematronOutputType applySchematronValidationToSVRL(@Nonnull Node aXMLNode, @Nullable String sBaseURI) throws com.helger.schematron.SchematronException
      The main method to convert a node to an SVRL document.
      Parameters:
      aXMLNode - The source node to be validated. May not be null.
      sBaseURI - Base URI of the XML document to be validated. May be null.
      Returns:
      The SVRL document. Never null.
      Throws:
      com.helger.schematron.SchematronException - in case of a sever error validating the schema
    • applySchematronValidation

      @Nullable public Document applySchematronValidation(@Nonnull Node aXMLNode, @Nullable String sBaseURI) throws Exception
      Throws:
      Exception
    • fromClassPath

      @Nonnull public static SchematronResourcePure fromClassPath(@Nonnull @Nonempty String sSCHPath)
      Create a new SchematronResourcePure from a Classpath Schematron rules
      Parameters:
      sSCHPath - The classpath relative path to the Schematron rules.
      Returns:
      Never null.
    • fromClassPath

      @Nonnull public static SchematronResourcePure fromClassPath(@Nonnull @Nonempty String sSCHPath, @Nullable ClassLoader aClassLoader)
      Create a new SchematronResourcePure from a Classpath Schematron rules
      Parameters:
      sSCHPath - The classpath relative path to the Schematron rules.
      aClassLoader - The class loader to be used to retrieve the classpath resource. May be null.
      Returns:
      Never null.
      Since:
      6.0.4
    • fromFile

      @Nonnull public static SchematronResourcePure fromFile(@Nonnull @Nonempty String sSCHPath)
      Create a new SchematronResourcePure from file system Schematron rules
      Parameters:
      sSCHPath - The file system path to the Schematron rules.
      Returns:
      Never null.
    • fromFile

      @Nonnull public static SchematronResourcePure fromFile(@Nonnull File aSCHFile)
      Create a new SchematronResourcePure from file system Schematron rules
      Parameters:
      aSCHFile - The file system path to the Schematron rules.
      Returns:
      Never null.
    • fromURL

      @Nonnull public static SchematronResourcePure fromURL(@Nonnull @Nonempty String sSCHURL) throws MalformedURLException
      Create a new SchematronResourcePure from Schematron rules provided at a URL
      Parameters:
      sSCHURL - The URL to the Schematron rules. May neither be null nor empty.
      Returns:
      Never null.
      Throws:
      MalformedURLException - In case an invalid URL is provided
    • fromURL

      @Nonnull public static SchematronResourcePure fromURL(@Nonnull URL aSCHURL)
      Create a new SchematronResourcePure from Schematron rules provided at a URL
      Parameters:
      aSCHURL - The URL to the Schematron rules. May not be null.
      Returns:
      Never null.
    • fromInputStream

      @Nonnull public static SchematronResourcePure fromInputStream(@Nonnull @Nonempty String sResourceID, @Nonnull InputStream aSchematronIS)
      Create a new SchematronResourcePure from Schematron rules provided by an arbitrary InputStream.
      Important: in this case, no include resolution will be performed!!
      Parameters:
      sResourceID - Resource ID to be used as the cache key. Should neither be null nor empty.
      aSchematronIS - The InputStream to read the Schematron rules from. May not be null.
      Returns:
      Never null.
      Since:
      6.2.5
    • fromByteArray

      @Nonnull public static SchematronResourcePure fromByteArray(@Nonnull byte[] aSchematron)
      Create a new SchematronResourcePure from Schematron rules provided by an arbitrary byte array.
      Important: in this case, no include resolution will be performed!!
      Parameters:
      aSchematron - The byte array representing the Schematron. May not be null.
      Returns:
      Never null.
    • fromString

      @Nonnull public static SchematronResourcePure fromString(@Nonnull String sSchematron, @Nonnull Charset aCharset)
      Create a new SchematronResourcePure from Schematron rules provided by an arbitrary String.
      Important: in this case, no include resolution will be performed!!
      Parameters:
      sSchematron - The String representing the Schematron. May not be null .
      aCharset - The charset to be used to convert the String to a byte array.
      Returns:
      Never null.
    • fromSchema

      @Nonnull public static SchematronResourcePure fromSchema(@Nonnull PSSchema aSchematron)
      Create a new SchematronResourcePure from Schematron rules provided by a domain model.
      Important: in this case, no include resolution will be performed!!
      Parameters:
      aSchematron - The Schematron model to be used. May not be null .
      Returns:
      Never null.