/** * Turn {@link ExpressionVariable}'s (pairs of variable names and string expressions) * into a map of variable names and parsed Spring EL expressions. The map will be saved * in a Spring EL {@link EvaluationContext} for later use at evaluation time. * * @param expressionVars an array of ExpressionVariable instances. * @return a Map or null if the input array is empty. */ private Map<String, Expression> parseSpelExpressionVariables(ExpressionVariable[] expressionVars) { if (expressionVars == null || expressionVars.length == 0) { return null; } Map<String, Expression> result = new HashMap<>(expressionVars.length); for (ExpressionVariable var : expressionVars) { result.put(var.getName(), parseExpression(var.getValueExpression(), var.getParserContext())); } return result; }
/** * Gets spring expression parser. * * @return the spring expression parser */ public SpringELExpressionParser getSpringExpressionParser() { val configuration = new SpelParserConfiguration(); val spelExpressionParser = new SpelExpressionParser(configuration); val parser = new SpringELExpressionParser(spelExpressionParser, this.flowBuilderServices.getConversionService()); parser.addPropertyAccessor(new ActionPropertyAccessor()); parser.addPropertyAccessor(new BeanFactoryPropertyAccessor()); parser.addPropertyAccessor(new FlowVariablePropertyAccessor()); parser.addPropertyAccessor(new MapAdaptablePropertyAccessor()); parser.addPropertyAccessor(new MessageSourcePropertyAccessor()); parser.addPropertyAccessor(new ScopeSearchingPropertyAccessor()); parser.addPropertyAccessor(new BeanExpressionContextAccessor()); parser.addPropertyAccessor(new MapAccessor()); parser.addPropertyAccessor(new MapAdaptablePropertyAccessor()); parser.addPropertyAccessor(new EnvironmentAccessor()); parser.addPropertyAccessor(new ReflectivePropertyAccessor()); return parser; }
public Expression parseExpression(String expression, ParserContext context) throws ParserException { Assert.hasText(expression, "The expression string to parse is required and must not be empty"); context = (context == null) ? NullParserContext.INSTANCE : context; Map<String, Expression> expressionVars = parseSpelExpressionVariables(context.getExpressionVariables()); org.springframework.expression.Expression spelExpression = parseSpelExpression(expression, context); Class<?> expectedResultType = context.getExpectedEvaluationResultType(); org.springframework.core.convert.ConversionService cs = conversionService.getDelegateConversionService(); return context instanceof SimpleParserContext ? new SpringELExpression(spelExpression, expectedResultType, simpleContextFactory) : createSpringELExpression(expressionVars, spelExpression, expectedResultType, cs); }
protected void setUp() { parser.addPropertyAccessor(new SpecialPropertyAccessor()); }
@Override protected void setUp() { StaticMessageSource messageSource = new StaticMessageSource(); messageSource.addMessage("foo", Locale.getDefault(), "bar"); messageSource.addMessage("bar", Locale.getDefault(), "{0}"); context = new DefaultMessageContext(messageSource); SpringELExpressionParser parser = new SpringELExpressionParser(new SpelExpressionParser()); DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver(); errors = new MessageContextErrors(context, "object", new Object(), parser, resolver, null); }
private SpringELExpressionParser createExpressionParser() { StringToDate c = new StringToDate(); c.setPattern("yyyy-MM-dd"); SpringELExpressionParser parser = new WebFlowSpringELExpressionParser(new SpelExpressionParser()); GenericConversionService cs = (GenericConversionService) parser.getConversionService(); cs.addConverter(c); return parser; }
private org.springframework.expression.Expression parseSpelExpression(String expression, ParserContext context) { org.springframework.expression.ParserContext spelParserContext = getSpelParserContext(context); if (spelParserContext != null) { return expressionParser.parseExpression(expression, spelParserContext); } return expressionParser.parseExpression(expression); }
public void testFlowBuilderServicesConversionServiceCustomized() { this.builderServices = (FlowBuilderServices) this.context.getBean("flowBuilderServicesConversionServiceCustom"); assertNotNull(this.builderServices); assertTrue(this.builderServices.getConversionService() instanceof TestConversionService); assertTrue(this.builderServices.getExpressionParser() instanceof WebFlowSpringELExpressionParser); assertTrue(((SpringELExpressionParser) this.builderServices.getExpressionParser()).getConversionService() instanceof TestConversionService); assertTrue(this.builderServices.getViewFactoryCreator() instanceof JsfViewFactoryCreator); assertFalse(this.builderServices.getDevelopment()); }
private org.springframework.expression.Expression parseSpelExpression(String expression, ParserContext context) { org.springframework.expression.ParserContext spelParserContext = getSpelParserContext(context); if (spelParserContext != null) { return expressionParser.parseExpression(expression, spelParserContext); } return expressionParser.parseExpression(expression); }
/** * Turn {@link ExpressionVariable}'s (pairs of variable names and string expressions) * into a map of variable names and parsed Spring EL expressions. The map will be saved * in a Spring EL {@link EvaluationContext} for later use at evaluation time. * * @param expressionVars an array of ExpressionVariable instances. * @return a Map or null if the input array is empty. */ private Map<String, Expression> parseSpelExpressionVariables(ExpressionVariable[] expressionVars) { if (expressionVars == null || expressionVars.length == 0) { return null; } Map<String, Expression> result = new HashMap<>(expressionVars.length); for (ExpressionVariable var : expressionVars) { result.put(var.getName(), parseExpression(var.getValueExpression(), var.getParserContext())); } return result; }
public Expression parseExpression(String expression, ParserContext context) throws ParserException { Assert.hasText(expression, "The expression string to parse is required and must not be empty"); context = (context == null) ? NullParserContext.INSTANCE : context; Map<String, Expression> expressionVars = parseSpelExpressionVariables(context.getExpressionVariables()); org.springframework.expression.Expression spelExpression = parseSpelExpression(expression, context); Class<?> expectedResultType = context.getExpectedEvaluationResultType(); org.springframework.core.convert.ConversionService cs = conversionService.getDelegateConversionService(); return context instanceof SimpleParserContext ? new SpringELExpression(spelExpression, expectedResultType, simpleContextFactory) : createSpringELExpression(expressionVars, spelExpression, expectedResultType, cs); }
/** * Gets spring expression parser. * * @return the spring expression parser */ protected SpringELExpressionParser getSpringExpressionParser() { final SpelParserConfiguration configuration = new SpelParserConfiguration(); final SpelExpressionParser spelExpressionParser = new SpelExpressionParser(configuration); final SpringELExpressionParser parser = new SpringELExpressionParser(spelExpressionParser, this.flowBuilderServices.getConversionService()); parser.addPropertyAccessor(new ActionPropertyAccessor()); parser.addPropertyAccessor(new BeanFactoryPropertyAccessor()); parser.addPropertyAccessor(new FlowVariablePropertyAccessor()); parser.addPropertyAccessor(new MapAdaptablePropertyAccessor()); parser.addPropertyAccessor(new MessageSourcePropertyAccessor()); parser.addPropertyAccessor(new ScopeSearchingPropertyAccessor()); parser.addPropertyAccessor(new BeanExpressionContextAccessor()); parser.addPropertyAccessor(new MapAccessor()); parser.addPropertyAccessor(new MapAdaptablePropertyAccessor()); parser.addPropertyAccessor(new EnvironmentAccessor()); parser.addPropertyAccessor(new ReflectivePropertyAccessor()); return parser; }
public void testFlowBuilderServicesConversionServiceCustomized() { builderServices = (FlowBuilderServices) context.getBean("flowBuilderServicesConversionServiceCustom"); assertNotNull(builderServices); assertTrue(builderServices.getConversionService() instanceof TestConversionService); assertTrue(builderServices.getExpressionParser() instanceof SpringELExpressionParser); assertTrue(((SpringELExpressionParser) builderServices.getExpressionParser()).getConversionService() instanceof TestConversionService); assertTrue(builderServices.getViewFactoryCreator() instanceof MvcViewFactoryCreator); assertNull(builderServices.getValidator()); assertNull(builderServices.getValidationHintResolver()); assertFalse(builderServices.getDevelopment()); }
public void testParseNullExpressionString() { String expressionString = null; try { parser.parseExpression(expressionString, null); fail("should have thrown iae"); } catch (IllegalArgumentException e) { } }
public void testParseEmptyExpressionString() { String expressionString = ""; try { parser.parseExpression(expressionString, null); fail("should have thrown iae"); } catch (IllegalArgumentException e) { } }
/** * Create expression expression. * * @param expression the expression * @param expectedType the expected type * @return the expression */ public Expression createExpression(final String expression, final Class expectedType) { val parserContext = new FluentParserContext().expectResult(expectedType); return getSpringExpressionParser().parseExpression(expression, parserContext); }
/** * Create expression expression. * * @param flow the flow * @param expression the expression * @param expectedType the expected type * @return the expression */ protected Expression createExpression(final Flow flow, final String expression, final Class expectedType) { final ParserContext parserContext = new FluentParserContext() .expectResult(expectedType); return getSpringExpressionParser().parseExpression(expression, parserContext); }
public void testParseSimpleEvalExpressionNoParserContext() { String expressionString = "3 + 4"; Expression exp = parser.parseExpression(expressionString, null); assertEquals(7, exp.getValue(null)); // Unified EL returns Long }
public void testGetExpressionString() { String expressionString = "maximum"; Expression exp = parser.parseExpression(expressionString, null); assertEquals("maximum", exp.getExpressionString()); }
public void testGetExpressionType() { String expressionString = "maximum"; Expression exp = parser.parseExpression(expressionString, null); TestBean context = new TestBean(); Class<?> clazz = exp.getValueType(context); assertTrue(int.class.equals(clazz) || Integer.class.equals(clazz)); }