commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christoph Gaffga (" <>
Subject [Jexl] String Literals with Newline do not work
Date Fri, 06 Jul 2007 14:46:55 GMT
hi all,

I have some problems to use Jexl expressions to look for special
characters in strings, like newline or tabs:

  e = ExpressionFactory.createExpression("'\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,

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() {

    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("");
        Object o = e.evaluate(jc);
        System.out.println("Return " + o);

        // try to search for newline...
        e = ExpressionFactory.createExpression("'\n')");
        o = e.evaluate(jc);
        System.out.println("Return'\\n'): " + o);

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message