List of usage examples for org.springframework.expression Expression getValue
@Nullable
<T> T getValue(EvaluationContext context, @Nullable Class<T> desiredResultType) throws EvaluationException;
From source file:com.fitbur.core.el.spring.SpringExpressionService.java
@Override public <T> T eval(String name, Reader template, Object context, Class<T> resultType) { Expression expression = compile(name, template); StandardEvaluationContext ctx = contextProvider.get(); ctx.setRootObject(context);//from w w w . j a va 2s. co m return expression.getValue(ctx, resultType); }
From source file:com.google.code.activetemplates.impl.CompileContext.java
public <T> T parseExpression(String expression, Class<T> clazz) { Expression expr = expressionParser.parseExpression(expression); return expr.getValue(getEvaluationContext(), clazz); }
From source file:com.google.code.activetemplates.impl.CompileContext.java
public <T> T parseTemplateExpression(String expression, Class<T> clazz) { Expression expr = expressionParser.parseExpression(expression, TEMPLATE_PARSER_CONTEXT); return expr.getValue(getEvaluationContext(), clazz); }
From source file:grails.plugin.cache.web.filter.ExpressionEvaluator.java
public boolean condition(String conditionExpression, Method method, EvaluationContext evalContext) { String key = toString(method, conditionExpression); Expression condExp = conditionCache.get(key); if (condExp == null) { condExp = parser.parseExpression(conditionExpression); conditionCache.put(key, condExp); }/*from w w w . j av a 2s . com*/ return condExp.getValue(evalContext, boolean.class); }
From source file:com.fitbur.core.el.spring.SpringExpressionService.java
@Override public <T> T eval(String name, Reader template, Map<String, Object> context, Class<T> resultType) { Expression expression = compile(name, template); StandardEvaluationContext ctx = contextProvider.get(); ctx.addPropertyAccessor(mapAccessor); ctx.setRootObject(context);/* w ww . ja v a 2 s . c o m*/ return expression.getValue(ctx, resultType); }
From source file:it.geosolutions.geostore.core.security.ExpressionUserMapper.java
@Override /**//from w ww . j a va2s.c o m * If details is a UserDetailsWithAttributes object, its attributes are mapped to User * attributes. * Each mapping is an SpEL expression using the UserDetailsWithAttributes as a source. * */ public void mapUser(Object details, User user) { List<UserAttribute> attributes = new ArrayList<UserAttribute>(); details = preProcessDetails(details); for (String attributeName : attributeMappings.keySet()) { Expression exp = parser.parseExpression(attributeMappings.get(attributeName)); UserAttribute userAttribute = new UserAttribute(); userAttribute.setName(attributeName); Object value = exp.getValue(evaluationContext, details); userAttribute.setValue(value == null ? null : value.toString()); attributes.add(userAttribute); } user.setAttribute(attributes); }
From source file:com.oneops.controller.cms.ExpressionEvaluator.java
public boolean isExpressionMatching(CmsCI complianceCi, CmsWorkOrderBase wo) { CmsCIAttribute attr = complianceCi.getAttribute(ATTR_NAME_FILTER); if (attr == null) { return false; }//from w w w .j a v a 2 s . c o m String filter = attr.getDjValue(); try { if (StringUtils.isNotBlank(filter)) { Expression expr = exprParser.parseExpression(filter); EvaluationContext context = getEvaluationContext(wo); //parse the filter expression and check if it matches this ci/rfc Boolean match = expr.getValue(context, Boolean.class); if (logger.isDebugEnabled()) { logger.debug("Expression " + filter + " provided by compliance ci " + complianceCi.getCiId() + " not matched for ci " + getCiName(wo)); } return match; } } catch (ParseException | EvaluationException e) { String error = "Error in evaluating expression " + filter + " provided by compliance ci " + complianceCi.getCiId() + ", target ci :" + getCiName(wo); logger.error(error, e); } return false; }
From source file:org.jasig.irclog.SpelEventFormatter.java
@Override public String formatEvent(IrcEvent event) { final Expression expression = this.formatExpressions.get(event.getClass()); if (expression == null) { logger.warn("No Expression configured for event " + event + ". event.toString() will be returned"); return event.toString(); }//from www . j a va 2 s . c om final String message = expression.getValue(event, String.class); this.logger.trace("Formatted '" + expression.getExpressionString() + "' to '" + message); return message; }
From source file:org.jmingo.el.springexp.SpringELEngine.java
/** * {@inheritDoc}// w ww . j a v a2s . com */ @Override public synchronized boolean evaluate(String expression, Map<String, Object> parameters) { Validate.notBlank(expression, "expression cannot be empty"); Expression exp = parser.parseExpression(expression); EvaluationContext context = new StandardEvaluationContext(); if (MapUtils.isNotEmpty(parameters)) { for (Map.Entry<String, Object> parameter : parameters.entrySet()) { context.setVariable(parameter.getKey(), parameter.getValue()); } } return exp.getValue(context, Boolean.class); }
From source file:fr.acxio.tools.agia.expression.StandardDataExpressionResolver.java
@Override public <T> T evaluate(String sExpression, EvaluationContext sEvalContext, Class<T> sTargetType) { if (!StringUtils.hasLength(sExpression)) { if (sTargetType == null || ClassUtils.isAssignableValue(sTargetType, sExpression)) { return (T) sExpression; }//from ww w. j a v a 2s . c o m throw new EvaluationException( "Cannot convert value '" + sExpression + "' to type '" + sTargetType.getName() + "'"); } try { Expression expr = this.expressionCache.get(sExpression); if (expr == null) { expr = this.expressionParser.parseExpression(sExpression, expressionParserContext); this.expressionCache.put(sExpression, expr); } return expr.getValue(sEvalContext, sTargetType); } catch (Exception ex) { throw new EvaluationException("Expression parsing failed", ex); } }