Package org.apache.sling.validation.spi
Interface Validator<T>
- All Known Implementing Classes:
RegexValidator
@ConsumerType
public interface Validator<T>
A
Validator
is responsible for validating a single piece of information according to an internal constraint.-
Field Summary
-
Method Summary
Modifier and TypeMethodDescription@NotNull ValidationResult
validate
(T data, @NotNull ValidatorContext context, @NotNull ValueMap arguments) Validates thedata
and/or thevalueMap
according to the internal constraints of this validator.
-
Field Details
-
PROPERTY_VALIDATOR_ID
EachValidator
must have a service property with namevalidator.id
of typeString
. The validators are only addressable via the value of this property from the validation models. If there are multiple validators registered for the samevalidator.id
, the one with highest service ranking is used. It is recommended to prefix the value of the validator with the providing bundle symbolic name to prevent any name clashes.- See Also:
-
PROPERTY_VALIDATOR_SEVERITY
EachValidator
may have a service property with namevalidator.severity
of typeInteger
. This is taken as the severity of allValidationFailure
s constructed by thisValidator
in case the model has not overwritten the severity. If this property is not set the default severity is being used.- See Also:
-
-
Method Details
-
validate
@NotNull @NotNull ValidationResult validate(@NotNull T data, @NotNull @NotNull ValidatorContext context, @NotNull @NotNull ValueMap arguments) throws SlingValidationException Validates thedata
and/or thevalueMap
according to the internal constraints of this validator. The validator can enforce the type of the given data just by setting the appropriate parameter typeT
which can be any non-primitive class. Depending on whether this type is an array or not thevalidate
method is called differently:T is array type Valuemap contains array value validate
is called...yes yes once per property with data
containing the full arrayyes no once per property with data
containing a single element arrayno yes once per element in the property array with data
containing one array elementno no once per property with data
containing the value of the propertyT
the validator is not called, but validation fails.- Parameters:
data
- the data to validate (primary property), nevernull
.context
- the validation context contains additional information about the data to be validated, nevernull
.arguments
- the parameterization of the validator. Nevernull
but might be the empty map.- Returns:
- the validation result (encapsulates the validation status as well as messages).
- Throws:
SlingValidationException
- if some expected arguments are missing from the arguments map
-