You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pierre Métras <ge...@sympatico.ca> on 2000/11/01 22:54:04 UTC

Can't obtain quote characters from struts message file

Hi,

I posted this problem one month ago but I've only found a strange solution.
Are other having such a behavior?

My tomcat+struts web application reads message tag strings from a property
file. In the default message file, that contains French sentences for the
moment, when the messages contains quotes ( ' ), these quotes disapear on
the HTML page. I traced the problem to the function reading the messages
from the property file.

For instance, "l'émission" is read as "lémission". I have tried to escape
the quote as in "l\'émission", according to the Properties class
documentation. I even run native2ascii on the property file and all
accentuated characters have been translated to Unicode escape, but the
problem still persist.
I created a test property file and stored it to disk, and the property are
really stored as the would do:
    test=l'0u00E9mission
without any escape for the quote. When I read the property file from the
test program, I obtain the expected result. But that's not the behavior I
have in the web application...

As a last test, I tried to double the quote as in "l''émission" (that's two
quotes, and not a double-quote). And then it worked! I have "l'émission" on
the displayed HTML page.

Can someone explain this?


Pierre Métras







Re: Can't obtain quote characters from struts message file

Posted by Pierre Metras <ge...@sympatico.ca>.
Thanks Michael,

The behavior of ' in Struts messages resources was turning me crazy.
Particularly when a resource string was used to localize javascript code,
where I use single quotes as string separator and frequently had syntax
errors due to quotes disappearing from the retrieved string.

Now, I have found in java.text.MessageFormat that the quote character is
used as escape char in format string. And Struts processes the strings from
the resource for argument substitution... Thus this strange and undocumented
(in Struts) behavior.

Perhaps a quote from the JDK doc could be added in the <struts:message>
documentation:
    In strings, single quotes can be used to quote the "{" (curly brace) if
necessary. A real single quote is represented by ''. Inside a
messageFormatElement, quotes are not removed


Thanks again.

Pierre Metras


----- Original Message -----
From: "Michael Westbay" <we...@seaple.icc.ne.jp>
To: <st...@jakarta.apache.org>
Sent: Saturday, November 04, 2000 10:38 AM
Subject: Re: Can't obtain quote characters from struts message file


> M騁ras-san wrote:
>
> > I posted this problem one month ago but I've only found a strange
solution.
> > Are other having such a behavior?
> >
> > My tomcat+struts web application reads message tag strings from a
property
> > file. In the default message file, that contains French sentences for
the
> > moment, when the messages contains quotes ( ' ), these quotes disapear
on
> > the HTML page. I traced the problem to the function reading the messages
> > from the property file.
> > [...]
> > As a last test, I tried to double the quote as in "l''蜊ission" (that's
two
> > quotes, and not a double-quote). And then it worked! I have "l'蜊ission"
on
> > the displayed HTML page.
>
> Are you putting this string through a java.text.MessageFormat.format(...)
> function?  I've had this problem with format()ed strings read from
> ResourceBundles in the past.  It's the MessageFormat that causes the
single
> quotes to require the two single quotes to escape.  When I don't put the
> string through the MessageFormat.format() function, doubling single quotes
> aren't required.
>
> --
> Michael Westbay
> Work: Beacon-IT http://www.beacon-it.co.jp/
> Home:           http://www.seaple.icc.ne.jp/~westbay
> Commentary:     http://www.japanesebaseball.com/
>


Re: Can't obtain quote characters from struts message file

Posted by Michael Westbay <we...@seaple.icc.ne.jp>.
M騁ras-san wrote:

> I posted this problem one month ago but I've only found a strange solution.
> Are other having such a behavior?
> 
> My tomcat+struts web application reads message tag strings from a property
> file. In the default message file, that contains French sentences for the
> moment, when the messages contains quotes ( ' ), these quotes disapear on
> the HTML page. I traced the problem to the function reading the messages
> from the property file.
> [...]
> As a last test, I tried to double the quote as in "l''蜊ission" (that's two
> quotes, and not a double-quote). And then it worked! I have "l'蜊ission" on
> the displayed HTML page.

Are you putting this string through a java.text.MessageFormat.format(...) 
function?  I've had this problem with format()ed strings read from 
ResourceBundles in the past.  It's the MessageFormat that causes the single
quotes to require the two single quotes to escape.  When I don't put the
string through the MessageFormat.format() function, doubling single quotes
aren't required.

--
Michael Westbay
Work: Beacon-IT http://www.beacon-it.co.jp/
Home:           http://www.seaple.icc.ne.jp/~westbay
Commentary:     http://www.japanesebaseball.com/