You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2024/12/12 14:02:41 UTC
(sling-org-apache-sling-validation-api) 02/03: SLING-12553 apply spotless formatting
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-validation-api.git
commit 9d504bb1cbeac7875e775fe64eda43cee89d55b7
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Thu Dec 12 14:40:12 2024 +0100
SLING-12553 apply spotless formatting
---
pom.xml | 10 ++--
.../sling/validation/SlingValidationException.java | 3 +-
.../apache/sling/validation/ValidationFailure.java | 9 ++--
.../apache/sling/validation/ValidationResult.java | 4 +-
.../apache/sling/validation/ValidationService.java | 34 ++++++++----
.../sling/validation/model/ChildResource.java | 19 ++++---
.../sling/validation/model/ResourceProperty.java | 15 +++---
.../sling/validation/model/ValidationModel.java | 23 ++++----
.../validation/model/ValidatorInvocation.java | 17 +++---
.../model/spi/ValidationModelProvider.java | 15 +++---
.../model/spi/ValidationModelRetriever.java | 5 +-
.../org/apache/sling/validation/spi/Validator.java | 21 ++++----
.../sling/validation/spi/ValidatorContext.java | 15 +++---
.../spi/support/DefaultValidationFailure.java | 63 +++++++++++-----------
.../spi/support/DefaultValidationResult.java | 23 +++++---
15 files changed, 157 insertions(+), 119 deletions(-)
diff --git a/pom.xml b/pom.xml
index c019856..42f8644 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,17 +32,17 @@
<name>Apache Sling Validation Framework API</name>
<description>The Apache Sling Validation Framework API</description>
- <properties>
- <sling.java.version>8</sling.java.version>
- <project.build.outputTimestamp>2020-01-22T15:10:38Z</project.build.outputTimestamp>
- </properties>
-
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-validation-api.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-validation-api.git</developerConnection>
<url>https://github.com/apache/sling-org-apache-sling-validation-api.git</url>
</scm>
+ <properties>
+ <sling.java.version>8</sling.java.version>
+ <project.build.outputTimestamp>2020-01-22T15:10:38Z</project.build.outputTimestamp>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
diff --git a/src/main/java/org/apache/sling/validation/SlingValidationException.java b/src/main/java/org/apache/sling/validation/SlingValidationException.java
index 4fad6c6..c58e07e 100644
--- a/src/main/java/org/apache/sling/validation/SlingValidationException.java
+++ b/src/main/java/org/apache/sling/validation/SlingValidationException.java
@@ -31,9 +31,8 @@ public class SlingValidationException extends RuntimeException {
public SlingValidationException(String message) {
super(message);
}
-
+
public SlingValidationException(String message, Throwable cause) {
super(message, cause);
}
-
}
diff --git a/src/main/java/org/apache/sling/validation/ValidationFailure.java b/src/main/java/org/apache/sling/validation/ValidationFailure.java
index ced5a95..b30ea3f 100644
--- a/src/main/java/org/apache/sling/validation/ValidationFailure.java
+++ b/src/main/java/org/apache/sling/validation/ValidationFailure.java
@@ -30,22 +30,23 @@ public interface ValidationFailure {
* @param resourceBundle ResourceBundle in which to look up the according message (used for i18n), if {@code null} is given, the default resource bundle is used.
* @return the failure message
*/
- @NotNull String getMessage(ResourceBundle resourceBundle);
+ @NotNull
+ String getMessage(ResourceBundle resourceBundle);
/**
* Returns the relative location of the property/resource/value which triggered this validation failure.
- * The location
+ * The location
* <ul>
* <li>is relative to the resource given in the first parameter in case it was returned by {@link ValidationService#validate(org.apache.sling.api.resource.Resource, org.apache.sling.validation.model.ValidationModel)} or {@link ValidationService#validateResourceRecursively(org.apache.sling.api.resource.Resource, boolean, java.util.function.Predicate, boolean)} or</li>
* <li>contains just the value name in case it was returned by {@link ValidationService#validate(org.apache.sling.api.resource.ValueMap, org.apache.sling.validation.model.ValidationModel)}</li>
* </ul>
* @return the location (usually the validated resource's property path).
*/
- @NotNull String getLocation();
+ @NotNull
+ String getLocation();
/**
* @return the severity of this validation failure. If no explicit severity was set either in the validation model or in the validator, this returns {@code 0}.
*/
int getSeverity();
-
}
diff --git a/src/main/java/org/apache/sling/validation/ValidationResult.java b/src/main/java/org/apache/sling/validation/ValidationResult.java
index f449cab..e4491b0 100644
--- a/src/main/java/org/apache/sling/validation/ValidationResult.java
+++ b/src/main/java/org/apache/sling/validation/ValidationResult.java
@@ -23,7 +23,6 @@ import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;
-
/**
* A {@code ValidationResult} contains validation information either from a single {@link org.apache.sling.validation.spi.Validator} or from multiple Validator invocations.
*/
@@ -42,5 +41,6 @@ public interface ValidationResult {
*
* @return the validation's failures (never {@code null})
*/
- @NotNull List<ValidationFailure> getFailures();
+ @NotNull
+ List<ValidationFailure> getFailures();
}
diff --git a/src/main/java/org/apache/sling/validation/ValidationService.java b/src/main/java/org/apache/sling/validation/ValidationService.java
index 88fc522..0dbd9d6 100644
--- a/src/main/java/org/apache/sling/validation/ValidationService.java
+++ b/src/main/java/org/apache/sling/validation/ValidationService.java
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -37,7 +37,7 @@ public interface ValidationService {
/**
* Tries to obtain a {@link ValidationModel} that is able to validate a {@code Resource} of type {@code validatedResourceType}.
*
- * @param validatedResourceType the type of {@code Resources} the model validates, should be either relative
+ * @param validatedResourceType the type of {@code Resources} the model validates, should be either relative
* (i.e. not start with a "/") or starting with one of the resource resolver's search paths
* @param resourcePath the path of the validated resource, may be {@code null} or empty. Must match the applicablePath property of the model
* @param considerResourceSuperTypeModels if {@code true} will also consider the validation model of the resource super type (recursively), otherwise not.
@@ -45,7 +45,10 @@ public interface ValidationService {
* @throws IllegalStateException in case an invalid validation model was found
* @throws IllegalArgumentException in case validatedResourceType was blank, {@code null} or absolute but outside of the search paths or some other error occurred while retrieving the models.
*/
- @Nullable ValidationModel getValidationModel(@NotNull String validatedResourceType, String resourcePath, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException;
+ @Nullable
+ ValidationModel getValidationModel(
+ @NotNull String validatedResourceType, String resourcePath, boolean considerResourceSuperTypeModels)
+ throws IllegalStateException, IllegalArgumentException;
/**
* Tries to obtain a {@link ValidationModel} that is able to validate the given {@code resource}.
@@ -56,7 +59,9 @@ public interface ValidationService {
* @throws IllegalStateException in case an invalid validation model was found
* @throws 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.
*/
- @Nullable ValidationModel getValidationModel(@NotNull Resource resource, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException;
+ @Nullable
+ ValidationModel getValidationModel(@NotNull Resource resource, boolean considerResourceSuperTypeModels)
+ throws IllegalStateException, IllegalArgumentException;
/**
* Validates a {@link Resource} using a specific {@link ValidationModel}. If the {@code model} describes a resource tree,
@@ -69,7 +74,9 @@ public interface ValidationService {
* @throws SlingValidationException if one validator was called with invalid arguments
* @throws IllegalStateException if a validator id referenced in the given model could not be resolved
*/
- @NotNull ValidationResult validate(@NotNull Resource resource, @NotNull ValidationModel model) throws SlingValidationException, IllegalStateException;
+ @NotNull
+ ValidationResult validate(@NotNull Resource resource, @NotNull ValidationModel model)
+ throws SlingValidationException, IllegalStateException;
/**
* Validates a {@link ValueMap} or any object adaptable to a {@code ValueMap} using a specific {@link ValidationModel}. Since the
@@ -81,14 +88,16 @@ public interface ValidationService {
* @return a {@link ValidationResult} that provides the necessary information
* @throws SlingValidationException if one validator was called with invalid arguments
*/
- @NotNull ValidationResult validate(@NotNull ValueMap valueMap, @NotNull ValidationModel model) throws SlingValidationException;
+ @NotNull
+ ValidationResult validate(@NotNull ValueMap valueMap, @NotNull ValidationModel model)
+ throws SlingValidationException;
/**
* Validates a {@link Resource} and all child resources recursively by traversing through the resource tree starting from the given resource.
* For all resources which are included in the given {@code filter} the according {@link ValidationModel} is retrieved and validation is called on those resources.
* @param resource the root resource which is validated
- * @param enforceValidation if {@code true} will throw an {@link IllegalArgumentException} in case a validation model could not be found for a (not-ignored) resource
- * @param filter a {@link Predicate} on a resource which is evaluated to determine whether a given resource should be validated. May be {@code null} in which case all resources are validated.
+ * @param enforceValidation if {@code true} will throw an {@link IllegalArgumentException} in case a validation model could not be found for a (not-ignored) resource
+ * @param filter a {@link Predicate} on a resource which is evaluated to determine whether a given resource should be validated. May be {@code null} in which case all resources are validated.
* Children of ignored resources are still validated (if this predicate applies to them).
* @param considerResourceSuperTypeModels if {@code true} will also consider the validation model of the resource super type (recursively), otherwise not.
* @return the aggregated {@link ValidationResult} over all child resource validations
@@ -96,6 +105,11 @@ public interface ValidationService {
* @throws IllegalArgumentException in case resourceType is absolute but outside of the search paths or if no validation model could be found (and enforceValidation is {@code true}).
* @throws SlingValidationException if one validator was called with invalid arguments
*/
- @NotNull ValidationResult validateResourceRecursively(@NotNull Resource resource, boolean enforceValidation, Predicate<Resource> filter, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException, SlingValidationException;
-
+ @NotNull
+ ValidationResult validateResourceRecursively(
+ @NotNull Resource resource,
+ boolean enforceValidation,
+ Predicate<Resource> filter,
+ boolean considerResourceSuperTypeModels)
+ throws IllegalStateException, IllegalArgumentException, SlingValidationException;
}
diff --git a/src/main/java/org/apache/sling/validation/model/ChildResource.java b/src/main/java/org/apache/sling/validation/model/ChildResource.java
index 98ce24f..7b0583a 100644
--- a/src/main/java/org/apache/sling/validation/model/ChildResource.java
+++ b/src/main/java/org/apache/sling/validation/model/ChildResource.java
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;
-
/**
* Defines the validation rules for a child resource, allowing {@link ValidationModel}s to be applied to {@link
* org.apache.sling.api.resource.Resource} trees.
@@ -39,18 +38,20 @@ public interface ChildResource {
*
* @return the name
*/
- @NotNull String getName();
-
+ @NotNull
+ String getName();
+
/**
* Returns this resource's name pattern. In case this is not returning {@code null}, this pattern is used for finding the child resources which should be validated.
*
* @return the name pattern (if one is set) or {@code null}
*/
- @Nullable Pattern getNamePattern();
+ @Nullable
+ Pattern getNamePattern();
/**
* Returns {@code true} if at least one resource matching the name/namePattern is required.
- *
+ *
* @return {@code true} if the resource is required, {@code false} otherwise
*/
boolean isRequired();
@@ -60,11 +61,13 @@ public interface ChildResource {
*
* @return the properties list. Never {@code null}.
*/
- @NotNull Collection<ResourceProperty> getProperties();
-
+ @NotNull
+ Collection<ResourceProperty> getProperties();
+
/**
* Returns the child resources of this part of the Validation Model
* @return child resources. Never {@code null}.
*/
- @NotNull Collection<ChildResource> getChildren();
+ @NotNull
+ Collection<ChildResource> getChildren();
}
diff --git a/src/main/java/org/apache/sling/validation/model/ResourceProperty.java b/src/main/java/org/apache/sling/validation/model/ResourceProperty.java
index 894acac..fa03ef1 100644
--- a/src/main/java/org/apache/sling/validation/model/ResourceProperty.java
+++ b/src/main/java/org/apache/sling/validation/model/ResourceProperty.java
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -37,14 +37,16 @@ public interface ResourceProperty {
*
* @return the name
*/
- @NotNull String getName();
-
+ @NotNull
+ String getName();
+
/**
* Returns the name pattern for this property. In case this is not returning {@code null}, this pattern is used for finding the properties which should be validated.
*
* @return the name pattern (if one is set) or {@code null}
*/
- @Nullable Pattern getNamePattern();
+ @Nullable
+ Pattern getNamePattern();
/**
*
@@ -54,7 +56,7 @@ public interface ResourceProperty {
/**
* Returns {@code true} if at least one property matching the name/namePattern is required.
- *
+ *
* @return {@code true} if the property is required, {@code false} otherwise
*/
boolean isRequired();
@@ -64,5 +66,6 @@ public interface ResourceProperty {
*
* @return the {@link List} of {@link ValidatorInvocation}s
*/
- @NotNull List<ValidatorInvocation> getValidatorInvocations();
+ @NotNull
+ List<ValidatorInvocation> getValidatorInvocations();
}
diff --git a/src/main/java/org/apache/sling/validation/model/ValidationModel.java b/src/main/java/org/apache/sling/validation/model/ValidationModel.java
index dd29bba..246bb5f 100644
--- a/src/main/java/org/apache/sling/validation/model/ValidationModel.java
+++ b/src/main/java/org/apache/sling/validation/model/ValidationModel.java
@@ -23,7 +23,6 @@ import java.util.Collection;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;
-
/**
* A {@code ValidationModel} defines the validation rules that a resource tree has to pass.
*/
@@ -35,35 +34,39 @@ public interface ValidationModel {
*
* @return the properties list (never {@code null}, but might be empty list)
*/
- @NotNull Collection<ResourceProperty> getResourceProperties();
+ @NotNull
+ Collection<ResourceProperty> getResourceProperties();
/**
* Returns the type of resource this model validates.
*
* @return the resource type to be validated, never {@code null}
*/
- @NotNull String getValidatingResourceType();
+ @NotNull
+ String getValidatingResourceType();
/**
- * Returns the paths under which resources will be validated by this model.
- * Might return a single element array containing only the empty string,
+ * Returns the paths under which resources will be validated by this model.
+ * Might return a single element array containing only the empty string,
* in which case the validation model has no path restriction.
*
* @return a path array. Is never {@code null} nor an empty collection.
*/
- @NotNull Collection<String> getApplicablePaths();
+ @NotNull
+ Collection<String> getApplicablePaths();
/**
* Returns the expected children for a resource validated by this model.
*
* @return the children list (can be empty if there are no children), never {@code null}
*/
- @NotNull Collection<ChildResource> getChildren();
+ @NotNull
+ Collection<ChildResource> getChildren();
/**
- *
+ *
* @return a string indicating the original source of this validation model, e.g. a resource path
*/
- @NotNull String getSource();
-
+ @NotNull
+ String getSource();
}
diff --git a/src/main/java/org/apache/sling/validation/model/ValidatorInvocation.java b/src/main/java/org/apache/sling/validation/model/ValidatorInvocation.java
index d0835bc..892003a 100644
--- a/src/main/java/org/apache/sling/validation/model/ValidatorInvocation.java
+++ b/src/main/java/org/apache/sling/validation/model/ValidatorInvocation.java
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -24,7 +24,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;
-
/**
* Defines a specific validator invocation for a given property (without actually exposing a reference to the underlying {@link Validator}).
*/
@@ -32,21 +31,23 @@ import org.osgi.annotation.versioning.ProviderType;
public interface ValidatorInvocation {
/**
- *
+ *
* @return the validator id of the {@link Validator} which is supposed to be called.
*/
- @NotNull String getValidatorId();
+ @NotNull
+ String getValidatorId();
/**
- *
+ *
* @return the parameterization of the {@link Validator#validate(Object, org.apache.sling.validation.spi.ValidatorContext, ValueMap)} call (never {@code null}, but might be empty map)
*/
- @NotNull ValueMap getParameters();
+ @NotNull
+ ValueMap getParameters();
/**
* @return the severity of validation failures emitted for this usage of the validator (as being set in the model).
* May be {@code null} in case it was not set on the model.
*/
- @Nullable Integer getSeverity();
-
+ @Nullable
+ Integer getSeverity();
}
diff --git a/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java b/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java
index ffb220e..c5af134 100644
--- a/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java
+++ b/src/main/java/org/apache/sling/validation/model/spi/ValidationModelProvider.java
@@ -25,26 +25,25 @@ import org.apache.sling.validation.model.ValidationModel;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ProviderType;
-
/**
- * All providers of {@link ValidationModel}s must implement this interface. Caching of validation models should be implemented in the provider itself,
- * because the providers are asked potentially multiple times for each {@link ValidationService#getValidationModel(org.apache.sling.api.resource.Resource, boolean)} or
+ * All providers of {@link ValidationModel}s must implement this interface. Caching of validation models should be implemented in the provider itself,
+ * because the providers are asked potentially multiple times for each {@link ValidationService#getValidationModel(org.apache.sling.api.resource.Resource, boolean)} or
* {@link ValidationService#getValidationModel(String, String, boolean)} call.
- *
+ *
*/
@ProviderType
public interface ValidationModelProvider {
/**
* Retrieves the models responsible for validating the given resourceType.
- *
+ *
* @param relativeResourceType the relative resource (relative to one of the resource resolver's search paths)
* @return a List of {@link ValidationModel}s. Never {@code null}, but might be empty collection in case no
- * model for the given resource type could be found. The order which model gets active is mostly determined by {@link ValidationModel#getApplicablePaths()} (longest path match wins)
+ * model for the given resource type could be found. The order which model gets active is mostly determined by {@link ValidationModel#getApplicablePaths()} (longest path match wins)
* but in case there are multiple models having the same applicable path, the order being returned here is considered (i.e. the first one is taken).
* @throws IllegalStateException
* in case a validation model was found but it is invalid
*/
- @NotNull List<ValidationModel> getValidationModels(@NotNull String relativeResourceType) throws IllegalStateException;
-
+ @NotNull
+ List<ValidationModel> getValidationModels(@NotNull String relativeResourceType) throws IllegalStateException;
}
diff --git a/src/main/java/org/apache/sling/validation/model/spi/ValidationModelRetriever.java b/src/main/java/org/apache/sling/validation/model/spi/ValidationModelRetriever.java
index 0074a81..51fffd8 100644
--- a/src/main/java/org/apache/sling/validation/model/spi/ValidationModelRetriever.java
+++ b/src/main/java/org/apache/sling/validation/model/spi/ValidationModelRetriever.java
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -34,5 +34,6 @@ public interface ValidationModelRetriever {
* @return a validation model which should be used for validation or {@code null}, if no validation model could be found
* @throws IllegalStateException in case some error occurred during looking up models
*/
- public @Nullable ValidationModel getValidationModel(@NotNull String resourceType, String resourcePath, boolean considerResourceSuperTypeModels);
+ public @Nullable ValidationModel getValidationModel(
+ @NotNull String resourceType, String resourcePath, boolean considerResourceSuperTypeModels);
}
diff --git a/src/main/java/org/apache/sling/validation/spi/Validator.java b/src/main/java/org/apache/sling/validation/spi/Validator.java
index 3936efb..5940038 100644
--- a/src/main/java/org/apache/sling/validation/spi/Validator.java
+++ b/src/main/java/org/apache/sling/validation/spi/Validator.java
@@ -25,17 +25,16 @@ import org.apache.sling.validation.ValidationResult;
import org.jetbrains.annotations.NotNull;
import org.osgi.annotation.versioning.ConsumerType;
-
/**
* A {@code Validator} is responsible for validating a single piece of information according to an internal constraint.
*/
@ConsumerType
-public interface Validator <T> {
+public interface Validator<T> {
/**
* Validates the {@code data} and/or the {@code valueMap} according to the internal constraints of this validator.
- *
- * The validator can enforce the type of the given data just by setting the appropriate parameter type {@code T} which can be any non-primitive class.
+ *
+ * The validator can enforce the type of the given data just by setting the appropriate parameter type {@code T} which can be any non-primitive class.
* Depending on whether this type is an array or not the {@code validate} method is called differently:
* <table summary="">
* <tr>
@@ -72,18 +71,20 @@ public interface Validator <T> {
* @return the validation result (encapsulates the validation status as well as messages).
* @throws SlingValidationException if some expected arguments are missing from the arguments map
*/
- @NotNull ValidationResult validate(@NotNull T data, @NotNull ValidatorContext context, @NotNull ValueMap arguments) throws SlingValidationException;
-
+ @NotNull
+ ValidationResult validate(@NotNull T data, @NotNull ValidatorContext context, @NotNull ValueMap arguments)
+ throws SlingValidationException;
+
/**
- * Each {@link Validator} must have a service property with name {@code validator.id} of type {@link String}. The validators are only addressable via the value of this property
+ * Each {@link Validator} must have a service property with name {@code validator.id} of type {@link String}. The validators are only addressable via the value of this property
* from the validation models. If there are multiple validators registered for the same {@code validator.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.
*/
String PROPERTY_VALIDATOR_ID = "validator.id";
-
+
/***
- * Each {@link Validator} may have a service property with name {@code validator.severity} of type {@link Integer}. This is taken as the severity of all
- * {@link ValidationFailure}s constructed by this {@link Validator} in case the model has not overwritten the severity.
+ * Each {@link Validator} may have a service property with name {@code validator.severity} of type {@link Integer}. This is taken as the severity of all
+ * {@link ValidationFailure}s constructed by this {@link Validator} in case the model has not overwritten the severity.
* If this property is not set the default severity is being used.
*/
String PROPERTY_VALIDATOR_SEVERITY = "validator.severity";
diff --git a/src/main/java/org/apache/sling/validation/spi/ValidatorContext.java b/src/main/java/org/apache/sling/validation/spi/ValidatorContext.java
index ba942df..1f0cb8a 100644
--- a/src/main/java/org/apache/sling/validation/spi/ValidatorContext.java
+++ b/src/main/java/org/apache/sling/validation/spi/ValidatorContext.java
@@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;
-
/**
* Used as parameter for each call of {@link Validator#validate(Object, ValidatorContext, ValueMap)}
* Exposes additional information about the context in which the validation was called.
@@ -38,26 +37,30 @@ public interface ValidatorContext {
/**
* @return the relative location of the property which should be checked by the validator. Refers to the 'data' parameter of {@link Validator#validate(Object, ValidatorContext, ValueMap)}
*/
- @NotNull String getLocation();
+ @NotNull
+ String getLocation();
/**
* @return all properties of the validated resource/valuemap (only used for validations considering multiple properties), never {@code null}.
*/
- @NotNull ValueMap getValueMap();
+ @NotNull
+ ValueMap getValueMap();
/**
* @return the resource on which the validation was triggered. {@code null} in case the validation was triggered on a {@link ValueMap} (via {@link ValidationService#validate(ValueMap, org.apache.sling.validation.model.ValidationModel)}).
*/
- @Nullable Resource getResource();
+ @Nullable
+ Resource getResource();
/**
* Returns the severity to be issued for validation failures in this context.
* @return the severity of the validation failure.
*/
int getSeverity();
-
+
/**
* @return resource bundle which should be able to give out the error message of the {@link Validator} in English.
*/
- @NotNull ResourceBundle getDefaultResourceBundle();
+ @NotNull
+ ResourceBundle getDefaultResourceBundle();
}
diff --git a/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationFailure.java b/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationFailure.java
index 9f64b0b..2549ca8 100644
--- a/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationFailure.java
+++ b/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationFailure.java
@@ -36,9 +36,10 @@ import org.osgi.annotation.versioning.ProviderType;
public final class DefaultValidationFailure implements ValidationFailure, Serializable {
/**
- *
+ *
*/
private static final long serialVersionUID = -1748031688917555982L;
+
private final @NotNull String location;
private final @NotNull String messageKey;
private final Object[] messageArguments;
@@ -46,18 +47,19 @@ public final class DefaultValidationFailure implements ValidationFailure, Serial
private final int severity;
/**
- * Constructor of a validation failure.
- * @param validationContext the context from which to extract location, severity and default resource bundle
- * @param messageKey the key to look up in the resource bundle
- * @param messageArguments the arguments to be used with the looked up value from the resource bundle (given in {@link #getMessage(ResourceBundle)}
- */
- public DefaultValidationFailure(@NotNull ValidatorContext validationContext, @NotNull String messageKey, Object... messageArguments) {
- this.location = validationContext.getLocation();
- this.severity = validationContext.getSeverity();
- this.defaultResourceBundle = validationContext.getDefaultResourceBundle();
- this.messageKey = messageKey;
- this.messageArguments = messageArguments;
- }
+ * Constructor of a validation failure.
+ * @param validationContext the context from which to extract location, severity and default resource bundle
+ * @param messageKey the key to look up in the resource bundle
+ * @param messageArguments the arguments to be used with the looked up value from the resource bundle (given in {@link #getMessage(ResourceBundle)}
+ */
+ public DefaultValidationFailure(
+ @NotNull ValidatorContext validationContext, @NotNull String messageKey, Object... messageArguments) {
+ this.location = validationContext.getLocation();
+ this.severity = validationContext.getSeverity();
+ this.defaultResourceBundle = validationContext.getDefaultResourceBundle();
+ this.messageKey = messageKey;
+ this.messageArguments = messageArguments;
+ }
/**
* Constructor of a validation failure.
@@ -68,7 +70,12 @@ public final class DefaultValidationFailure implements ValidationFailure, Serial
* @param messageKey the key to look up in the resource bundle
* @param messageArguments the arguments to be used with the looked up value from the resource bundle (given in {@link #getMessage(ResourceBundle)}
*/
- public DefaultValidationFailure(@NotNull String location, int severity, @NotNull ResourceBundle defaultResourceBundle, @NotNull String messageKey, Object... messageArguments) {
+ public DefaultValidationFailure(
+ @NotNull String location,
+ int severity,
+ @NotNull ResourceBundle defaultResourceBundle,
+ @NotNull String messageKey,
+ Object... messageArguments) {
this.location = location;
this.severity = severity;
this.messageKey = messageKey;
@@ -82,8 +89,10 @@ public final class DefaultValidationFailure implements ValidationFailure, Serial
resourceBundle = defaultResourceBundle;
}
if (resourceBundle == null) {
- // this should only happen if this class was deserialized because there the default resource bundle is missing
- return "No defaultResourceBundle found to resolve, messageKey = " + messageKey + ", messageArguments: " + Arrays.toString(messageArguments);
+ // this should only happen if this class was deserialized because there the default resource bundle is
+ // missing
+ return "No defaultResourceBundle found to resolve, messageKey = " + messageKey + ", messageArguments: "
+ + Arrays.toString(messageArguments);
}
return MessageFormat.format(resourceBundle.getString(messageKey), messageArguments);
}
@@ -117,22 +126,14 @@ public final class DefaultValidationFailure implements ValidationFailure, Serial
@Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
DefaultValidationFailure other = (DefaultValidationFailure) obj;
- if (!location.equals(other.location))
- return false;
- if (!Arrays.equals(messageArguments, other.messageArguments))
- return false;
- if (!messageKey.equals(other.messageKey))
- return false;
- if (severity != other.severity)
- return false;
+ if (!location.equals(other.location)) return false;
+ if (!Arrays.equals(messageArguments, other.messageArguments)) return false;
+ if (!messageKey.equals(other.messageKey)) return false;
+ if (severity != other.severity) return false;
return true;
}
-
}
diff --git a/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationResult.java b/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationResult.java
index 5ace422..08a3b84 100644
--- a/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationResult.java
+++ b/src/main/java/org/apache/sling/validation/spi/support/DefaultValidationResult.java
@@ -39,9 +39,10 @@ import org.osgi.annotation.versioning.ProviderType;
public final class DefaultValidationResult implements ValidationResult, Serializable {
/**
- *
+ *
*/
private static final long serialVersionUID = -3370520716090956033L;
+
private final boolean isValid;
private final @NotNull List<ValidationFailure> failures;
@@ -50,19 +51,21 @@ public final class DefaultValidationResult implements ValidationResult, Serializ
this.failures = Collections.emptyList();
}
- /**
+ /**
* Constructs a result with one failure message. The message is constructed by looking up the given messageKey from a resourceBundle.
* and formatting it using the given messageArguments via {@link MessageFormat#format(String, Object...)}.
* @param validationContext the context from which to take the location, severity and default resource bundle
* @param messageKey the message key used for looking up a value in the resource bundle given in {@link ValidationFailure#getMessage(java.util.ResourceBundle)}
* @param messageArguments optional number of arguments being used in {@link MessageFormat#format(String, Object...)}
*/
- public DefaultValidationResult(@NotNull ValidatorContext validationContext, @NotNull String messageKey, Object... messageArguments) {
+ public DefaultValidationResult(
+ @NotNull ValidatorContext validationContext, @NotNull String messageKey, Object... messageArguments) {
this.isValid = false;
- this.failures = Collections.<ValidationFailure>singletonList(new DefaultValidationFailure(validationContext, messageKey, messageArguments));
+ this.failures = Collections.<ValidationFailure>singletonList(
+ new DefaultValidationFailure(validationContext, messageKey, messageArguments));
}
- /**
+ /**
* Constructs a result with one failure message. The message is constructed by looking up the given messageKey from a resourceBundle.
* and formatting it using the given messageArguments via {@link MessageFormat#format(String, Object...)}.
* @param location the location
@@ -71,9 +74,15 @@ public final class DefaultValidationResult implements ValidationResult, Serializ
* @param messageKey the message key used for looking up a value in the resource bundle given in {@link ValidationFailure#getMessage(java.util.ResourceBundle)}
* @param messageArguments optional number of arguments being used in {@link MessageFormat#format(String, Object...)}
*/
- public DefaultValidationResult(@NotNull String location, int severity, @NotNull ResourceBundle defaultResourceBundle, @NotNull String messageKey, Object... messageArguments) {
+ public DefaultValidationResult(
+ @NotNull String location,
+ int severity,
+ @NotNull ResourceBundle defaultResourceBundle,
+ @NotNull String messageKey,
+ Object... messageArguments) {
this.isValid = false;
- this.failures = Collections.<ValidationFailure>singletonList(new DefaultValidationFailure(location, severity, defaultResourceBundle, messageKey, messageArguments));
+ this.failures = Collections.<ValidationFailure>singletonList(
+ new DefaultValidationFailure(location, severity, defaultResourceBundle, messageKey, messageArguments));
}
public DefaultValidationResult(ValidationFailure... failures) {