Search in sources :

Example 91 with ExpressionParser

use of org.springframework.expression.ExpressionParser in project spring-security by spring-projects.

the class ExpressionBasedAnnotationAttributeFactory method createPostInvocationAttribute.

public PostInvocationAttribute createPostInvocationAttribute(String postFilterAttribute, String postAuthorizeAttribute) {
    try {
        ExpressionParser parser = getParser();
        Expression postAuthorizeExpression = postAuthorizeAttribute == null ? null : parser.parseExpression(postAuthorizeAttribute);
        Expression postFilterExpression = postFilterAttribute == null ? null : parser.parseExpression(postFilterAttribute);
        if (postFilterExpression != null || postAuthorizeExpression != null) {
            return new PostInvocationExpressionAttribute(postFilterExpression, postAuthorizeExpression);
        }
    } catch (ParseException e) {
        throw new IllegalArgumentException("Failed to parse expression '" + e.getExpressionString() + "'", e);
    }
    return null;
}
Also used : Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) ParseException(org.springframework.expression.ParseException)

Example 92 with ExpressionParser

use of org.springframework.expression.ExpressionParser in project opennms by OpenNMS.

the class PersistRegexSelectorStrategyTest method testSpringEl.

@Test
public void testSpringEl() throws Exception {
    ExpressionParser parser = new SpelExpressionParser();
    Expression exp = parser.parseExpression("#name matches '^Alejandro.*'");
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setVariable("name", "Alejandro Galue");
    boolean result = (Boolean) exp.getValue(context, Boolean.class);
    Assert.assertTrue(result);
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Test(org.junit.Test)

Aggregations

ExpressionParser (org.springframework.expression.ExpressionParser)92 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)89 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)81 Expression (org.springframework.expression.Expression)78 Test (org.junit.Test)76 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)51 EvaluationContext (org.springframework.expression.EvaluationContext)10 BigInteger (java.math.BigInteger)6 Map (java.util.Map)5 BigDecimal (java.math.BigDecimal)4 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 TreeMap (java.util.TreeMap)3 ParseException (org.springframework.expression.ParseException)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 SyslogRuntimeException (org.graylog2.syslog4j.SyslogRuntimeException)2 EvaluationException (org.springframework.expression.EvaluationException)2