Class TypeValidatorHelper
java.lang.Object
de.hybris.platform.configurablebundleservices.constraints.TypeValidatorHelper
- Direct Known Subclasses:
BasicBundleRuleValidator,BasicBundleTemplateValidator
A helper class for validators providing some common functionality of error message constructing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final PatternPattern to check whether validation message is a string resource id. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildErrorMessage(String fieldName, javax.validation.ConstraintValidatorContext context, Object... args) Creates custom error message.protected Localeprotected I18NServiceprotected StringgetLocalizedString(String key, Locale locale) protected ResourceBundleProvider
-
Field Details
-
MESSAGE_PARAMETER_PATTERN
Pattern to check whether validation message is a string resource id.
-
-
Constructor Details
-
TypeValidatorHelper
public TypeValidatorHelper()
-
-
Method Details
-
buildErrorMessage
protected void buildErrorMessage(String fieldName, @Nonnull javax.validation.ConstraintValidatorContext context, Object... args) Creates custom error message.Message template is taken from validation context. In general it is the one specified in
C.messagefield. Strings {string.resource.id} treated as string key of localized string resource. Current add locale is used to resolve value.
To have such string as it is, double the surrounding curly brackets:{{not.a.resource{0}}}will be show as{not.a.resource<value_of_first_arg>}The resulting string is then passed to
MessageFormat.format(String, Object...)along withargsonly if any args provided.Please pay attention to syntax inconsistency between parametrized and non-parametrized lines:
It''s a parametrized line with arg ''{0}''butIt'a a non-parametrized line- Parameters:
fieldName- name of field where the error occurredcontext- validation contextargs- optional message arguments- Throws:
IllegalStateException- if the instance has not been initialized by Spring (seeBasicBundleRuleValidator.initialize(Annotation)as an example of initialization)- See Also:
-
getCurrentLocale
-
getLocalizedString
-
getI18nService
-
getResourceBundleProvider
-