Example usage for javax.el ExpressionFactory createValueExpression

List of usage examples for javax.el ExpressionFactory createValueExpression

Introduction

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

Prototype

public abstract ValueExpression createValueExpression(ELContext context, String expression,
        Class<?> expectedType);

Source Link

Document

Create a new value expression.

Usage

From source file:org.richfaces.el.ELBuilder.java

/**
 * Creates new expression using replacements provided 
 * @param expr          - original expression
 * @param expectedType  - expected type/*from w  ww  .  j a  v  a  2  s.co  m*/
 * @param factory       - expression factory
 * @param elContext     - El context
 * @param var           - var string
 * @param index         - index string
 * @param varR          - replacement for var
 * @param indexR        - replacement for index
 * @return 
 */
public static ValueExpression createValueExpression(String expr, Class<?> expectedType,
        ExpressionFactory factory, ELContext elContext, String var, String index, String varR, String indexR) {
    ELBuilder builder = new ELBuilder(expr, var, index, varR, indexR);
    String newExpr = builder.parse();
    return factory.createValueExpression(elContext, newExpr, expectedType);
}

From source file:org.richfaces.skin.SkinFactoryImpl.java

private void processProperties(FacesContext context, Map<Object, Object> properties) {
    ELContext elContext = context.getELContext();
    // replace all EL-expressions by prepared ValueBinding ?
    ApplicationFactory factory = (ApplicationFactory) FactoryFinder
            .getFactory(FactoryFinder.APPLICATION_FACTORY);
    Application app = factory.getApplication();

    for (Entry<Object, Object> entry : properties.entrySet()) {
        Object propertyObject = entry.getValue();
        if (propertyObject instanceof String) {
            String property = (String) propertyObject;
            if (ELUtils.isValueReference(property)) {
                ExpressionFactory expressionFactory = app.getExpressionFactory();
                entry.setValue(expressionFactory.createValueExpression(elContext, property, Object.class));
            } else {
                entry.setValue(property);
            }// www.j  a  v a2 s.c o m
        }
    }
}

From source file:org.tinygroup.jspengine.runtime.PageContextImpl.java

/**
 * Evaluates an EL expression/*from  w w w  .ja v  a  2s.  co  m*/
 *
 * @param expression The expression to be evaluated
 * @param expectedType The expected resulting type
 * @param pageContext The page context
 * @param functionMap Maps prefix and name to Method
 * @return The result of the evaluation
 */
public static Object evaluateExpression(final String expression, final Class expectedType,
        final PageContext pageContext, final ProtectedFunctionMapper functionMap) throws ELException {
    Object retValue;
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    ELContextImpl elContext = (ELContextImpl) pageContext.getELContext();
                    elContext.setFunctionMapper(functionMap);
                    ExpressionFactory expFactory = getExpressionFactory(pageContext);
                    ValueExpression expr = expFactory.createValueExpression(elContext, expression,
                            expectedType);
                    return expr.getValue(elContext);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception realEx = ex.getException();
            if (realEx instanceof ELException) {
                throw (ELException) realEx;
            } else {
                throw new ELException(realEx);
            }
        }
    } else {
        ELContextImpl elContext = (ELContextImpl) pageContext.getELContext();
        elContext.setFunctionMapper(functionMap);
        ExpressionFactory expFactory = getExpressionFactory(pageContext);
        ValueExpression expr = expFactory.createValueExpression(elContext, expression, expectedType);
        retValue = expr.getValue(elContext);
    }
    return retValue;
}

From source file:org.tinygroup.jspengine.runtime.PageContextImpl.java

public static ValueExpression getValueExpression(String expression, PageContext pageContext, Class expectedType,
        FunctionMapper functionMap) {/*from  ww  w  .j a v  a2 s .  co  m*/
    // ELResolvers are not used in createValueExpression
    ELContextImpl elctxt = (ELContextImpl) pageContext.getELContext();
    elctxt.setFunctionMapper(functionMap);
    ExpressionFactory expFactory = getExpressionFactory(pageContext);
    return expFactory.createValueExpression(elctxt, expression, expectedType);
}

From source file:pl.umk.mat.zawodyweb.www.FaceletErrorHandler.java

@Override
public String getActionURL(FacesContext context, String viewId) {
    String result = super.getActionURL(context, viewId);

    if (result.contains("#{")) {
        ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
        ValueExpression valueExpression = expressionFactory.createValueExpression(context.getELContext(),
                viewId, String.class);
        ExternalContext externalContext = context.getExternalContext();
        String contextPath = externalContext.getRequestContextPath();
        result = contextPath + ((String) valueExpression.getValue(context.getELContext()));
    }//from   www  .  j  a va2  s.  com

    return result;
}