Return-Path: Delivered-To: apmail-cocoon-users-archive@www.apache.org Received: (qmail 13060 invoked from network); 15 Jan 2007 20:49:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Jan 2007 20:49:59 -0000 Received: (qmail 36172 invoked by uid 500); 15 Jan 2007 20:50:01 -0000 Delivered-To: apmail-cocoon-users-archive@cocoon.apache.org Received: (qmail 36105 invoked by uid 500); 15 Jan 2007 20:50:01 -0000 Mailing-List: contact users-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: users@cocoon.apache.org List-Id: Delivered-To: mailing list users@cocoon.apache.org Received: (qmail 36094 invoked by uid 99); 15 Jan 2007 20:50:00 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jan 2007 12:50:00 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: local policy) Received: from [74.52.162.130] (HELO mx11.mesanetworks.net) (74.52.162.130) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Jan 2007 12:49:50 -0800 Received: (qmail 27309 invoked by uid 509); 15 Jan 2007 13:50:47 -0700 Received: from 65.175.0.109 by mx11.mesanetworks.net (envelope-from , uid 508) with qmail-scanner-1.25-st-qms (clamdscan: 0.87/2133. spamassassin: 3.0.6. perlscan: 1.25-st-qms. Clear:RC:1(65.175.0.109):. Processed in 0.111436 secs); 15 Jan 2007 20:50:47 -0000 X-Antivirus-MESANETWORKS-Mail-From: cocoon@lojjic.net via mx11.mesanetworks.net X-Antivirus-MESANETWORKS: 1.25-st-qms (Clear:RC:1(65.175.0.109):. Processed in 0.111436 secs Process 27297) Received: from 65-175-0-109.static.mesanetworks.net (HELO mail.lojjic.net) (65.175.0.109) by mx11.mesanetworks.net with SMTP; 15 Jan 2007 13:50:47 -0700 Received: from 209.108.197.61 (SquirrelMail authenticated user jj) by mail.lojjic.net with HTTP; Mon, 15 Jan 2007 13:49:58 -0700 (MST) Message-ID: <28577.209.108.197.61.1168894198.squirrel@mail.lojjic.net> In-Reply-To: <28509.209.108.197.61.1168893993.squirrel@mail.lojjic.net> References: <45ABE0E6.7090503@hhpl.on.ca> <28509.209.108.197.61.1168893993.squirrel@mail.lojjic.net> Date: Mon, 15 Jan 2007 13:49:58 -0700 (MST) Subject: Re: Regular Expressions, flowscript and java.lang.Character From: "Jason Johnston" To: users@cocoon.apache.org User-Agent: SquirrelMail/1.4.4 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Checked: Checked by ClamAV on apache.org >> 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 ================= >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> --------------------------------------------------------------------- >> 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