cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luca Morandini <lmorand...@ieee.org>
Subject Re: repalce function in Flowscript ?
Date Mon, 08 May 2006 15:37:10 GMT
Simone Gianni wrote:
> Hi Luca,
> 
> Luca Morandini wrote:
> 
>> Hmmm... "replace" is a JavaScript function, not a Java one, hence I
>> cannot understand how the string differences apply :(
>>
>> Anyway, I tried:
>> var jfilters= new Packages.java.lang.String(filters);
>> var re= new Packages.java.lang.String("/a/g");
>> var s= new Packages.java.lang.String("b");
>> jfilters.replace(re, b);
> 
> Nope, in this case you are not calling the javascript replace function,
> which accept the /a/g syntax, but the java.lang.String.replace(char,
> char) method, which only accept two chars.

Got it... a bit confusing though.


> How is the filter variable declared?

It's declared as "var filters", but it's returned by a JavaScript 
function that set its value as: outStream.toString(), where
var outStream= new Packages.java.io.ByteArrayOutputStream()
...hence, it is a Java String in the end.


> You could try one of the following :
> 
> var jsfilters = new String(filter);
> var jsfilters = filters + '';
> 
> and then :
> 
> jsfilters.replace(/a/g,'b');

Ok, I did the following:
var jsfilters= new String(filters);
cocoon.log.debug("XXX updateMap: filters pre: " + jsfilters); 	
jsfilters.replace(/i/g, "x");
cocoon.log.debug("XXX updateMap: filters post: " + jsfilters); 	

...and it works :)

Thanks for Simone and Alessandro for their help in sorting this out.

Regards,

--------------------
    Luca Morandini
www.lucamorandini.it
--------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message