Interface IMessageResolver
- All Known Implementing Classes:
AbstractMessageResolver
,StandardMessageResolver
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.
- Since:
- 3.0.0
- Author:
- Daniel Fernández
-
Method Summary
Modifier and TypeMethodDescriptioncreateAbsentMessageRepresentation
(ITemplateContext context, Class<?> origin, String key, Object[] messageParameters) Create a suitable representation of an absent message (a message that could not be resolved).getName()
Returns the name of the message resolver.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.resolveMessage
(ITemplateContext context, Class<?> origin, String key, Object[] messageParameters) Resolve the message, returning the requested message (ornull
if not found).
-
Method Details
-
getName
String getName()Returns the name of the message resolver.
- Returns:
- the name of the message resolver
-
getOrder
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.
- Returns:
- the order of this resolver in the chain.
-
resolveMessage
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 thecontext
andorigin
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 anIProcessor
or theMessageExpression
class).- Parameters:
context
- theITemplateContext
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.- Returns:
- the resolved message, or
null
if the message could not be resolved.
-
createAbsentMessageRepresentation
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 returnnull
, the engine will call this method on the first resolver in the chain. If the first resolver returnsnull
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.- Parameters:
context
- theITemplateContext
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.- Returns:
- the absent message representation, of
null
if the resolver cannot create such representation.
-