use of org.springframework.expression.Expression in project uPortal by Jasig.
the class PortalSpELServiceImpl method getValue.
@Override
public String getValue(String expressionString, Object spelEnvironment) {
final StandardEvaluationContext context = new StandardEvaluationContext(spelEnvironment);
context.setBeanResolver(this.beanResolver);
final Expression expression = this.parseCachedExpression(expressionString, TemplateParserContext.INSTANCE);
return expression.getValue(context, String.class);
}
use of org.springframework.expression.Expression in project uPortal by Jasig.
the class PortletSpELServiceImpl method parseExpression.
@Override
public Expression parseExpression(String expressionString) throws ParseException {
if (this.expressionCache == null) {
return parseExpression(expressionString, TemplateParserContext.INSTANCE);
}
Element element = this.expressionCache.get(expressionString);
if (element != null) {
return (Expression) element.getObjectValue();
}
final Expression expression = parseExpression(expressionString, TemplateParserContext.INSTANCE);
element = new Element(expressionString, expression);
this.expressionCache.put(element);
return expression;
}
use of org.springframework.expression.Expression in project uPortal by Jasig.
the class RoleBasedBackgroundSetSelectionStrategy method evaluateImagePath.
/*
* Implementation
*/
private String evaluateImagePath(String pathBeforeProcessing) {
final Expression x = portalSpELService.parseExpression(pathBeforeProcessing, PortalSpELServiceImpl.TemplateParserContext.INSTANCE);
final String rslt = x.getValue(evaluationContext, String.class);
return rslt;
}
use of org.springframework.expression.Expression in project spring-framework by spring-projects.
the class CachedExpressionEvaluator method getExpression.
/**
* Return the {@link Expression} for the specified SpEL value
* <p>Parse the expression if it hasn't been already.
* @param cache the cache to use
* @param elementKey the element on which the expression is defined
* @param expression the expression to parse
*/
protected Expression getExpression(Map<ExpressionKey, Expression> cache, AnnotatedElementKey elementKey, String expression) {
ExpressionKey expressionKey = createKey(elementKey, expression);
Expression expr = cache.get(expressionKey);
if (expr == null) {
expr = getParser().parseExpression(expression);
cache.put(expressionKey, expr);
}
return expr;
}
use of org.springframework.expression.Expression in project spring-framework by spring-projects.
the class AbstractExpressionTests method evaluate.
/**
* Evaluate an expression and check that the actual result matches the
* expectedValue and the class of the result matches the expectedClassOfResult.
* This method can also check if the expression is writable (for example,
* it is a variable or property reference).
* @param expression the expression to evaluate
* @param expectedValue the expected result for evaluating the expression
* @param expectedClassOfResult the expected class of the evaluation result
* @param shouldBeWritable should the parsed expression be writable?
*/
public void evaluate(String expression, Object expectedValue, Class<?> expectedClassOfResult, boolean shouldBeWritable) {
Expression expr = parser.parseExpression(expression);
if (expr == null) {
fail("Parser returned null for expression");
}
if (DEBUG) {
SpelUtilities.printAbstractSyntaxTree(System.out, expr);
}
Object value = expr.getValue(eContext);
if (value == null) {
if (expectedValue == null) {
// no point doing other checks
return;
}
assertEquals("Expression returned null value, but expected '" + expectedValue + "'", expectedValue, null);
}
Class<? extends Object> resultType = value.getClass();
if (expectedValue instanceof String) {
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, AbstractExpressionTests.stringValueOf(value));
} else {
assertEquals("Did not get expected value for expression '" + expression + "'.", expectedValue, value);
}
assertEquals("Type of the result was not as expected. Expected '" + expectedClassOfResult + "' but result was of type '" + resultType + "'", expectedClassOfResult.equals(resultType), true);
boolean isWritable = expr.isWritable(eContext);
if (isWritable != shouldBeWritable) {
if (shouldBeWritable)
fail("Expected the expression to be writable but it is not");
else
fail("Expected the expression to be readonly but it is not");
}
}
Aggregations