Top Description Fields Constructors Methods
org.hibernate.validator.messageinterpolation

public abstract Class AbstractMessageInterpolator

extends Object
implements MessageInterpolator
Class Inheritance
All Implemented Interfaces
jakarta.validation.MessageInterpolator
Known Direct Subclasses
org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator, org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator
Static Imports
org.hibernate.validator.internal.util.ConcurrentReferenceHashMap.ReferenceType.SOFT, org.hibernate.validator.internal.util.logging.Messages.MESSAGES

Resource bundle backed message interpolator.
Authors
Emmanuel Bernard, Hardy Ferentschik, Gunnar Morling, Adam Stawicki, Marko Bekhta, Guillaume Smet
Since
5.2

Field Summary

Modifier and TypeField and Description
private final boolean
cachingEnabled

Flag indicating whether this interpolator should cache some of the interpolation steps.

public static final String
CONTRIBUTOR_VALIDATION_MESSAGES

Default name of the message bundle defined by a constraint definition contributor.

private final ResourceBundleLocator
contributorResourceBundleLocator

Loads contributed resource bundles.

private static final int
DEFAULT_CONCURRENCY_LEVEL

The default concurrency level for this cache.

private static final int
DEFAULT_INITIAL_CAPACITY

The default initial capacity for this cache.

private static final float
DEFAULT_LOAD_FACTOR

The default load factor for this cache.

public static final String
DEFAULT_VALIDATION_MESSAGES

The name of the default message bundle.

private final ResourceBundleLocator
defaultResourceBundleLocator

Loads built-in resource bundles.

private static final Pattern
private static final Pattern
private final LocaleResolver
localeResolver

The locale resolver.

private final LocaleResolverContext
localeResolverContext

The execution context of the locale resolver.

private static final Log
private final ConcurrentReferenceHashMap<LocalizedMessage, String>
resolvedMessages

Step 1-3 of message interpolation can be cached.

private static final Pattern
private static final Pattern
private final ConcurrentReferenceHashMap<String, List<Token>>
tokenizedELMessages

Step 5 of message interpolation replaces EL expressions.

private final ConcurrentReferenceHashMap<String, List<Token>>
tokenizedParameterMessages

Step 4 of message interpolation replaces message parameters.

public static final String
USER_VALIDATION_MESSAGES

The name of the user-provided message bundle as defined in the specification.

private final ResourceBundleLocator
userResourceBundleLocator

Loads user-specified resource bundles.

Constructor Summary

AccessConstructor and Description
public
AbstractMessageInterpolator()

MessageInterpolator using the default resource bundle locators.

public
AbstractMessageInterpolator(ResourceBundleLocator
ResourceBundleLocator used to load user provided resource bundle
userResourceBundleLocator
)

MessageInterpolator taking a resource bundle locator.

public
AbstractMessageInterpolator(ResourceBundleLocator
ResourceBundleLocator used to load user provided resource bundle
userResourceBundleLocator
,
ResourceBundleLocator
ResourceBundleLocator used to load resource bundle of constraint contributor
contributorResourceBundleLocator
)

MessageInterpolator taking two resource bundle locators.

public
AbstractMessageInterpolator(ResourceBundleLocator
ResourceBundleLocator used to load user provided resource bundle
userResourceBundleLocator
,
ResourceBundleLocator
ResourceBundleLocator used to load resource bundle of constraint contributor
contributorResourceBundleLocator
,
boolean
Whether resolved messages should be cached or not.
cacheMessages
)

MessageInterpolator taking two resource bundle locators.

public
AbstractMessageInterpolator(Set<Locale>
the set of locales to initialize at bootstrap
locales
,
Locale
the default locale
defaultLocale
,
LocaleResolver
the locale resolver
localeResolver
,
boolean
if the resource bundled should be initialized at initialization time, this is useful in the case of a PredefinedScopeValidatorFactoryImpl
preloadResourceBundles
)

MessageInterpolator using the default resource bundle locators.

