Package org.kiwiproject.validation
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
UrlValidatorinternally.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinitialize(ValidURL constraintAnnotation) Initializes the validator with the annotation's properties.booleanisValid(CharSequence value, jakarta.validation.ConstraintValidatorContext context) Validates that the given value is a valid URL.
-
Constructor Details
-
ValidURLValidator
public ValidURLValidator()
-
-
Method Details
-
initialize
Initializes the validator with the annotation's properties.This method is called by the Bean Validation API before validation begins. It configures the internal
UrlValidatorbased on the annotation's properties.- Specified by:
initializein interfacejakarta.validation.ConstraintValidator<ValidURL,CharSequence> - Parameters:
constraintAnnotation- the annotation instance
-
isValid
Validates that the given value is a valid URL.The validation process consists of the following steps:
- If the value is null, it is valid only if
ValidURL.allowNull()is true. - The value is validated using Apache Commons Validator's
UrlValidator. - If the value passes the initial validation, additional edge cases are checked.
- Specified by:
isValidin interfacejakarta.validation.ConstraintValidator<ValidURL,CharSequence> - Parameters:
value- the value to validatecontext- the constraint validator context- Returns:
- true if the value is a valid URL, false otherwise
- If the value is null, it is valid only if
-