List of usage examples for org.springframework.expression Expression getValue
@Nullable
Object getValue(EvaluationContext context) throws EvaluationException;
From source file:gov.nih.nci.calims2.taglib.form.SingleSelectHelper.java
/** * Evaluate the given expression in the given context. * //from w w w. j ava 2 s . co m * @param expression The expression to evaluate * @param context The evaluation context * @return The value of the expression as a string. */ static String evaluateExpression(Expression expression, EvaluationContext context) { try { Object value = expression.getValue(context); return (value != null) ? value.toString() : ""; } catch (EvaluationException e) { return ""; } }
From source file:gov.nih.nci.calims2.ui.generic.crud.CRUDTableDecorator.java
/** * Evaluate the given expression in the given context. * //ww w .ja v a 2 s.c o m * @param expression The expression to evaluate * @param context The evaluation context * @return */ private Object evaluateExpression(Expression expression, EvaluationContext context) { if (expression == null) { return null; } try { return expression.getValue(context); } catch (EvaluationException e) { return null; } }
From source file:org.apereo.portal.spring.spel.PortalSpELServiceImpl.java
@Override public Object getValue(Expression expression, WebRequest request) { final EvaluationContext evaluationContext = this.getEvaluationContext(request); return expression.getValue(evaluationContext); }
From source file:org.craftercms.security.impl.processors.UrlAccessRestrictionCheckingProcessor.java
/** * Executes the Spring EL expression using an {@link AccessRestrictionExpressionRoot}, with the user profile, * as root object. The/*from w w w .j a va2 s . com*/ * expression should return a boolean: true if access is allowed, false otherwise. */ protected boolean isAccessAllowed(UserProfile profile, Expression expression) { Object value = expression.getValue(createExpressionRoot(profile)); if (!(value instanceof Boolean)) { throw new CrafterSecurityException( "Expression " + expression.getExpressionString() + " should return a " + "boolean value"); } return (Boolean) value; }
From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java
/** * @see org.kuali.rice.krad.uif.service.ExpressionEvaluatorService#evaluateExpression(java.lang.Object, * java.util.Map, java.lang.String) */// w ww . j av a 2 s.com public Object evaluateExpression(Object contextObject, Map<String, Object> evaluationParameters, String expressionStr) { StandardEvaluationContext context = new StandardEvaluationContext(contextObject); context.setVariables(evaluationParameters); addCustomFunctions(context); // if expression contains placeholders remove before evaluating if (StringUtils.startsWith(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX) && StringUtils.endsWith(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX)) { expressionStr = StringUtils.removeStart(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX); expressionStr = StringUtils.removeEnd(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX); } ExpressionParser parser = new SpelExpressionParser(); Object result = null; try { Expression expression = parser.parseExpression(expressionStr); result = expression.getValue(context); } catch (Exception e) { LOG.error("Exception evaluating expression: " + expressionStr); throw new RuntimeException("Exception evaluating expression: " + expressionStr, e); } return result; }
From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java
/** * {@inheritDoc}// ww w . j a va2 s . c o m */ @Override public Object evaluateExpression(Map<String, Object> evaluationParameters, String expressionStr) { Object result = null; // if expression contains placeholders remove before evaluating if (StringUtils.startsWith(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX) && StringUtils.endsWith(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX)) { expressionStr = StringUtils.removeStart(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX); expressionStr = StringUtils.removeEnd(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX); } try { Expression expression = retrieveCachedExpression(expressionStr); if (evaluationParameters != null) { evaluationContext.setVariables(evaluationParameters); } result = expression.getValue(evaluationContext); } catch (Exception e) { LOG.error("Exception evaluating expression: " + expressionStr); throw new RuntimeException("Exception evaluating expression: " + expressionStr, e); } return result; }
From source file:org.springframework.cloud.function.deployer.ApplicationRunner.java
private Object getBeanByName(String name) { Expression parsed = new SpelExpressionParser().parseExpression("context.getBean(\"" + name + "\")"); return parsed.getValue(this.app); }
From source file:org.springframework.cloud.function.deployer.ApplicationRunner.java
private Object getBeanByType(String name) { Expression parsed = new SpelExpressionParser().parseExpression("context.getBean(T(" + name + "))"); return parsed.getValue(this.app); }
From source file:org.springframework.cloud.function.deployer.ApplicationRunner.java
public boolean containsBean(String name) { if (this.app != null) { if (containsBeanByName(name)) { return true; }//from www. jav a2s .c o m Expression parsed = new SpelExpressionParser() .parseExpression("context.getBeansOfType(T(" + name + "))"); try { @SuppressWarnings("unchecked") Map<String, Object> beans = (Map<String, Object>) parsed.getValue(this.app); return !beans.isEmpty(); } catch (Exception e) { } } return false; }
From source file:org.springframework.cloud.function.deployer.ApplicationRunner.java
/** * List the bean names in the application context for a given type (by its fully * qualified name)./*from w ww. j a v a2 s . co m*/ * @param type the name of the type (Class) * @return the bean names of that type */ public Set<String> getBeanNames(String type) { if (this.app != null) { Expression parsed = new SpelExpressionParser() .parseExpression("context.getBeansOfType(T(" + type + "))"); try { @SuppressWarnings("unchecked") Map<String, Object> beans = (Map<String, Object>) parsed.getValue(this.app); return beans.keySet(); } catch (Exception e) { } } return Collections.emptySet(); }