Chapter 5. Custom validation hook

Table of Contents
1. A sample validation hook
2. Compiling and testing the sample validation hook

What is a custom validation hook?

A validation hook is some code written in Java™ notified by XXE before and after a document is checked for validity. A document is checked for validity on demand (menu item ToolsCheck Validity) but also automatically, after just being opened and before being saved to disk.

This mechanism has been created to perform semantic validation beyond what can be done using a DTD or schema.

In some cases, an alternative to writing a validation hook in Java™ is to write a Schematron and declare it in the configuration file by the means of a schematron configuration element in XMLmind XML Editor - Configuration and Deployment.

Where to declare a custom validation hook?

A validation hook is declared in an XXE configuration file by the means of the validateHook configuration element in XMLmind XML Editor - Configuration and Deployment. DITA topic example:

<validateHook name="checkTopicId">
  <class>com.xmlmind.xmleditext.dita.CheckTopicId</class>
</validateHook>

How to implement a custom validation hook?

Implement interface ValidateHook. The ValidateHook interface is simple and straightforward:

MethodDescription
checkingDocument

Invoked before a document conforming to a schema is validated.

Therefore validation hooks automatically fixing problems in the document being edited must implement method checkingDocument.

documentChecked

Invoked after a document conforming to a DTD or schema has been validated.

Therefore validation hooks reporting semantic errors must implement method documentChecked.