MessageFormat.format() not invoked in ResourceTool.render() if there are no
arguments
-------------------------------------------------------------------------------------
Key: VELTOOLS-104
URL: https://issues.apache.org/jira/browse/VELTOOLS-104
Project: Velocity Tools
Issue Type: Bug
Components: GenericTools
Affects Versions: 1.4, 2.0, 2.x
Reporter: Rod
render() currently looks like this:
public String render(Object resource, Object[] args)
{
String value = String.valueOf(resource);
if (args == null)
{
return value;
}
return MessageFormat.format(value, args);
}
Unfortunately, if you're using MessageFormat-ready messages then you should be
format()ting even strings with no arguments, even if this seems like an
inefficiency.
We use many strings that are used on their own, or as part of other messages,
sometimes they have arguments and sometimes they don't. This creates a sticky
situation if you have to use MessageFormat escaping for some messages and not
others. For example:
message1=ResourceTool's problem
message2=$(message1) is {0}
where "$(message1)" is a substitution for message1 (which our ResourceBundle
does for us). ResourceTool renders the first message fine but the second
message with an argument doesn't render properly due to the unescaped ' passed
to MessageFormat. Even without the special message substitution render() causes
problems because the escaping rules are different depending on the message
context.
The messages should actually be:
message1=ResourceTool''s problem
message2=$(message1) is {0}
to be consistent with MessageFormat's rules across all messages. Unfortunately
ResourceTool can't handle this because it doesn't pass a no-argument resource
to MessageFormat.
I'm using a subclass of ResourceTool that doesn't have the shortcut:
@Override
public String render(Object resource, Object[] args) {
return MessageFormat.format(String.valueOf(resource), args);
}
So all my messages have the same escaping rules.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]