commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: [Jexl] String Literals with Newline do not work
Date Fri, 06 Jul 2007 14:57:06 GMT
On 06/07/07, Christoph Gaffga (triplemind.com) <cgaffga@triplemind.com> wrote:
> hi all,
>
> I have some problems to use Jexl expressions to look for special
> characters in strings, like newline or tabs:
>
>  e = ExpressionFactory.createExpression("foo.bar.indexOf('\n')");

Does not look valid syntax.

Try

e = ExpressionFactory.createExpression("foo.bar.indexOf('"\n'")");

>  o = e.evaluate(jc);
>
> there seem to be no way to encode the linebreak, I also tried '\\n' etc.
> No chance, always get an exception.
>
> Is this a bug in Jexl or is it my fault? Has anybody done this? How?
> I would appreciate any help...
>
> kind regards,
> Christoph
>
>
>
>
> P.S.: Here is my test programm:
> import org.apache.commons.jexl.Expression;
> import org.apache.commons.jexl.ExpressionFactory;
> import org.apache.commons.jexl.JexlContext;
> import org.apache.commons.jexl.JexlHelper;
>
> public class TestJexlLinebreaks {
>    public static class Foo {
>        String bar = "This is line 1,\nline 2,\nline 3.";
>        public String getBar() {
>            return this.bar;
>        }
>    }
>
>    public static void main(String[] args) throws Exception {
>        // First make a jexlContext and put stuff in it...
>        JexlContext jc = JexlHelper.createContext();
>        jc.getVars().put("foo", new Foo());
>        jc.getVars().put("number", new Integer(10));
>
>        // access a property...
>        Expression e = ExpressionFactory.createExpression("foo.bar");
>        Object o = e.evaluate(jc);
>        System.out.println("Return foo.bar: " + o);
>
>        // try to search for newline...
>        e = ExpressionFactory.createExpression("foo.bar.indexOf('\n')");
>        o = e.evaluate(jc);
>        System.out.println("Return foo.bar.indexOf('\\n'): " + o);
>    }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message