Class ValidatorManager

java.lang.Object
net.ionite.docval.validation.ValidatorManager

public class ValidatorManager extends Object
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 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

      public 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.
      Parameters:
      unknownKeywords - The way to handle unknown keywords.
    • applyConfig

      public void applyConfig(ConfigData configData) throws IOException, ConfigurationError
      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 data
      ConfigurationError - if the configuration itself contains an error.
    • getValidator

      public DocumentValidator getValidator(String fileName)
      Returns the DocumentValidator instance for the given filename If not loaded yet, tries to load it.
    • hasValidatorsForKeyword

      public boolean hasValidatorsForKeyword(String keyword)
      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

      public void addValidator(String keyword, String fileName, boolean lazyLoad)
      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 file
      lazyLoad - if false, immediately load the validation file. If true, load it upon first use.
    • addValidator

      public void addValidator(String keyword, String fileName, DocumentValidator validator)
      Add a pre-initialized validator for a given (potentially fake) filename
      Parameters:
      keyword - The keyword to add this validator to
      fileName - The (potentially fake) filename that will be used to reference this validator
      validator - An instance of a DocumentValidator implementation class
    • getValidatorsForKeyword

      public ArrayList<DocumentValidator> getValidatorsForKeyword(String keyword)
      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

      public ValidationResult validate(String keyword, byte[] source)
      Validate the given XML data for the given keyword.
      Parameters:
      keyword - The keyword that selects which validation(s) to execute
      source - 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.