public
AbstractMessageInterpolator(ResourceBundleLocator
ResourceBundleLocator used to load user provided resource bundle
userResourceBundleLocator
,
Set<Locale>
the set of locales to initialize at bootstrap
locales
,
Locale
the default locale
defaultLocale
,
LocaleResolver
the locale resolver
localeResolver
,
boolean
if the resource bundled should be initialized at initialization time, this is useful in the case of a PredefinedScopeValidatorFactoryImpl
preloadResourceBundles
)

MessageInterpolator taking a resource bundle locator.

public
AbstractMessageInterpolator(ResourceBundleLocator
ResourceBundleLocator used to load user provided resource bundle
userResourceBundleLocator
,
ResourceBundleLocator
ResourceBundleLocator used to load resource bundle of constraint contributor
contributorResourceBundleLocator
,
Set<Locale>
the set of locales to initialize at bootstrap
localesToInitialize
,
Locale
the default locale
defaultLocale
,
LocaleResolver
the locale resolver
localeResolver
,
boolean
if the resource bundled should be initialized at initialization time, this is useful in the case of a PredefinedScopeValidatorFactoryImpl
preloadResourceBundles
)

MessageInterpolator taking two resource bundle locators.

public
AbstractMessageInterpolator(ResourceBundleLocator
ResourceBundleLocator used to load user provided resource bundle
userResourceBundleLocator
,
ResourceBundleLocator
ResourceBundleLocator used to load resource bundle of constraint contributor
contributorResourceBundleLocator
,
Set<Locale>
the set of locales to initialize at bootstrap
locales
,
Locale
the default locale
defaultLocale
,
LocaleResolver
the locale resolver
localeResolver
,
boolean
if the resource bundled should be initialized at initialization time, this is useful in the case of a PredefinedScopeValidatorFactoryImpl
preloadResourceBundles
,
boolean
whether resolved messages should be cached or not
cacheMessages
)

MessageInterpolator taking two resource bundle locators.

Method Summary

Modifier and TypeMethod and Description
private Set<Locale>
getAllLocales(Set<Locale> localesToInitialize, Locale defaultLocale)

private List<Token>
private boolean
hasReplacementTakenPlace(String origMessage, String newMessage)

public String
interpolate(String
the message to interpolate
message
,
MessageInterpolator.Context
contextual information related to the interpolation
context
)

Implements jakarta.validation.MessageInterpolator.interpolate.

Interpolates the message template based on the constraint validation context.
public String
interpolate(String
the message to interpolate
message
,
MessageInterpolator.Context
contextual information related to the interpolation
context
,
Locale
the locale targeted for the message
locale
)

Implements jakarta.validation.MessageInterpolator.interpolate.

Interpolates the message template based on the constraint validation context.
protected abstract String
private String
interpolateBundleMessage(String message, ResourceBundle bundle, Locale locale, boolean recursive)

private String
private String

Returns:

the interpolated message.
interpolateMessage
(String
the message to interpolate
message
,
MessageInterpolator.Context
the context for this interpolation
context
,
Locale
the Locale to use for the resource bundle.
locale
)

Runs the message interpolation according to algorithm specified in the Bean Validation specification.

private String
private String
replaceEscapedLiterals(String resolvedMessage)

private String
resolveMessage(String message, Locale locale)

private String
resolveParameter(String parameterName, ResourceBundle bundle, Locale locale, boolean recursive)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachingEnabledback to summary
private final boolean cachingEnabled

Flag indicating whether this interpolator should cache some of the interpolation steps.

CONTRIBUTOR_VALIDATION_MESSAGESback to summary
public static final String CONTRIBUTOR_VALIDATION_MESSAGES

Default name of the message bundle defined by a constraint definition contributor.

Since
5.2
contributorResourceBundleLocatorback to summary
private final ResourceBundleLocator contributorResourceBundleLocator

Loads contributed resource bundles.

DEFAULT_CONCURRENCY_LEVELback to summary
private static final int DEFAULT_CONCURRENCY_LEVEL

The default concurrency level for this cache.

DEFAULT_INITIAL_CAPACITYback to summary
private static final int DEFAULT_INITIAL_CAPACITY

The default initial capacity for this cache.

