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
ConstructorsConstructorDescriptionDefaultValidationFailure(@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 StringReturns the relative location of the property/resource/value which triggered this validation failure.@NotNull StringgetMessage(ResourceBundle resourceBundle) intinthashCode()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 benullwhich leads to using the validator's default severity)defaultResourceBundle- the default resourceBundle which is used to resolve themessageKeyingetMessage(ResourceBundle)ifnullis 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:
getMessagein interfaceValidationFailure- Parameters:
resourceBundle- ResourceBundle in which to look up the according message (used for i18n), ifnullis given, the default resource bundle is used.- Returns:
- the failure message
-
getLocation
Description copied from interface:ValidationFailureReturns 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:
getLocationin 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:
getSeverityin 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
-