On Sat, 2004-08-28 at 11:42, Gary Gregory wrote:
> Hello,
> 
> Since Interpolation is so close in intent to MessageFormat, I seems less
> confusing to Java (as opposed to Perl) people to use a
> MessageFormat-like name. For example MappedMessageFormat is not bad.
> 
> Look at java.text.MessageFormat [1], Interpolation seems to do the same
> kind of thing. For example [1], with MessageFormat, you can:
> 
> Object[] arguments = {
>      new Integer(7),
>      new Date(System.currentTimeMillis()),
>      "a disturbance in the Force"
>  };
> 
>  String result = MessageFormat.format(
>      "At {1,time} on {1,date}, there was {2} on planet
> {0,number,integer}.",
>      arguments);
> 
>  output: At 12:30 PM on Jul 3, 2053, there was a disturbance
>            in the Force on planet 7.
> 
> The new Interpolation version would be:
> 
>    Map arguments = HashMap();
>    valuesMap.put( "time", new Date(System.currentTimeMillis()) );
>    valuesMap.put( "what", "a disturbance in the Force" );
>    //etc
>    String result = Interpolation.interpolate(
>      "At ${time} on ${date}, there was ${what} on planet ${planet}.",
>      arguments);
> 
> So the added value to MessageFormat is a more flexible way to pass in
> arguments (no positional issues). So why call it something oh-so
> completely different from MessageFormat which is so close in
> functionality? ;-)
> 
> The MappedMessageFormat would also have a "format" method, not an
> "interpolate".
> 
> Thanks,
> Gary
> 
> [1] http://java.sun.com/j2se/1.3/docs/api/java/text/MessageFormat.html

Hi,

I just wanted to note that commons-digester has an implementation of 
this sort of thing in o.a.c.digester.substitution.MultiVariableExpander
(in CVS head at the moment, though the recently created RC1 contains
it).

It has the additional feature that multiple maps can be used; eg
 "A ${var} and #{another} and an env{PATH} variable too."

Variables of form ${...} are looked up in an associated map, which
is different from the map for #{...} variables, which is different
again from env{...} variables, etc. The user can define any sequence of
chars as a "marker" string, and then specifies a map associated with
that marker string. When a marker string is found preceding a brace pair
"{varname}" the associated map is used.

I also agree with Gary's suggestion that if a class is created its name
should be some variant of "MessageFormat".

Gary: I would appreciate it if you could add your comments *after* the
paragraph(s) you are replying to ("bottom posting"). This is the
convention on this list, and when involved in a multi-person
conversation is *far* easier to follow than "top posting".

Regards,

Simon




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to