Class AbstractMessageInterpolator
- java.lang.Object
-
- org.hibernate.validator.messageinterpolation.AbstractMessageInterpolator
-
- All Implemented Interfaces:
MessageInterpolator
- Direct Known Subclasses:
ParameterMessageInterpolator,ResourceBundleMessageInterpolator
public abstract class AbstractMessageInterpolator extends Object implements MessageInterpolator
Resource bundle backed message interpolator.- Since:
- 5.2
- Author:
- Emmanuel Bernard, Hardy Ferentschik, Gunnar Morling, Adam Stawicki, Marko Bekhta, Guillaume Smet
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jakarta.validation.MessageInterpolator
MessageInterpolator.Context
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONTRIBUTOR_VALIDATION_MESSAGESDefault name of the message bundle defined by a constraint definition contributor.static StringDEFAULT_VALIDATION_MESSAGESThe name of the default message bundle.static StringUSER_VALIDATION_MESSAGESThe name of the user-provided message bundle as defined in the specification.
-
Constructor Summary
Constructors Constructor Description AbstractMessageInterpolator()MessageInterpolatorusing the default resource bundle locators.AbstractMessageInterpolator(Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)MessageInterpolatorusing the default resource bundle locators.AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator)MessageInterpolatortaking a resource bundle locator.AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)MessageInterpolatortaking a resource bundle locator.AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator)MessageInterpolatortaking two resource bundle locators.AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, boolean cacheMessages)MessageInterpolatortaking two resource bundle locators.AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, Set<Locale> localesToInitialize, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)MessageInterpolatortaking two resource bundle locators.AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles, boolean cacheMessages)MessageInterpolatortaking two resource bundle locators.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Stringinterpolate(MessageInterpolator.Context context, Locale locale, String term)Stringinterpolate(String message, MessageInterpolator.Context context)Interpolates the message template based on the constraint validation context.Stringinterpolate(String message, MessageInterpolator.Context context, Locale locale)Interpolates the message template based on the constraint validation context.
-
-
-
Field Detail
-
DEFAULT_VALIDATION_MESSAGES
public static final String DEFAULT_VALIDATION_MESSAGES
The name of the default message bundle.- See Also:
- Constant Field Values
-
USER_VALIDATION_MESSAGES
public static final String USER_VALIDATION_MESSAGES
The name of the user-provided message bundle as defined in the specification.- See Also:
- Constant Field Values
-
CONTRIBUTOR_VALIDATION_MESSAGES
public static final String CONTRIBUTOR_VALIDATION_MESSAGES
Default name of the message bundle defined by a constraint definition contributor.- Since:
- 5.2
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractMessageInterpolator
public AbstractMessageInterpolator()
MessageInterpolatorusing the default resource bundle locators.
-
AbstractMessageInterpolator
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator)
MessageInterpolatortaking a resource bundle locator.- Parameters:
userResourceBundleLocator-ResourceBundleLocatorused to load user provided resource bundle
-
AbstractMessageInterpolator
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator)
MessageInterpolatortaking two resource bundle locators.- Parameters:
userResourceBundleLocator-ResourceBundleLocatorused to load user provided resource bundlecontributorResourceBundleLocator-ResourceBundleLocatorused to load resource bundle of constraint contributor- Since:
- 5.2
-
AbstractMessageInterpolator
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, boolean cacheMessages)
MessageInterpolatortaking two resource bundle locators.- Parameters:
userResourceBundleLocator-ResourceBundleLocatorused to load user provided resource bundlecontributorResourceBundleLocator-ResourceBundleLocatorused to load resource bundle of constraint contributorcacheMessages- Whether resolved messages should be cached or not.- Since:
- 5.2
-
AbstractMessageInterpolator
@Incubating public AbstractMessageInterpolator(Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)
MessageInterpolatorusing the default resource bundle locators.- Parameters:
locales- the set of locales to initialize at bootstrapdefaultLocale- the default localelocaleResolver- the locale resolverpreloadResourceBundles- if the resource bundled should be initialized at initialization time, this is useful in the case of aPredefinedScopeValidatorFactoryImpl- Since:
- 6.1.1
-
AbstractMessageInterpolator
@Incubating public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)
MessageInterpolatortaking a resource bundle locator.- Parameters:
userResourceBundleLocator-ResourceBundleLocatorused to load user provided resource bundlelocales- the set of locales to initialize at bootstrapdefaultLocale- the default localelocaleResolver- the locale resolverpreloadResourceBundles- if the resource bundled should be initialized at initialization time, this is useful in the case of aPredefinedScopeValidatorFactoryImpl- Since:
- 6.1.1
-
AbstractMessageInterpolator
@Incubating public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, Set<Locale> localesToInitialize, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)
MessageInterpolatortaking two resource bundle locators.- Parameters:
userResourceBundleLocator-ResourceBundleLocatorused to load user provided resource bundlecontributorResourceBundleLocator-ResourceBundleLocatorused to load resource bundle of constraint contributorlocalesToInitialize- the set of locales to initialize at bootstrapdefaultLocale- the default localelocaleResolver- the locale resolverpreloadResourceBundles- if the resource bundled should be initialized at initialization time, this is useful in the case of aPredefinedScopeValidatorFactoryImpl- Since:
- 6.1.1
-
AbstractMessageInterpolator
@Incubating public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles, boolean cacheMessages)
MessageInterpolatortaking two resource bundle locators.- Parameters:
userResourceBundleLocator-ResourceBundleLocatorused to load user provided resource bundlecontributorResourceBundleLocator-ResourceBundleLocatorused to load resource bundle of constraint contributorlocales- the set of locales to initialize at bootstrapdefaultLocale- the default localecacheMessages- whether resolved messages should be cached or notlocaleResolver- the locale resolverpreloadResourceBundles- if the resource bundled should be initialized at initialization time, this is useful in the case of aPredefinedScopeValidatorFactoryImpl- Since:
- 6.1.1
-
-
Method Detail
-
interpolate
public String interpolate(String message, MessageInterpolator.Context context)
Description copied from interface:MessageInterpolatorInterpolates the message template based on the constraint validation context.The locale is defaulted according to the
MessageInterpolatorimplementation. See the implementation documentation for more detail.- Specified by:
interpolatein interfaceMessageInterpolator- Parameters:
message- the message to interpolatecontext- contextual information related to the interpolation- Returns:
- interpolated error message
-
interpolate
public String interpolate(String message, MessageInterpolator.Context context, Locale locale)
Description copied from interface:MessageInterpolatorInterpolates the message template based on the constraint validation context. TheLocaleused is provided as a parameter.- Specified by:
interpolatein interfaceMessageInterpolator- Parameters:
message- the message to interpolatecontext- contextual information related to the interpolationlocale- the locale targeted for the message- Returns:
- interpolated error message
-
interpolate
protected abstract String interpolate(MessageInterpolator.Context context, Locale locale, String term)
-
-