Package org.apache.sling.validation
Interface ValidationService
@ProviderType
public interface ValidationService
The
ValidationService
provides methods for finding ValidationModel
s and to trigger validations against those.-
Method Summary
Modifier and TypeMethodDescription@Nullable ValidationModel
getValidationModel
(@NotNull String validatedResourceType, String resourcePath, boolean considerResourceSuperTypeModels) Tries to obtain aValidationModel
that is able to validate aResource
of typevalidatedResourceType
.@Nullable ValidationModel
getValidationModel
(@NotNull Resource resource, boolean considerResourceSuperTypeModels) Tries to obtain aValidationModel
that is able to validate the givenresource
.@NotNull ValidationResult
validate
(@NotNull Resource resource, @NotNull ValidationModel model) Validates aResource
using a specificValidationModel
.@NotNull ValidationResult
validate
(@NotNull ValueMap valueMap, @NotNull ValidationModel model) @NotNull ValidationResult
validateResourceRecursively
(@NotNull Resource resource, boolean enforceValidation, Predicate<Resource> filter, boolean considerResourceSuperTypeModels) Validates aResource
and all child resources recursively by traversing through the resource tree starting from the given resource.
-
Method Details
-
getValidationModel
@Nullable @Nullable ValidationModel getValidationModel(@NotNull @NotNull String validatedResourceType, String resourcePath, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException Tries to obtain aValidationModel
that is able to validate aResource
of typevalidatedResourceType
.- Parameters:
validatedResourceType
- the type ofResources
the model validates, should be either relative (i.e. not start with a "/") or starting with one of the resource resolver's search pathsresourcePath
- the path of the validated resource, may benull
or empty. Must match the applicablePath property of the modelconsiderResourceSuperTypeModels
- iftrue
will also consider the validation model of the resource super type (recursively), otherwise not.- Returns:
- a
ValidationModel
if one is found,null
otherwise - Throws:
IllegalStateException
- in case an invalid validation model was foundIllegalArgumentException
- in case validatedResourceType was blank,null
or absolute but outside of the search paths or some other error occurred while retrieving the models.
-
getValidationModel
@Nullable @Nullable ValidationModel getValidationModel(@NotNull @NotNull Resource resource, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException Tries to obtain aValidationModel
that is able to validate the givenresource
.- Parameters:
resource
- the resource for which to obtain a validation modelconsiderResourceSuperTypeModels
- iftrue
will also consider the validation model of the resource super type (recursively), otherwise not.- Returns:
- a
ValidationModel
if one is found,null
otherwise - Throws:
IllegalStateException
- in case an invalid validation model was foundIllegalArgumentException
- in case resourceType being set on the given resource is blank, not set or absolute but outside of the search paths or some other error occurred while retrieving the models.
-
validate
@NotNull @NotNull ValidationResult validate(@NotNull @NotNull Resource resource, @NotNull @NotNull ValidationModel model) throws SlingValidationException, IllegalStateException Validates aResource
using a specificValidationModel
. If themodel
describes a resource tree, theResourceResolver
associated with theresource
will be used for retrieving information about theresource
's descendants.- Parameters:
resource
- the resource to validatemodel
- the model with which to perform the validation- Returns:
- a
ValidationResult
that provides the necessary information - Throws:
SlingValidationException
- if one validator was called with invalid argumentsIllegalStateException
- if a validator id referenced in the given model could not be resolved
-
validate
@NotNull @NotNull ValidationResult validate(@NotNull @NotNull ValueMap valueMap, @NotNull @NotNull ValidationModel model) throws SlingValidationException Validates aValueMap
or any object adaptable to aValueMap
using a specificValidationModel
. Since thevalueMap
only contains the direct properties of the adapted object, themodel
's descendants description should not be queried for this validation operation.- Parameters:
valueMap
- the map to validatemodel
- the model with which to perform the validation- Returns:
- a
ValidationResult
that provides the necessary information - Throws:
SlingValidationException
- if one validator was called with invalid arguments
-
validateResourceRecursively
@NotNull @NotNull ValidationResult validateResourceRecursively(@NotNull @NotNull Resource resource, boolean enforceValidation, Predicate<Resource> filter, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException, SlingValidationException Validates aResource
and all child resources recursively by traversing through the resource tree starting from the given resource. For all resources which are included in the givenfilter
the accordingValidationModel
is retrieved and validation is called on those resources.- Parameters:
resource
- the root resource which is validatedenforceValidation
- iftrue
will throw anIllegalArgumentException
in case a validation model could not be found for a (not-ignored) resourcefilter
- aPredicate
on a resource which is evaluated to determine whether a given resource should be validated. May benull
in which case all resources are validated. Children of ignored resources are still validated (if this predicate applies to them).considerResourceSuperTypeModels
- iftrue
will also consider the validation model of the resource super type (recursively), otherwise not.- Returns:
- the aggregated
ValidationResult
over all child resource validations - Throws:
IllegalStateException
- in case an invalid validation model was foundIllegalArgumentException
- in case resourceType is absolute but outside of the search paths or if no validation model could be found (and enforceValidation istrue
).SlingValidationException
- if one validator was called with invalid arguments
-