cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Johnston" <coc...@lojjic.net>
Subject Re: Regular Expressions, flowscript and java.lang.Character
Date Mon, 15 Jan 2007 20:49:58 GMT
>> I'm new to flowscript work in Cocoon, but I've gotten to this point from
>> a number of variable manipulations which are just a whole lot easier
>> (theoretically) with regular expressions than in XSLT. The following is
>> a simple variation that illustrates the problem. There are 40 or so
>> other pieces to the whole puzzle.
>>
>> Some of you will be familiar with the error message:
>>     org.mozilla.javascript.EvaluatorException: "file:/D:/Program
>> Files/Apache Software Foundation/Tomcat
>> 5.5/webapps/dist/ROOT/Test/flow/searchTest.js", line 10: Cannot convert
>> /\s*((\S+\s*)*)/ to java.lang.Character
>> It was discussed at length in May 2005, but I would appreciate a simple
>> statement of the conclusions.  I don't see anything like them in play in
>> the schema.js flowscript for the linotype block, which pattern is echoed
>> below.
>>
>> Clues?
>>
>> Walter
>>
>> === the ProcessParameters.js script ============
>> function main() {
>>     /* collect the possible parameters from the search screens*/
>>     var q = cocoon.request.get("q");
>>     /* trim extra spaces and break q into words */
>>     LTrim(q);
>> }
>>
>> // Removes leading whitespaces
>> function LTrim( value ) {
>>     value = value.replace(/\s*((\S+\s*)*)/, "$1");
>
> I believe the problem is this: cocoon.request.get("q") returns a
> java.lang.String, not a JavaScript String.  Then you try to call the
> 'replace' method on it; java.lang.String does have a 'replace' method, but
> it takes Java char primitives as its arguments.  Rhino tries to convert
> your RegExp into a char (or Character) to fit the method signature but
> cannot, hence the error message.
>
> What you need is to convert the java.lang.String into a JavaScript String
> before calling the replace method:
>
>    value = String(value).replace(/\s*((\S+\s*)*)/, "$1");
>
> You might also be able to use the java.util.String 'replaceAll' method

Of course I meant java.*lang*.String here.

> which takes a regular expression as its first argument, but I don't recall
> off the top of my head if it supports $1 substitutions in the second
> argument.
>
>
>>     return value;
>> }
>>
>> === extracts from the Sitemap =================
>>    <map:pipeline>
>>       <map:match pattern="style/*">
>>         <map:generate type="jx" src="style/{1}.xml"/>
>>         <map:serialize/>
>>       </map:match>
>> </map:pipeline>
>>
>> <map:pipeline>
>> <map:match pattern="results">
>>         <map:call function="main"/>
>>         <map:serialize type="xml"/>
>>     </map:match>
>> </map:pipeline>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>



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


Mime
View raw message