Skip to content

Module: husky validation service

Quentin Ligier edited this page Jan 21, 2022 · 5 revisions

Module: husky-validation-service

XML Schema validation

In the org.husky.validation.service.schema package is implemented an XML Schema validator that is initialized with an XML Schema Definition file (xsd) and can then validate any XML file.

final var validator = new XmlSchemaValidator(new File("schema.xsd"));
final var result = validator.validate(new File("file.xml"));
result.getWarnings();
if (!result.isValid()) {
  result.getErrors();
  result.getFatalErrors();
}

Schematron validation

In the org.husky.validation.service.schematron package is implemented a Schematron validator based on the ph-schematron library. Schematron definitions are stored in .sch files and need to be compiled to .xslt files before being used by the validator. This is a costly operation, so if a definition is often used, the better choice is to transform it manually to XSLT with the SchematronTransformer once, store it and use it each time. Else, the Schematron definition can be directly passed to the validator (SchematronValidator.fromSchematronFile and SchematronValidator.fromSchematronContent).

PDF/A validation

In the org.husky.validation.service.pdf package is implemented a PDF/A validator.

final var validator = new PdfA12Validator();
final var pdfContent = Files.readString(Path.of("file.pdf");
final var result = validator.validate(pdfContent);
if (!result.isCompliant()) {
  log.error("The PDF file is not compliant");
}

Validation passes if the PDF document conforms to the A-1a, A1-b, A-2a, A-2b or A-2u level. It shall not be password protected.