DEFAULT_LOAD_FACTORback to summary
private static final float DEFAULT_LOAD_FACTOR

The default load factor for this cache.

DEFAULT_VALIDATION_MESSAGESback to summary
public static final String DEFAULT_VALIDATION_MESSAGES

The name of the default message bundle.

defaultResourceBundleLocatorback to summary
private final ResourceBundleLocator defaultResourceBundleLocator

Loads built-in resource bundles.

DOLLARback to summary
private static final Pattern DOLLAR
LEFT_BRACEback to summary
private static final Pattern LEFT_BRACE
localeResolverback to summary
private final LocaleResolver localeResolver

The locale resolver.

localeResolverContextback to summary
private final LocaleResolverContext localeResolverContext

The execution context of the locale resolver.

LOGback to summary
private static final Log LOG
resolvedMessagesback to summary
private final ConcurrentReferenceHashMap<LocalizedMessage, String> resolvedMessages

Step 1-3 of message interpolation can be cached. We do this in this map.

RIGHT_BRACEback to summary
private static final Pattern RIGHT_BRACE
SLASHback to summary
private static final Pattern SLASH
tokenizedELMessagesback to summary
private final ConcurrentReferenceHashMap<String, List<Token>> tokenizedELMessages

Step 5 of message interpolation replaces EL expressions. The token list for EL expressions is cached in this map.

tokenizedParameterMessagesback to summary
private final ConcurrentReferenceHashMap<String, List<Token>> tokenizedParameterMessages

Step 4 of message interpolation replaces message parameters. The token list for message parameters is cached in this map.

USER_VALIDATION_MESSAGESback to summary
public static final String USER_VALIDATION_MESSAGES

The name of the user-provided message bundle as defined in the specification.

userResourceBundleLocatorback to summary
private final ResourceBundleLocator userResourceBundleLocator

Loads user-specified resource bundles.

Constructor Detail

AbstractMessageInterpolatorback to summary
public AbstractMessageInterpolator()

MessageInterpolator using the default resource bundle locators.

AbstractMessageInterpolatorback to summary
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator)

MessageInterpolator taking a resource bundle locator.

Parameters
userResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load user provided resource bundle

AbstractMessageInterpolatorback to summary
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator)

MessageInterpolator taking two resource bundle locators.

Parameters
userResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load user provided resource bundle

contributorResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load resource bundle of constraint contributor

Since
5.2
AbstractMessageInterpolatorback to summary
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, boolean cacheMessages)

MessageInterpolator taking two resource bundle locators.

Parameters
userResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load user provided resource bundle

contributorResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load resource bundle of constraint contributor

cacheMessages:boolean

Whether resolved messages should be cached or not.

Since
5.2
AbstractMessageInterpolatorback to summary
public AbstractMessageInterpolator(Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)

MessageInterpolator using the default resource bundle locators.

Parameters
locales:Set<Locale>

the set of locales to initialize at bootstrap

defaultLocale:Locale

the default locale

localeResolver:LocaleResolver

the locale resolver

preloadResourceBundles:boolean

if the resource bundled should be initialized at initialization time, this is useful in the case of a PredefinedScopeValidatorFactoryImpl

Annotations
@Incubating
Since
6.1.1
AbstractMessageInterpolatorback to summary
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)

MessageInterpolator taking a resource bundle locator.

Parameters
userResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load user provided resource bundle

locales:Set<Locale>

the set of locales to initialize at bootstrap

defaultLocale:Locale

the default locale

localeResolver:LocaleResolver

the locale resolver

preloadResourceBundles:boolean

if the resource bundled should be initialized at initialization time, this is useful in the case of a PredefinedScopeValidatorFactoryImpl

Annotations
@Incubating
Since
6.1.1
AbstractMessageInterpolatorback to summary
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, Set<Locale> localesToInitialize, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles)

MessageInterpolator taking two resource bundle locators.

Parameters
userResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load user provided resource bundle

contributorResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load resource bundle of constraint contributor

localesToInitialize:Set<Locale>

the set of locales to initialize at bootstrap

defaultLocale:Locale

the default locale

localeResolver:LocaleResolver

