Search in sources :

Example 1 with ParserContext

use of org.springframework.expression.ParserContext in project camel by apache.

the class SpelExpression method parseExpression.

private Expression parseExpression() {
    // Support template parsing with #{ } delimiters
    ParserContext parserContext = new TemplateParserContext();
    Expression expression = expressionParser.parseExpression(expressionString, parserContext);
    return expression;
}
Also used : Expression(org.springframework.expression.Expression) TemplateParserContext(org.springframework.expression.common.TemplateParserContext) ParserContext(org.springframework.expression.ParserContext) TemplateParserContext(org.springframework.expression.common.TemplateParserContext)

Example 2 with ParserContext

use of org.springframework.expression.ParserContext in project spring-framework by spring-projects.

the class TemplateExpressionParsingTests method testTemplateParserContext.

@Test
public void testTemplateParserContext() {
    TemplateParserContext tpc = new TemplateParserContext("abc", "def");
    assertThat(tpc.getExpressionPrefix()).isEqualTo("abc");
    assertThat(tpc.getExpressionSuffix()).isEqualTo("def");
    assertThat(tpc.isTemplate()).isTrue();
    tpc = new TemplateParserContext();
    assertThat(tpc.getExpressionPrefix()).isEqualTo("#{");
    assertThat(tpc.getExpressionSuffix()).isEqualTo("}");
    assertThat(tpc.isTemplate()).isTrue();
    ParserContext pc = ParserContext.TEMPLATE_EXPRESSION;
    assertThat(pc.getExpressionPrefix()).isEqualTo("#{");
    assertThat(pc.getExpressionSuffix()).isEqualTo("}");
    assertThat(pc.isTemplate()).isTrue();
}
Also used : TemplateParserContext(org.springframework.expression.common.TemplateParserContext) ParserContext(org.springframework.expression.ParserContext) TemplateParserContext(org.springframework.expression.common.TemplateParserContext) Test(org.junit.jupiter.api.Test)

Example 3 with ParserContext

use of org.springframework.expression.ParserContext in project spring-framework by spring-projects.

the class SpelReproTests method NPE_SPR5673.

@Test
void NPE_SPR5673() {
    ParserContext hashes = TemplateExpressionParsingTests.HASH_DELIMITED_PARSER_CONTEXT;
    ParserContext dollars = TemplateExpressionParsingTests.DEFAULT_TEMPLATE_PARSER_CONTEXT;
    checkTemplateParsing("abc${'def'} ghi", "abcdef ghi");
    checkTemplateParsingError("abc${ {}( 'abc'", "Missing closing ')' for '(' at position 8");
    checkTemplateParsingError("abc${ {}[ 'abc'", "Missing closing ']' for '[' at position 8");
    checkTemplateParsingError("abc${ {}{ 'abc'", "Missing closing '}' for '{' at position 8");
    checkTemplateParsingError("abc${ ( 'abc' }", "Found closing '}' at position 14 but most recent opening is '(' at position 6");
    checkTemplateParsingError("abc${ '... }", "Found non terminating string literal starting at position 6");
    checkTemplateParsingError("abc${ \"... }", "Found non terminating string literal starting at position 6");
    checkTemplateParsingError("abc${ ) }", "Found closing ')' at position 6 without an opening '('");
    checkTemplateParsingError("abc${ ] }", "Found closing ']' at position 6 without an opening '['");
    checkTemplateParsingError("abc${ } }", "No expression defined within delimiter '${}' at character 3");
    checkTemplateParsingError("abc$[ } ]", DOLLARSQUARE_TEMPLATE_PARSER_CONTEXT, "Found closing '}' at position 6 without an opening '{'");
    checkTemplateParsing("abc ${\"def''g}hi\"} jkl", "abc def'g}hi jkl");
    checkTemplateParsing("abc ${'def''g}hi'} jkl", "abc def'g}hi jkl");
    checkTemplateParsing("}", "}");
    checkTemplateParsing("${'hello'} world", "hello world");
    checkTemplateParsing("Hello ${'}'}]", "Hello }]");
    checkTemplateParsing("Hello ${'}'}", "Hello }");
    checkTemplateParsingError("Hello ${ ( ", "No ending suffix '}' for expression starting at character 6: ${ ( ");
    checkTemplateParsingError("Hello ${ ( }", "Found closing '}' at position 11 but most recent opening is '(' at position 9");
    checkTemplateParsing("#{'Unable to render embedded object: File ({#this == 2}'}", hashes, "Unable to render embedded object: File ({#this == 2}");
    checkTemplateParsing("This is the last odd number in the list: ${listOfNumbersUpToTen.$[#this%2==1]}", dollars, "This is the last odd number in the list: 9");
    checkTemplateParsing("Hello ${'here is a curly bracket }'}", dollars, "Hello here is a curly bracket }");
    checkTemplateParsing("He${'${'}llo ${'here is a curly bracket }'}}", dollars, "He${llo here is a curly bracket }}");
    checkTemplateParsing("Hello ${'()()()}{}{}{][]{}{][}[][][}{()()'} World", dollars, "Hello ()()()}{}{}{][]{}{][}[][][}{()() World");
    checkTemplateParsing("Hello ${'inner literal that''s got {[(])]}an escaped quote in it'} World", "Hello inner literal that's got {[(])]}an escaped quote in it World");
    checkTemplateParsingError("Hello ${", "No ending suffix '}' for expression starting at character 6: ${");
}
Also used : ParserContext(org.springframework.expression.ParserContext) Test(org.junit.jupiter.api.Test)

Aggregations

ParserContext (org.springframework.expression.ParserContext)3 Test (org.junit.jupiter.api.Test)2 TemplateParserContext (org.springframework.expression.common.TemplateParserContext)2 Expression (org.springframework.expression.Expression)1