Package org.apache.sling.validation
Interface ValidationService
@ProviderType
public interface ValidationService
The 
ValidationService provides methods for finding ValidationModels and to trigger validations against those.- 
Method SummaryModifier and TypeMethodDescription@Nullable ValidationModelgetValidationModel(@NotNull String validatedResourceType, String resourcePath, boolean considerResourceSuperTypeModels) Tries to obtain aValidationModelthat is able to validate aResourceof typevalidatedResourceType.@Nullable ValidationModelgetValidationModel(@NotNull Resource resource, boolean considerResourceSuperTypeModels) Tries to obtain aValidationModelthat is able to validate the givenresource.@NotNull ValidationResultvalidate(@NotNull Resource resource, @NotNull ValidationModel model) Validates aResourceusing a specificValidationModel.@NotNull ValidationResultvalidate(@NotNull ValueMap valueMap, @NotNull ValidationModel model) @NotNull ValidationResultvalidateResourceRecursively(@NotNull Resource resource, boolean enforceValidation, Predicate<Resource> filter, boolean considerResourceSuperTypeModels) Validates aResourceand 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 aValidationModelthat is able to validate aResourceof typevalidatedResourceType.- Parameters:
- validatedResourceType- the type of- Resourcesthe model validates, should be either relative (i.e. not start with a "/") or starting with one of the resource resolver's search paths
- resourcePath- the path of the validated resource, may be- nullor empty. Must match the applicablePath property of the model
- considerResourceSuperTypeModels- if- truewill also consider the validation model of the resource super type (recursively), otherwise not.
- Returns:
- a ValidationModelif one is found,nullotherwise
- Throws:
- IllegalStateException- in case an invalid validation model was found
- IllegalArgumentException- in case validatedResourceType was blank,- nullor 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 aValidationModelthat is able to validate the givenresource.- Parameters:
- resource- the resource for which to obtain a validation model
- considerResourceSuperTypeModels- if- truewill also consider the validation model of the resource super type (recursively), otherwise not.
- Returns:
- a ValidationModelif one is found,nullotherwise
- Throws:
- IllegalStateException- in case an invalid validation model was found
- IllegalArgumentException- 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 aResourceusing a specificValidationModel. If themodeldescribes a resource tree, theResourceResolverassociated with theresourcewill be used for retrieving information about theresource's descendants.- Parameters:
- resource- the resource to validate
- model- the model with which to perform the validation
- Returns:
- a ValidationResultthat provides the necessary information
- Throws:
- SlingValidationException- if one validator was called with invalid arguments
- IllegalStateException- 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 aValueMapor any object adaptable to aValueMapusing a specificValidationModel. Since thevalueMaponly 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 validate
- model- the model with which to perform the validation
- Returns:
- a ValidationResultthat 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 aResourceand all child resources recursively by traversing through the resource tree starting from the given resource. For all resources which are included in the givenfilterthe accordingValidationModelis retrieved and validation is called on those resources.- Parameters:
- resource- the root resource which is validated
- enforceValidation- if- truewill throw an- IllegalArgumentExceptionin case a validation model could not be found for a (not-ignored) resource
- filter- a- Predicateon a resource which is evaluated to determine whether a given resource should be validated. May be- nullin which case all resources are validated. Children of ignored resources are still validated (if this predicate applies to them).
- considerResourceSuperTypeModels- if- truewill also consider the validation model of the resource super type (recursively), otherwise not.
- Returns:
- the aggregated ValidationResultover all child resource validations
- Throws:
- IllegalStateException- in case an invalid validation model was found
- IllegalArgumentException- in case resourceType is absolute but outside of the search paths or if no validation model could be found (and enforceValidation is- true).
- SlingValidationException- if one validator was called with invalid arguments
 
 
-