Class ValidURLValidator

java.lang.Object
org.kiwiproject.validation.ValidURLValidator
All Implemented Interfaces:
jakarta.validation.ConstraintValidator<ValidURL,CharSequence>

public class ValidURLValidator extends Object implements jakarta.validation.ConstraintValidator<ValidURL,CharSequence>
Validator for the ValidURL annotation.

The validator can be configured to allow or disallow null values, to allow all URL schemes or only specific schemes, and to specify which schemes are allowed.

Implementation Note:
This validator requires the commons-validator dependency when using it, since it uses Apache Commons Validator's UrlValidator internally.
  • Constructor Details

    • ValidURLValidator

      public ValidURLValidator()
  • Method Details

    • initialize

      public void initialize(ValidURL constraintAnnotation)
      Initializes the validator with the annotation's properties.

      This method is called by the Bean Validation API before validation begins. It configures the internal UrlValidator based on the annotation's properties.

      Specified by:
      initialize in interface jakarta.validation.ConstraintValidator<ValidURL,CharSequence>
      Parameters:
      constraintAnnotation - the annotation instance
    • isValid

      public boolean isValid(CharSequence value, jakarta.validation.ConstraintValidatorContext context)
      Validates that the given value is a valid URL.

      The validation process consists of the following steps:

      1. If the value is null, it is valid only if ValidURL.allowNull() is true.
      2. The value is validated using Apache Commons Validator's UrlValidator.
      3. If the value passes the initial validation, additional edge cases are checked.
      Specified by:
      isValid in interface jakarta.validation.ConstraintValidator<ValidURL,CharSequence>
      Parameters:
      value - the value to validate
      context - the constraint validator context
      Returns:
      true if the value is a valid URL, false otherwise