public interface IMessageResolver
Common interface for all objects used for the resolution of externalized (internationalized) messages.
A Template Engine can be set several message resolvers, which will be asked for
resolution of externalized messages in the order established by the getOrder()
method.
Note that message resolution will return null if no message is found, in which case callers will have the
possibility to choose between asking the resolver to create an absent message representation or not.
This is precisely what the useAbsentMessageRepresentation flag does in
ITemplateContext.getMessage(Class, String, Object[], boolean)
.
An absent message representation looks like ??mymessage_gl_ES?? and is useful to quickly determine when a message is lacking from the application's configuration. Note #{...} message expressions will always ask for an absent message representation, whereas methods in the #messages expression object will do it depending on the specific method being called.
Implementations of this interface should be thread-safe.
Modifier and Type | Method and Description |
---|---|
String |
createAbsentMessageRepresentation(ITemplateContext context,
Class<?> origin,
String key,
Object[] messageParameters)
Create a suitable representation of an absent message (a message that could not be resolved).
|
String |
getName()
Returns the name of the message resolver.
|
Integer |
getOrder()
Return the order in which this message resolver will be executed in the
chain when several message resolvers are set for the same Template Engine.
|
String |
resolveMessage(ITemplateContext context,
Class<?> origin,
String key,
Object[] messageParameters)
Resolve the message, returning the requested message (or null if not found).
|
String getName()
Returns the name of the message resolver.
Integer getOrder()
Return the order in which this message resolver will be executed in the chain when several message resolvers are set for the same Template Engine.
String resolveMessage(ITemplateContext context, Class<?> origin, String key, Object[] messageParameters)
Resolve the message, returning the requested message (or null if not found).
Message resolvers should perform resolution of the key + messageParameters pair
based on the context and origin specified. The context will provide
information about the template and the (optional) origin about the point in template execution from
which the message is being requested (usually an IProcessor
or
the MessageExpression
class).
context
- the ITemplateContext
object being used for template processing. Can be null.origin
- the origin of the message request, usually a processor or expression class. Can be null.key
- the message key.messageParameters
- the (optional) message parameters.String createAbsentMessageRepresentation(ITemplateContext context, Class<?> origin, String key, Object[] messageParameters)
Create a suitable representation of an absent message (a message that could not be resolved).
Once the entire chain of configured IMessageResolver
objects is asked for a specific message
and all of them return null, the engine will call this method on the first resolver in the chain.
If the first resolver returns null as a representation, the following resolver will be called, and
so on until a resolver returns a non-null result. The empty String will be used if all resolvers return null.
context
- the ITemplateContext
object being used for template processing. Can be null.origin
- the origin of the message request, usually a processor or expression class. Can be null.key
- the message key.messageParameters
- the (optional) message parameters.Copyright © 2016 The THYMELEAF team. All rights reserved.