Example usage for javax.el ELContext ELContext

List of usage examples for javax.el ELContext ELContext

Introduction

In this page you can find the example usage for javax.el ELContext ELContext.

Prototype

public ELContext() 

Source Link

Usage

From source file:biz.netcentric.cq.tools.actool.configreader.YamlMacroElEvaluator.java

public YamlMacroElEvaluator() {

    try {//from w w  w .  ja va2s.  co m
        Class<?> expressionFactoryClass = getClass().getClassLoader()
                .loadClass("org.apache.el.ExpressionFactoryImpl");
        expressionFactory = (ExpressionFactory) expressionFactoryClass.newInstance();
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new IllegalStateException("Could not init EL: " + e);
    }

    final VariableMapper variableMapper = new ElVariableMapper();
    final ElFunctionMapper functionMapper = new ElFunctionMapper();
    final CompositeELResolver compositeELResolver = new CompositeELResolver();

    compositeELResolver.add(new BaseELResolver());
    compositeELResolver.add(new ArrayELResolver());
    compositeELResolver.add(new ListELResolver());
    compositeELResolver.add(new BeanELResolver());
    compositeELResolver.add(new MapELResolver());
    context = new ELContext() {
        @Override
        public ELResolver getELResolver() {
            return compositeELResolver;
        }

        @Override
        public FunctionMapper getFunctionMapper() {
            return functionMapper;
        }

        @Override
        public VariableMapper getVariableMapper() {
            return variableMapper;
        }
    };

}

From source file:org.richfaces.taglib.ColumnsTag.java

/**
 * Create custom context with VariableMapper override.
 * /*from   w  w w .j av  a  2s.  c om*/
 * @param context
 * @return
 */
private ELContext getContext(final ELContext cont) {
    return new ELContext() {

        @Override
        public Object getContext(Class key) {
            return cont.getContext(key);
        }

        @Override
        public ELResolver getELResolver() {
            return cont.getELResolver();
        }

        @Override
        public FunctionMapper getFunctionMapper() {
            return cont.getFunctionMapper();
        }

        @Override
        public VariableMapper getVariableMapper() {
            return new VariableMapper() {

                @Override
                public ValueExpression resolveVariable(String variable) {
                    if (variable.equals(itemId)) {
                        return new IndexedValueExpression(__value, index);
                    } else if (variable.equals(indexId)) {
                        return new IteratedIndexExpression(index);
                    }
                    return cont.getVariableMapper().resolveVariable(variable);
                }

                @Override
                public ValueExpression setVariable(String variable, ValueExpression expression) {
                    return cont.getVariableMapper().setVariable(variable, expression);
                }

            };
        }

    };
}