Class TypeValidatorHelper
- java.lang.Object
-
- de.hybris.platform.configurablebundleservices.constraints.TypeValidatorHelper
-
- Direct Known Subclasses:
BasicBundleRuleValidator,BasicBundleTemplateValidator
public class TypeValidatorHelper extends java.lang.ObjectA helper class for validators providing some common functionality of error message constructing.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.regex.PatternMESSAGE_PARAMETER_PATTERNPattern to check whether validation message is a string resource id.
-
Constructor Summary
Constructors Constructor Description TypeValidatorHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildErrorMessage(java.lang.String fieldName, javax.validation.ConstraintValidatorContext context, java.lang.Object... args)Creates custom error message.protected java.util.LocalegetCurrentLocale()protected I18NServicegetI18nService()protected java.lang.StringgetLocalizedString(java.lang.String key, java.util.Locale locale)protected ResourceBundleProvidergetResourceBundleProvider()
-
-
-
Method Detail
-
buildErrorMessage
protected void buildErrorMessage(java.lang.String fieldName, @Nonnull javax.validation.ConstraintValidatorContext context, java.lang.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:
java.lang.IllegalStateException- if the instance has not been initialized by Spring (seeBasicBundleRuleValidator.initialize(Annotation)as an example of initialization)- See Also:
BundleTemplateDependsOnAncestorValidator,MessageFormat.format(String, Object...),I18NService
-
getCurrentLocale
protected java.util.Locale getCurrentLocale()
-
getLocalizedString
protected java.lang.String getLocalizedString(java.lang.String key, java.util.Locale locale)
-
getI18nService
protected I18NService getI18nService()
-
getResourceBundleProvider
protected ResourceBundleProvider getResourceBundleProvider()
-
-