Class SchematronValidator

java.lang.Object
org.projecthusky.validation.service.schematron.SchematronValidator

@NotThreadSafe public class SchematronValidator extends Object
A Schematron validator for XML files.

The underlying Schematron validator is not thread-safe.

Author:
Quentin Ligier
  • Constructor Details

    • SchematronValidator

      public SchematronValidator(com.helger.commons.io.resource.IReadableResource xsltResource)
      Constructs a Schematron validator.

      Beware to only pass IReadableResource instances that have a unique resource ID or all instances of the validator will use the same XSLT resource (internals use the resource ID as a key for caching).

      Parameters:
      xsltResource - The XSLT resource.
      Throws:
      IllegalArgumentException - if the Schematron resource is invalid.
    • SchematronValidator

      public SchematronValidator(File xsltFile)
      Constructs a Schematron validator from a XSLT file (.xsl).
      Parameters:
      xsltFile - The XSLT file.
      Throws:
      IllegalArgumentException - if the Schematron resource is invalid.
    • SchematronValidator

      public SchematronValidator(byte[] xsltContent)
      Constructs a Schematron validator from the content of a XSLT file (.xsl).
      Parameters:
      xsltContent - The XSLT file content.
      Throws:
      IllegalArgumentException - if the Schematron resource is invalid.
  • Method Details

    • fromSchematronFile

      public static SchematronValidator fromSchematronFile(File schematronFile) throws TransformerException
      Constructs a Schematron validator from a Schematron file (.sch).

      If you are often using this method, you should consider transforming the Schematron file with the SchematronTransformer and storing the result as it is an expensive operation.

      Parameters:
      schematronFile - The Schematron file.
      Returns:
      the constructed Schematron validator.
      Throws:
      TransformerException - if the Schematron content transformation fails.
      IllegalArgumentException - if the Schematron resource is invalid.
    • fromSchematronContent

      public static SchematronValidator fromSchematronContent(byte[] schematronContent) throws TransformerException
      Constructs a Schematron validator from a Schematron content (.sch).

      If you are often using this method, you should consider transforming the Schematron content with the SchematronTransformer and storing the result as it is an expensive operation.

      Parameters:
      schematronContent - The Schematron content.
      Returns:
      the constructed Schematron validator.
      Throws:
      TransformerException - if the Schematron content transformation fails.
      IllegalArgumentException - if the Schematron resource is invalid.
    • validate

      public @Nullable SchematronReport validate(Source source) throws Exception
      Performs the Schematron validation of an XML content.
      Parameters:
      source - The source of the XML content to validate. You can use Sources to convert different objects to Sources.
      Returns:
      the SVRL object containing the result. May be null when interpreting the Schematron failed.
      Throws:
      Exception - in case the transformation somehow goes wrong.