Class DefaultValidationFailure
java.lang.Object
org.apache.sling.validation.spi.support.DefaultValidationFailure
- All Implemented Interfaces:
Serializable
,ValidationFailure
@ProviderType
public final class DefaultValidationFailure
extends Object
implements ValidationFailure, Serializable
Wraps a message key (being looked up in a
ResourceBundle
), messageArguments (being used with MessageFormat.format(String, Object...)
and the location where the validation failure occurred.- See Also:
-
Constructor Summary
ConstructorDescriptionDefaultValidationFailure
(@NotNull String location, int severity, @NotNull ResourceBundle defaultResourceBundle, @NotNull String messageKey, Object... messageArguments) Constructor of a validation failure.DefaultValidationFailure
(@NotNull ValidatorContext validationContext, @NotNull String messageKey, Object... messageArguments) Constructor of a validation failure. -
Method Summary
Modifier and TypeMethodDescriptionboolean
@NotNull String
Returns the relative location of the property/resource/value which triggered this validation failure.@NotNull String
getMessage
(ResourceBundle resourceBundle) int
int
hashCode()
toString()
-
Constructor Details
-
DefaultValidationFailure
public DefaultValidationFailure(@NotNull @NotNull ValidatorContext validationContext, @NotNull @NotNull String messageKey, Object... messageArguments) Constructor of a validation failure.- Parameters:
validationContext
- the context from which to extract location, severity and default resource bundlemessageKey
- the key to look up in the resource bundlemessageArguments
- the arguments to be used with the looked up value from the resource bundle (given ingetMessage(ResourceBundle)
-
DefaultValidationFailure
public DefaultValidationFailure(@NotNull @NotNull String location, int severity, @NotNull @NotNull ResourceBundle defaultResourceBundle, @NotNull @NotNull String messageKey, Object... messageArguments) Constructor of a validation failure.- Parameters:
location
- the location where the validation error occurredseverity
- the severity of this failure (may benull
which leads to using the validator's default severity)defaultResourceBundle
- the default resourceBundle which is used to resolve themessageKey
ingetMessage(ResourceBundle)
ifnull
is provided as parameter.messageKey
- the key to look up in the resource bundlemessageArguments
- the arguments to be used with the looked up value from the resource bundle (given ingetMessage(ResourceBundle)
-
-
Method Details
-
getMessage
- Specified by:
getMessage
in interfaceValidationFailure
- Parameters:
resourceBundle
- ResourceBundle in which to look up the according message (used for i18n), ifnull
is given, the default resource bundle is used.- Returns:
- the failure message
-
getLocation
Description copied from interface:ValidationFailure
Returns the relative location of the property/resource/value which triggered this validation failure. The location- is relative to the resource given in the first parameter in case it was returned by
ValidationService.validate(org.apache.sling.api.resource.Resource, org.apache.sling.validation.model.ValidationModel)
orValidationService.validateResourceRecursively(org.apache.sling.api.resource.Resource, boolean, java.util.function.Predicate, boolean)
or - contains just the value name in case it was returned by
ValidationService.validate(org.apache.sling.api.resource.ValueMap, org.apache.sling.validation.model.ValidationModel)
- Specified by:
getLocation
in interfaceValidationFailure
- Returns:
- the location (usually the validated resource's property path).
- is relative to the resource given in the first parameter in case it was returned by
-
getSeverity
public int getSeverity()- Specified by:
getSeverity
in interfaceValidationFailure
- Returns:
- the severity of this validation failure. If no explicit severity was set either in the validation model or in the validator, this returns
0
.
-
toString
-
hashCode
public int hashCode() -
equals
-