Package net.ionite.docval.validation
Class ValidatorManager
java.lang.Object
net.ionite.docval.validation.ValidatorManager
The validator manager holds any number of validators for a specific keyword,
with an option to automatically reload the underlying validation definition
(such as an xsd or xslt).
It keeps any validator in memory, so that it can be reused for multiple
keywords
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addValidator
(String keyword, String fileName, boolean lazyLoad) Adds the Validator for the given file to the list of entries for the given keyword.void
addValidator
(String keyword, String fileName, DocumentValidator validator) Add a pre-initialized validator for a given (potentially fake) filenamevoid
applyConfig
(ConfigData configData) Apply the given configuration data.getValidator
(String fileName) Returns the DocumentValidator instance for the given filename If not loaded yet, tries to load it.getValidatorsForKeyword
(String keyword) Return the validators for the given keywordboolean
hasValidatorsForKeyword
(String keyword) Check whether there are validators for the given keywordvoid
setAutoReload
(boolean value) Enable or disable autoreload.void
setUnknownKeywords
(ConfigData.UnknownKeywords unknownKeywords) Set the way the validator manager should handle requests for unknown keywords.
The keyword specifies which validation(s) to run, and can be derived automatically from documents.Validate the given XML data for the given keyword.
-
Constructor Details
-
ValidatorManager
public ValidatorManager()Construct a new ValidatorManager
-
-
Method Details
-
setAutoReload
public void setAutoReload(boolean value) Enable or disable autoreload. Autoreload will automatically reload validation files if they change on disk.
When autoreload is enabled, each time a validation file is used, the last-modified time of the on-disk file is checked, and the file is reloaded if it has been changed.
Note that this does perform any checks on the main configuration file: any change there needs a full reload of the entire program. Autoreload can only reload already-configured files.- Parameters:
value
- boolean specifying whether to enable or disable autoreload
-
setUnknownKeywords
Set the way the validator manager should handle requests for unknown keywords.
The keyword specifies which validation(s) to run, and can be derived automatically from documents.- Parameters:
unknownKeywords
- The way to handle unknown keywords.
-
applyConfig
Apply the given configuration data. If successful, this removes and replaces all validators and keywords that were added through earlier calls to any of applyConfig() or addValidator(). If it fails, the currently running set is kept.- Parameters:
configData
- the configuration data to apply- Throws:
IOException
- If there is an I/O error reading any file specified in the configuration dataConfigurationError
- if the configuration itself contains an error.
-
getValidator
Returns the DocumentValidator instance for the given filename If not loaded yet, tries to load it. -
hasValidatorsForKeyword
Check whether there are validators for the given keyword- Parameters:
keyword
- The keyword to check- Returns:
- true if there are validators configured for the keyword, false if not
-
addValidator
Adds the Validator for the given file to the list of entries for the given keyword. Creates the keyword entry if it doesn't exist. No-op if the validator file is already in the list for this keyword.- Parameters:
keyword
- The keyword to add this valdidator to.fileName
- File name of the validation filelazyLoad
- if false, immediately load the validation file. If true, load it upon first use.
-
addValidator
Add a pre-initialized validator for a given (potentially fake) filename- Parameters:
keyword
- The keyword to add this validator tofileName
- The (potentially fake) filename that will be used to reference this validatorvalidator
- An instance of a DocumentValidator implementation class
-
getValidatorsForKeyword
Return the validators for the given keyword- Parameters:
keyword
- the keyword to get the validators for- Returns:
- ArrayList of DocumentValidator implementation instances, configured for the given keyword. Returns an empty list if the keyword is not known.
-
validate
Validate the given XML data for the given keyword.- Parameters:
keyword
- The keyword that selects which validation(s) to executesource
- byte-array containing the XML document- Returns:
- ValidationResult The result of the validation
- Throws:
ValidatorException
- if there is no configuration for the given keyword, and the manager is configured to raise an exception in that case.
-