Package org.apache.jasper.el

Examples of org.apache.jasper.el.ELContextImpl


    }

    @Test
    public void testBug51177ObjectList() {
        ExpressionFactory factory = ExpressionFactory.newInstance();
        ELContext context = new ELContextImpl();
       
        Object o1 = "String value";
        Object o2 = Integer.valueOf(32);

        List<Object> list = new ArrayList<Object>();
        list.add(0, o1);
        list.add(1, o2);
       
        ValueExpression var =
            factory.createValueExpression(list, List.class);
        context.getVariableMapper().setVariable("list", var);

        ValueExpression ve1 = factory.createValueExpression(
                context, "${list[0]}", Object.class);
        ve1.setValue(context, o2);
        assertEquals(o2, ve1.getValue(context));
View Full Code Here


     * Test returning an empty list as a bean property.
     */
    @Test
    public void testBug51544Bean() throws Exception {
        ExpressionFactory factory = ExpressionFactory.newInstance();
        ELContext context = new ELContextImpl();
       
        TesterBeanA beanA = new TesterBeanA();
        beanA.setValList(Collections.emptyList());
       
        ValueExpression var =
            factory.createValueExpression(beanA, TesterBeanA.class);
        context.getVariableMapper().setVariable("beanA", var);

        ValueExpression ve = factory.createValueExpression(
                context, "${beanA.valList.size()}", Integer.class);

        Integer result = (Integer) ve.getValue(context);
View Full Code Here

     * Test using list directly as variable.
     */
    @Test
    public void testBug51544Direct() throws Exception {
        ExpressionFactory factory = ExpressionFactory.newInstance();
        ELContext context = new ELContextImpl();
       
        List<?> list = Collections.emptyList();
       
        ValueExpression var =
            factory.createValueExpression(list, List.class);
        context.getVariableMapper().setVariable("list", var);

        ValueExpression ve = factory.createValueExpression(
                context, "${list.size()}", Integer.class);

        Integer result = (Integer) ve.getValue(context);
View Full Code Here


    // ************************************************************************

    private String evaluateExpression(String expression) {
        ELContextImpl ctx = new ELContextImpl();
        ctx.setFunctionMapper(new FMapper());
        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ValueExpression ve = exprFactory.createValueExpression(ctx, expression,
                String.class);
        return (String) ve.getValue(ctx);
    }
View Full Code Here

        // Don't try and evaluate expressions that depend on variables or functions
        if (expected != null) {
            try {
                ExpressionFactory factory = ExpressionFactory.newInstance();
                ELContext context = new ELContextImpl();
                ValueExpression ve = factory.createValueExpression(context, input, String.class);
                elResult = ve.getValue(context).toString();
                Assert.assertEquals(expected, elResult);
            } catch (ELException ele) {
                elException = ele;
View Full Code Here

                    result = new Node.JspAttribute(tai, qName, uri, localName,
                            value, false, el, dynamic);

                    if (el != null) {
                        ELContextImpl ctx = new ELContextImpl();
                        ctx.setFunctionMapper(getFunctionMapper(el));

                        try {
                            result.validateEL(this.pageInfo
                                    .getExpressionFactory(), ctx);
                        } catch (ELException e) {
View Full Code Here

        private void prepareExpression(ELNode.Nodes el, Node n, String expr)
                throws JasperException {
            validateFunctions(el, n);

            // test it out
            ELContextImpl ctx = new ELContextImpl();
            ctx.setFunctionMapper(this.getFunctionMapper(el));
            ExpressionFactory ef = this.pageInfo.getExpressionFactory();
            try {
                ef.createValueExpression(ctx, expr, Object.class);
            } catch (ELException e) {
View Full Code Here

                retValue = AccessController
                        .doPrivileged(new PrivilegedExceptionAction<Object>() {

                            @Override
                            public Object run() throws Exception {
                                ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
                                ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
                                ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
                                return ve.getValue(ctx);
                            }
                        });
            } catch (PrivilegedActionException ex) {
                Exception realEx = ex.getException();
                if (realEx instanceof ELException) {
                    throw (ELException) realEx;
                } else {
                    throw new ELException(realEx);
                }
            }
        } else {
            ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
            ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
            ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
            retValue = ve.getValue(ctx);
        }
        if (escape && retValue != null) {
            retValue = XmlEscape(retValue.toString());
View Full Code Here

      try {
        retValue = AccessController
            .doPrivileged(new PrivilegedExceptionAction() {

              public Object run() throws Exception {
                                ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
                                ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
                ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
                                return ve.getValue(ctx);
              }
            });
      } catch (PrivilegedActionException ex) {
        Exception realEx = ex.getException();
        if (realEx instanceof ELException) {
          throw (ELException) realEx;
        } else {
          throw new ELException(realEx);
        }
      }
    } else {
            ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
            ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
            ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
            retValue = ve.getValue(ctx);
    }
    return retValue;
  }
View Full Code Here

                                        validateFunctions(el, n);
                                        jspAttrs[i] = new Node.JspAttribute(tldAttr,
                                                attrs.getQName(i), attrs.getURI(i),
                                                attrs.getLocalName(i),
                                                attrs.getValue(i), false, el, false);
                                        ELContextImpl ctx = new ELContextImpl(expressionFactory);
                                        ctx.setFunctionMapper(getFunctionMapper(el));
                                        try {
                                            jspAttrs[i].validateEL(this.pageInfo.getExpressionFactory(), ctx);
                                        } catch (ELException e) {
                                            err.jspError(n.getStart(),
                                                    MESSAGES.invalidExpression(attrs.getValue(i)), e);
View Full Code Here

TOP

Related Classes of org.apache.jasper.el.ELContextImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.