public interface ValidateHook
A ValidateHook allows to perform the semantic validation of a document (that is, to check business rules), a task that schemas alone cannot achieve.
Implementations are expected to be thread-safe.
Modifier and Type | Method and Description |
---|---|
default void |
checkingDocument(Document document,
Reason reason,
URL saveAsURL)
Invoked before a document conforming to a schema is validated.
|
default Diagnostic[] |
documentChecked(Document document,
boolean canceled,
Diagnostic[] diagnostics)
Invoked after a document conforming to a schema has been validated.
|
default void checkingDocument(Document document, Reason reason, URL saveAsURL)
Document validation can occur at user's will but also automatically after a document has been created or opened and also before a document is saved.
If this hook modifies the document, it must be careful to
use Document.beginEdit()
/
Document.endEdit()
if needed to.
If this hook modifies the document, it is recommended that it describes to the UndoManager what it has done by adding a label to topmost undo action.
Receiving this notification guarantees that
documentChecked(com.xmlmind.xml.doc.Document, boolean, com.xmlmind.xml.validate.Diagnostic[])
will also being invoked and this, even if
document validation has been canceled by the application.
document
- document that is to be checked for validityreason
- the reason why this method is being invoked;
null
if unknownsaveAsURL
- the new location of the document;
null
if reason!=SAVE_AS
.UndoManager
default Diagnostic[] documentChecked(Document document, boolean canceled, Diagnostic[] diagnostics)
This method can be used to implement semantic validation. Such
validation method must append semantic
warnings (Diagnostic.Severity#SEMANTIC_WARNING
)
and errors (Diagnostic.Severity#SEMANTIC_ERROR
) to the
list of validity warnings and errors passed as third argument.
document
- document having been validatedcanceled
- document validation has been canceled: return
passed diagnostics as isdiagnostics
- (possibly empty) list of warnings and errors found
during validation