Top Description Inners Constructors Methods
org.springframework.expression.common

public abstract Class TemplateAwareExpressionParser

extends Object
implements ExpressionParser
Class Inheritance
All Implemented Interfaces
org.springframework.expression.ExpressionParser
Known Direct Subclasses
org.springframework.expression.spel.standard.InternalSpelExpressionParser, org.springframework.expression.spel.standard.SpelExpressionParser
Imports
java.util.ArrayDeque, .ArrayList, .Deque, .List, org.springframework.expression.Expression, .ExpressionParser, .ParseException, .ParserContext, org.springframework.lang.Nullable, org.springframework.util.Assert

An expression parser that understands templates. It can be subclassed by expression parsers that do not offer first class support for templating.
Authors
Keith Donald, Juergen Hoeller, Andy Clement, Sam Brannen
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
TemplateAwareExpressionParser.Bracket

This captures a type of bracket and the position in which it occurs in the expression.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected abstract Expression

Returns:

an evaluator for the parsed expression
doParseExpression
(String
the raw expression string to parse
expressionString
,
ParserContext
a context for influencing this expression parsing routine (optional)
context
)

Actually parse the expression string and return an Expression object.

private boolean
isSuffixHere(String
the expression string which may contain the suffix
expressionString
,
int
the start position at which to check for the suffix
pos
,
String
the suffix string
suffix
)

Return true if the specified suffix can be found at the supplied position in the supplied expression string.

public Expression
parseExpression(String
the raw expression string to parse
expressionString
)

Implements org.springframework.expression.ExpressionParser.parseExpression.

Parse the expression string and return an Expression object you can use for repeated evaluation.
public Expression
parseExpression(String
the raw expression string to parse
expressionString
,
ParserContext
a context for influencing this expression parsing routine (optional)
context
)

Implements org.springframework.expression.ExpressionParser.parseExpression.

Parse the expression string and return an Expression object you can use for repeated evaluation.
private Expression[]

Returns:

the parsed expressions
parseExpressions
(String
the expression string
expressionString
,
ParserContext context)

Helper that parses given expression string using the configured parser.

private Expression
parseTemplate(String expressionString, ParserContext context)

private int

Returns:

the position of the correct matching nextSuffix or -1 if none can be found
skipToCorrectEndSuffix
(String
the suffix
suffix
,
String
the expression string
expressionString
,
int
the most recently found prefix location for which the matching end suffix is being sought
afterPrefixIndex
)

Copes with nesting, for example '${...${...}}' where the correct end for the first ${ is the final }.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TemplateAwareExpressionParserback to summary
public TemplateAwareExpressionParser()

Method Detail

doParseExpressionback to summary
protected abstract Expression doParseExpression(String expressionString, ParserContext context) throws ParseException

Actually parse the expression string and return an Expression object.

Parameters
expressionString:String

the raw expression string to parse

context:ParserContext

a context for influencing this expression parsing routine (optional)

Returns:Expression

an evaluator for the parsed expression

Exceptions
ParseException:
an exception occurred during parsing
isSuffixHereback to summary
private boolean isSuffixHere(String expressionString, int pos, String suffix)

Return true if the specified suffix can be found at the supplied position in the supplied expression string.

Parameters
expressionString:String

the expression string which may contain the suffix

pos:int

the start position at which to check for the suffix

suffix:String

the suffix string

parseExpressionback to summary
public Expression parseExpression(String expressionString) throws ParseException

Implements org.springframework.expression.ExpressionParser.parseExpression.

Doc from org.springframework.expression.ExpressionParser.parseExpression.

Parse the expression string and return an Expression object you can use for repeated evaluation.

Some examples:

    3 + 4
    name.firstName
Parameters
expressionString:String

the raw expression string to parse

Returns:Expression

an evaluator for the parsed expression

Annotations
@Override
Exceptions
ParseException:
an exception occurred during parsing
parseExpressionback to summary
public Expression parseExpression(String expressionString, ParserContext context) throws ParseException

Implements org.springframework.expression.ExpressionParser.parseExpression.

Doc from org.springframework.expression.ExpressionParser.parseExpression.

Parse the expression string and return an Expression object you can use for repeated evaluation.

Some examples:

    3 + 4
    name.firstName
Parameters
expressionString:String

the raw expression string to parse

context:ParserContext

a context for influencing this expression parsing routine (optional)

Returns:Expression

an evaluator for the parsed expression

Annotations
@Override
Exceptions
ParseException:
an exception occurred during parsing
parseExpressionsback to summary
private Expression[] parseExpressions(String expressionString, ParserContext context) throws ParseException

Helper that parses given expression string using the configured parser. The expression string can contain any number of expressions all contained in "${...}" markers. For instance: "foo${expr0}bar${expr1}". The static pieces of text will also be returned as Expressions that just return that static piece of text. As a result, evaluating all returned expressions and concatenating the results produces the complete evaluated string. Unwrapping is only done of the outermost delimiters found, so the string 'hello ${foo${abc}}' would break into the pieces 'hello ' and 'foo${abc}'. This means that expression languages that use ${..} as part of their functionality are supported without any problem. The parsing is aware of the structure of an embedded expression. It assumes that parentheses '(', square brackets '[', and curly brackets '}' must be in pairs within the expression unless they are within a string literal and the string literal starts and terminates with a single quote '.

Parameters
expressionString:String

the expression string

Returns:Expression[]

the parsed expressions

Exceptions
ParseException:
when the expressions cannot be parsed
parseTemplateback to summary
private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException
skipToCorrectEndSuffixback to summary
private int skipToCorrectEndSuffix(String suffix, String expressionString, int afterPrefixIndex) throws ParseException

Copes with nesting, for example '${...${...}}' where the correct end for the first ${ is the final }.

Parameters
suffix:String

the suffix

expressionString:String

the expression string

afterPrefixIndex:int

the most recently found prefix location for which the matching end suffix is being sought

Returns:int

the position of the correct matching nextSuffix or -1 if none can be found

org.springframework.expression.common back to summary

private final Record TemplateAwareExpressionParser.Bracket

extends Record
Class Inheritance
Record Components
bracket:char 
pos:int 

This captures a type of bracket and the position in which it occurs in the expression. The positional information is used if an error has to be reported because the related end bracket cannot be found. Bracket is used to describe square brackets [], round brackets (), and curly brackets {}.

Field Summary

Modifier and TypeField and Description
private final char
bracket

Record Component accessed by bracket().

private final int
pos

Record Component accessed by pos().

Constructor Summary

AccessConstructor and Description
private
Bracket(char bracket, int pos)

Method Summary

Modifier and TypeMethod and Description
public char
bracket()

Record Component getter of bracket.

pack-priv boolean
compatibleWithCloseBracket(char closeBracket)

public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.
public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.
public int
pos()

Record Component getter of pos.

pack-priv static char
theCloseBracketFor(char openBracket)

pack-priv static char
theOpenBracketFor(char closeBracket)

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

bracketback to summary
private final char bracket

Record Component accessed by bracket().

posback to summary
private final int pos

Record Component accessed by pos().

Constructor Detail

Bracketback to summary
private Bracket(char bracket, int pos)

Method Detail

bracketback to summary
public char bracket()

Record Component getter of bracket.

compatibleWithCloseBracketback to summary
pack-priv boolean compatibleWithCloseBracket(char closeBracket)
equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

posback to summary
public int pos()

Record Component getter of pos.

theCloseBracketForback to summary
pack-priv static char theCloseBracketFor(char openBracket)
theOpenBracketForback to summary
pack-priv static char theOpenBracketFor(char closeBracket)
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.