From: "Jon Barber" <[EMAIL PROTECTED]>

> We want to store CSS as message resources as we white label our site for
> different partners. The white labelling takes place through our own
> content management system, which we have interfaced struts to via our
> own implementation of the MessageResourcesFactory.
>
> Everything works fine, apart from style sheets. Looking through the
> struts source for 1.2.7 it's because Struts strips any message content
> of single characters before performing an argument replacement using the
> java.text.MessageFormat class.

Don't you mean "single quotes" rather than "single characters"?

> Now this is fine for when you want to do something of the form :
>
> <bean:message key="some.key" arg0="hello"/>
>
> but we don't.
>
> Our CSS has the usual stuff, including sequences such as "{blah; blah
> blah}", and this causes npe's in the text replacement as it's seen as a
> token. If we try and escape it as per the javadocs with '{' blah '}'
> it's stripped by Struts !

It doesn't "strip it out" - it automatically escapes single quotes - so it
turns '{' blah '}'  into ''{'' blah ''}''

> Looking at the code for bean:message (MessageTag.java) reveals that it
> invokes the underlying TagUtils method that accepts an array of Object[]
> as text replacement params even when they are not set ! So:

I think you're mistaken - the issue is the "single quote" escaping in
MessageResources (in the escape() method) - I changed it recently so that
you can configure the MessageResources to "turn off" this behaviour:

   http://issues.apache.org/bugzilla/show_bug.cgi?id=32584#c7

However, in the current release of Struts (1.2.7) you can achieve the same
by overriding the escape() method and in your custom MessageResources
implementation:

     protected String escape(String string) {
        return string;
    }

That way your '{' blah '}' stuff should be left unchanged  and then TagUtils
should not try and do the text replacement.

Niall

> 1. Isn't this a bug ? Surely, of arg0=arg1=arg2=null then the TagUtils
> call that doesn't accept text replacement args & so doesn't strip the
> message should be called ?
> 2. Is there any way, short of writing our own version, to get the
> message bypassing the whole text replacement / stripping stuff ? If not,
> we can't have any occurrences of "{<some text>}" anywhere in our messages
?
> 3. Just out of interest, why is the message source stripped anyway ?

Its to make life easier - if you want to see something like "Jon Barber's
code is...." displayed - then Struts automatically escapes the single quote
so that you don't have to in the message resources.

Niall

> Thanks,
>
> Jon.



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

Reply via email to