the locale resolver

preloadResourceBundles:boolean

if the resource bundled should be initialized at initialization time, this is useful in the case of a PredefinedScopeValidatorFactoryImpl

Annotations
@Incubating
Since
6.1.1
AbstractMessageInterpolatorback to summary
public AbstractMessageInterpolator(ResourceBundleLocator userResourceBundleLocator, ResourceBundleLocator contributorResourceBundleLocator, Set<Locale> locales, Locale defaultLocale, LocaleResolver localeResolver, boolean preloadResourceBundles, boolean cacheMessages)

MessageInterpolator taking two resource bundle locators.

Parameters
userResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load user provided resource bundle

contributorResourceBundleLocator:ResourceBundleLocator

ResourceBundleLocator used to load resource bundle of constraint contributor

locales:Set<Locale>

the set of locales to initialize at bootstrap

defaultLocale:Locale

the default locale

localeResolver:LocaleResolver

the locale resolver

preloadResourceBundles:boolean

if the resource bundled should be initialized at initialization time, this is useful in the case of a PredefinedScopeValidatorFactoryImpl

cacheMessages:boolean

whether resolved messages should be cached or not

Annotations
@Incubating
Since
6.1.1

Method Detail

getAllLocalesback to summary
private Set<Locale> getAllLocales(Set<Locale> localesToInitialize, Locale defaultLocale)
getParameterTokensback to summary
private List<Token> getParameterTokens(String resolvedMessage, ConcurrentReferenceHashMap<String, List<Token>> cache, InterpolationTermType termType)
hasReplacementTakenPlaceback to summary
private boolean hasReplacementTakenPlace(String origMessage, String newMessage)
interpolateback to summary
public String interpolate(String message, MessageInterpolator.Context context)

Implements jakarta.validation.MessageInterpolator.interpolate.

Doc from jakarta.validation.MessageInterpolator.interpolate.

Interpolates the message template based on the constraint validation context.

The locale is defaulted according to the MessageInterpolator implementation. See the implementation documentation for more detail.

Parameters
message:String

the message to interpolate

context:MessageInterpolator.Context

contextual information related to the interpolation

Returns:String

interpolated error message

Annotations
@Override
interpolateback to summary
public String interpolate(String message, MessageInterpolator.Context context, Locale locale)

Implements jakarta.validation.MessageInterpolator.interpolate.

Doc from jakarta.validation.MessageInterpolator.interpolate.

Interpolates the message template based on the constraint validation context. The Locale used is provided as a parameter.

Parameters
message:String

the message to interpolate

context:MessageInterpolator.Context

contextual information related to the interpolation

locale:Locale

the locale targeted for the message

Returns:String

interpolated error message

Annotations
@Override
interpolateback to summary
protected abstract String interpolate(MessageInterpolator.Context context, Locale locale, String term)
interpolateBundleMessageback to summary
private String interpolateBundleMessage(String message, ResourceBundle bundle, Locale locale, boolean recursive) throws MessageDescriptorFormatException
interpolateExpressionback to summary
private String interpolateExpression(TokenIterator tokenIterator, MessageInterpolator.Context context, Locale locale) throws MessageDescriptorFormatException
interpolateMessageback to summary
private String interpolateMessage(String message, MessageInterpolator.Context context, Locale locale) throws MessageDescriptorFormatException

Runs the message interpolation according to algorithm specified in the Bean Validation specification.

Note:

Look-ups in user bundles is recursive whereas look-ups in default bundle are not!

Parameters
message:String

the message to interpolate

context:MessageInterpolator.Context

the context for this interpolation

locale:Locale

the Locale to use for the resource bundle.

Returns:String

the interpolated message.

removeCurlyBracesback to summary
private String removeCurlyBraces(String parameter)
replaceEscapedLiteralsback to summary
private String replaceEscapedLiterals(String resolvedMessage)
resolveMessageback to summary
private String resolveMessage(String message, Locale locale)
resolveParameterback to summary
private String resolveParameter(String parameterName, ResourceBundle bundle, Locale locale, boolean recursive) throws MessageDescriptorFormatException