Class DefaultExpressionEvaluator
- All Implemented Interfaces:
ExpressionEvaluator
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static org.springframework.expression.ExpressionParserprotected static final PatternFields inherited from interface org.kuali.rice.krad.uif.view.ExpressionEvaluator
EMBEDDED_PROPERTY_NAME_ADD_INDICATOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCustomFunctions(org.springframework.expression.spel.support.StandardEvaluationContext context) Registers custom functions for el expressions with the given contextbooleancontainsElPlaceholder(String value) Indicates whether or not the given string contains the el placeholder (begin and end delimiters)protected voidevaluateCurrentStack(String stack, List<String> controlNames) Used internally by parseExpression to evaluate if the current stack is a property name (ie, will be a control on the form)evaluateExpression(Map<String, Object> evaluationParameters, String expressionStr) Evaluates the given el expression against the content object and parameters, and returns the result of the evaluationvoidevaluateExpressionsOnConfigurable(View view, UifDictionaryBean expressionConfigurable, Map<String, Object> evaluationParameters) Evaluates any el expressions that are found as a string property value for the objectevaluateExpressionTemplate(Map<String, Object> evaluationParameters, String expressionTemplate) Evaluates the given expression template string against the context object and map of parametersvoidevaluatePropertyExpression(View view, Map<String, Object> evaluationParameters, UifDictionaryBean expressionConfigurable, String propertyName, boolean removeExpression) Evaluates the configured expression for the given property name (if not exists) on the given configurableprotected voidevaluatePropertyExpressions(View view, UifDictionaryBean expressionConfigurable, Map<String, Object> evaluationParameters) Iterates through the keys of the property expressions map and invokesevaluatePropertyExpression(org.kuali.rice.krad.uif.view.View, java.util.Map, org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean, String, boolean)protected voidevaluatePropertyReplacers(View view, UifDictionaryBean expressionConfigurable, Map<String, Object> evaluationParameters) Iterates through any configuredPropertyReplacerinstances for the component and evaluates the given condition.Find the control names (ie, propertyNames) used in the passed in expressionprotected static StringgetLinePathPrefixValue(Component component) Determines the value for theUifConstants.LINE_PATH_BIND_ADJUST_PREFIXbinding prefix based on collection group found in the component contextvoidinitializeEvaluationContext(Object contextObject) Initializes the expression context for the given expression context objectTakes in an expression and a list to be filled in with names(property names) of controls found in the expression.voidpopulatePropertyExpressionsFromGraph(UifDictionaryBean expressionConfigurable, boolean buildRefreshGraphs) Pulls expressions within the expressionConfigurable's expression graph and moves them to the property expressions map for the expressionConfigurable or a nested expressionConfigurable (for the case of nested expression property names)replaceBindingPrefixes(View view, Object object, String expression) Adjusts the property expressions for a given objectprotected org.springframework.expression.ExpressionretrieveCachedExpression(String expressionTemplate) Attempts to retrieve theExpressioninstance for the given expression template, if not found one is created and added to the cache
-
Field Details
-
SERVER_EVALUATION_PATTERN
-
parser
protected static org.springframework.expression.ExpressionParser parser
-
-
Constructor Details
-
DefaultExpressionEvaluator
public DefaultExpressionEvaluator()Default constructor
-
-
Method Details
-
populatePropertyExpressionsFromGraph
public void populatePropertyExpressionsFromGraph(UifDictionaryBean expressionConfigurable, boolean buildRefreshGraphs) Pulls expressions within the expressionConfigurable's expression graph and moves them to the property expressions map for the expressionConfigurable or a nested expressionConfigurable (for the case of nested expression property names)Expressions that are configured on properties and pulled out by the
and put in theinvalid reference
org.kuali.rice.krad.uif.util.UifBeanFactoryPostProcessorUifDictionaryBean.getExpressionGraph()for the bean that is at root (non nested) level. Before evaluating the expressions, they need to be moved to theUifDictionaryBean.getPropertyExpressions()map for the expressionConfigurable that property is on.- Specified by:
populatePropertyExpressionsFromGraphin interfaceExpressionEvaluator- Parameters:
expressionConfigurable- expressionConfigurable instance to process expressions forbuildRefreshGraphs- indicates whether the expression graphs for component refresh should be built
-
parseExpression
Takes in an expression and a list to be filled in with names(property names) of controls found in the expression.This method returns a js expression which can be executed on the client to determine if the original exp was satisfied before interacting with the server - ie, this js expression is equivalent to the one passed in.
There are limitations on the Spring expression language that can be used as this method. It is only used to parse expressions which are valid case statements for determining if some action/processing should be performed. ONLY Properties, comparison operators, booleans, strings, matches expression, and boolean logic are supported. Server constants and calls will be evaluated early. The isValueEmpty, listContains, and emptyList custom KRAD functions, however, will be converted to a js equivalent function. Properties must be a valid property on the form, and should have a visible control within the view.
Example valid exp: "account.name == 'Account Name'"
- Specified by:
parseExpressionin interfaceExpressionEvaluator- Parameters:
exp- the expression to convert to a js conditioncontrolNames- the list to populate with control names found in the expression (these may later be used to add js change handlers)- Returns:
- the converted expression into an equivalent js condition
-
findControlNamesInExpression
Find the control names (ie, propertyNames) used in the passed in expression- Specified by:
findControlNamesInExpressionin interfaceExpressionEvaluator- Parameters:
exp- the expression to search- Returns:
- the list of control names found (ie, propertyNames)
-
evaluateCurrentStack
Used internally by parseExpression to evaluate if the current stack is a property name (ie, will be a control on the form) -
initializeEvaluationContext
Initializes the expression context for the given expression context objectThe object given here will form the default context for expression terms (terms without any variable prefix)
- Specified by:
initializeEvaluationContextin interfaceExpressionEvaluator- Parameters:
contextObject- instance of an Object
-
evaluateExpressionsOnConfigurable
public void evaluateExpressionsOnConfigurable(View view, UifDictionaryBean expressionConfigurable, Map<String, Object> evaluationParameters) Evaluates any el expressions that are found as a string property value for the objectUsing reflection the properties for the object are retrieved and if of
Stringtype the corresponding value is retrieved. If the value is not empty and contains the el placeholder seeExpressionEvaluator.containsElPlaceholder(String)then the expression is evaluated using the given context object and parameters. The evaluated string is then set as the new property value, or in the case of a template (expression contained within a literal string), the expression part is replaced in the property value.In addition to evaluating any property expressions, any configured
PropertyReplacerfor the object are also evaluated and if a match occurs those property replacements are made- Specified by:
evaluateExpressionsOnConfigurablein interfaceExpressionEvaluator- Parameters:
view- view instance being renderedexpressionConfigurable- object whose properties should be checked for expressions and evaluatedevaluationParameters- map of parameters that may appear in expressions, the map key gives the parameter name that may appear in the expression, and the map value is the object that expression should evaluate against when that name is found
-
evaluateExpression
Evaluates the given el expression against the content object and parameters, and returns the result of the evaluationThe given expression string is assumed to be one el expression and should not contain the el placeholders. The returned result depends on the evaluation and what type is returns, for instance a boolean will be return for a boolean expression, or a string for string expression
- Specified by:
evaluateExpressionin interfaceExpressionEvaluator- Parameters:
evaluationParameters- map of parameters that may appear in expressions, the map key gives the parameter name that may appear in the expression, and the map value is the object that expression should evaluate against when that name is foundexpressionStr- el expression to evaluate- Returns:
- Object result of the expression evaluation
-
evaluateExpressionTemplate
public String evaluateExpressionTemplate(Map<String, Object> evaluationParameters, String expressionTemplate) Evaluates the given expression template string against the context object and map of parametersIf the template string contains one or more el placeholders (see
ExpressionEvaluator.containsElPlaceholder(String)), the expression contained within the placeholder will be evaluated and the corresponding value will be substituted back into the property value where the placeholder occurred. If no placeholders are found, the string will be returned unchanged- Specified by:
evaluateExpressionTemplatein interfaceExpressionEvaluator- Parameters:
evaluationParameters- map of parameters that may appear in expressions, the map key gives the parameter name that may appear in the expression, and the map value is the object that expression should evaluate against when that name is foundexpressionTemplate- string that should be evaluated for el expressions- Returns:
- String formed by replacing any el expressions in the original expression template with their corresponding evaluation results
-
evaluatePropertyExpression
public void evaluatePropertyExpression(View view, Map<String, Object> evaluationParameters, UifDictionaryBean expressionConfigurable, String propertyName, boolean removeExpression) Evaluates the configured expression for the given property name (if not exists) on the given configurable- Specified by:
evaluatePropertyExpressionin interfaceExpressionEvaluator- Parameters:
view- view instance the configurable is associated with, used to adjust binding prefixesevaluationParameters- map that will be exposed as EL parametersexpressionConfigurable- configurable object to pull and evaluate the expression onpropertyName- name of the property whose expression should be evaluatedremoveExpression- boolean that indicates whether the expression should be removed after evaluation
-
containsElPlaceholder
Indicates whether or not the given string contains the el placeholder (begin and end delimiters)- Specified by:
containsElPlaceholderin interfaceExpressionEvaluator- Parameters:
value- String to check for contained placeholders- Returns:
- boolean true if the string contains one or more placeholders, false if it contains none
- See Also:
-
replaceBindingPrefixes
Adjusts the property expressions for a given objectThe
UifConstants.NO_BIND_ADJUST_PREFIXprefix will be removed as this is a placeholder indicating that the property is directly on the form. TheUifConstants.FIELD_PATH_BIND_ADJUST_PREFIXprefix will be replaced by the object's field path - this is only applicable to DataFields. TheUifConstants.DEFAULT_PATH_BIND_ADJUST_PREFIXprefix will be replaced by the view's default path if it is set.- Specified by:
replaceBindingPrefixesin interfaceExpressionEvaluator- Parameters:
view- the parent view of the objectobject- Object to adjust property expressions onexpression- The expression to adjust- Returns:
- the adjusted expression String
-
retrieveCachedExpression
protected org.springframework.expression.Expression retrieveCachedExpression(String expressionTemplate) Attempts to retrieve theExpressioninstance for the given expression template, if not found one is created and added to the cache- Parameters:
expressionTemplate- template string for the expression- Returns:
- Expression instance
-
addCustomFunctions
protected void addCustomFunctions(org.springframework.expression.spel.support.StandardEvaluationContext context) Registers custom functions for el expressions with the given context- Parameters:
context- - context instance to register functions to
-
evaluatePropertyReplacers
protected void evaluatePropertyReplacers(View view, UifDictionaryBean expressionConfigurable, Map<String, Object> evaluationParameters) Iterates through any configuredPropertyReplacerinstances for the component and evaluates the given condition. If the condition is met, the replacement value is set on the corresponding property- Parameters:
view- - view instance being renderedexpressionConfigurable- - expressionConfigurable instance with property replacers list, should be either a component or layout managerevaluationParameters- - parameters for el evaluation
-
evaluatePropertyExpressions
protected void evaluatePropertyExpressions(View view, UifDictionaryBean expressionConfigurable, Map<String, Object> evaluationParameters) Iterates through the keys of the property expressions map and invokesevaluatePropertyExpression(org.kuali.rice.krad.uif.view.View, java.util.Map, org.kuali.rice.krad.datadictionary.uif.UifDictionaryBean, String, boolean)If the expression is an el template (part static text and part expression), only the expression part will be replaced with the result. More than one expressions may be contained within the template
- Parameters:
view- - view instance that is being renderedexpressionConfigurable- - object instance to evaluate expressions forevaluationParameters- - map of additional parameters that may be used within the expressions
-
getLinePathPrefixValue
Determines the value for theUifConstants.LINE_PATH_BIND_ADJUST_PREFIXbinding prefix based on collection group found in the component context- Parameters:
component- - component instance for which the prefix is configured on- Returns:
- String line binding path or empty string if path not found
-