List of usage examples for javax.el ELContext getVariableMapper
public abstract VariableMapper getVariableMapper();
From source file:org.nuxeo.ecm.platform.actions.jsf.JSFActionContext.java
@Override public boolean checkCondition(String expression) throws ELException { if (StringUtils.isBlank(expression) || (expression != null && StringUtils.isBlank(expression.trim()))) { return false; }/* ww w . j a va2 s.c o m*/ String expr = expression.trim(); // compatibility code, as JEXL could resolve that kind of expression: // detect if expression is in brackets #{}, otherwise add it if (!expr.startsWith("#{") && !expr.startsWith("${") // don't confuse error messages in case of simple mistakes in the // expression && !expr.endsWith("}")) { expr = "#{" + expr + "}"; } ELContext finalContext = new JSFELContext(originalContext); VariableMapper vm = finalContext.getVariableMapper(); // init default variables ValueExpression documentExpr = expressionFactory.createValueExpression(getCurrentDocument(), DocumentModel.class); ValueExpression userExpr = expressionFactory.createValueExpression(getCurrentPrincipal(), NuxeoPrincipal.class); vm.setVariable("actionContextDocument", documentExpr); // add variables originally exposed by the action framework, // do not add aliases currentDocument and currentUser here as they // should already be available in this JSF context vm.setVariable("document", documentExpr); vm.setVariable("principal", userExpr); // get custom context from ActionContext for (String key : localVariables.keySet()) { vm.setVariable(key, expressionFactory.createValueExpression(getLocalVariable(key), Object.class)); } // expose Seam context for compatibility, although available its // components should be natively exposed in this JSF context putLocalVariable("SeamContext", new SeamContextHelper()); // evaluate expression ValueExpression ve = expressionFactory.createValueExpression(finalContext, expr, Boolean.class); return Boolean.TRUE.equals(ve.getValue(finalContext)); }
From source file:org.richfaces.taglib.ColumnsTag.java
/** * Create custom context with VariableMapper override. * /*from www .j a v a 2 s. c o m*/ * @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); } }; } }; }