Package org.apache.struts2.util
Class TextParseUtil
java.lang.Object
org.apache.struts2.util.TextParseUtil
Utility class for text parsing.
- Author:
- Jason Carreira, Rainer Hermanns, tm_jee
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns a set from comma delimited Strings.static Object
translateVariables
(char[] openChars, String expression, ValueStack stack, Class asType, TextParseUtil.ParsedValueEvaluator evaluator) Converted object from variable translation.static Object
translateVariables
(char[] openChars, String expression, ValueStack stack, Class asType, TextParseUtil.ParsedValueEvaluator evaluator, int maxLoopCount) Converted object from variable translation.static String
translateVariables
(char open, String expression, ValueStack stack) Converts all instances of ${...} inexpression
to the value returned by a call toValueStack.findValue(java.lang.String)
.static Object
translateVariables
(char open, String expression, ValueStack stack, Class asType) Converted object from variable translation.static Object
translateVariables
(char open, String expression, ValueStack stack, Class asType, TextParseUtil.ParsedValueEvaluator evaluator) Converted object from variable translation.static Object
translateVariables
(char open, String expression, ValueStack stack, Class asType, TextParseUtil.ParsedValueEvaluator evaluator, int maxLoopCount) Converted object from variable translation.static String
translateVariables
(String expression, ValueStack stack) Converts all instances of ${...}, and %{...} inexpression
to the value returned by a call toValueStack.findValue(java.lang.String)
.static String
translateVariables
(String expression, ValueStack stack, TextParseUtil.ParsedValueEvaluator evaluator) Function similarly astranslateVariables(char, String, ValueStack)
except for the introduction of an additionalevaluator
that allows the parsed value to be evaluated by theevaluator
.static Collection<String>
translateVariablesCollection
(char[] openChars, String expression, ValueStack stack, boolean excludeEmptyElements, TextParseUtil.ParsedValueEvaluator evaluator, int maxLoopCount) Resolves given expression on given ValueStack.static Collection<String>
translateVariablesCollection
(String expression, ValueStack stack, boolean excludeEmptyElements, TextParseUtil.ParsedValueEvaluator evaluator)
-
Constructor Details
-
TextParseUtil
public TextParseUtil()
-
-
Method Details
-
translateVariables
Converts all instances of ${...}, and %{...} inexpression
to the value returned by a call toValueStack.findValue(java.lang.String)
. If an item cannot be found on the stack (null is returned), then the entire variable ${...} is not displayed, just as if the item was on the stack but returned an empty string.- Parameters:
expression
- an expression that hasn't yet been translatedstack
- value stack- Returns:
- the parsed expression
-
translateVariables
public static String translateVariables(String expression, ValueStack stack, TextParseUtil.ParsedValueEvaluator evaluator) Function similarly astranslateVariables(char, String, ValueStack)
except for the introduction of an additionalevaluator
that allows the parsed value to be evaluated by theevaluator
. Theevaluator
could be null, if it is it will just be skipped as if it is just callingtranslateVariables(char, String, ValueStack)
.
A typical use-case would be when we need to URL Encode the parsed value. To do so we could just supply a URLEncodingEvaluator for example.- Parameters:
expression
- expression stringstack
- value stackevaluator
- The parsed Value evaluator (could be null).- Returns:
- the parsed (and possibly evaluated) variable String.
-
translateVariables
Converts all instances of ${...} inexpression
to the value returned by a call toValueStack.findValue(java.lang.String)
. If an item cannot be found on the stack (null is returned), then the entire variable ${...} is not displayed, just as if the item was on the stack but returned an empty string.- Parameters:
open
- open characterexpression
- expression stringstack
- value stack- Returns:
- Translated variable String
-
translateVariables
public static Object translateVariables(char open, String expression, ValueStack stack, Class asType) Converted object from variable translation.- Parameters:
open
- open characterexpression
- expression stringstack
- value stackasType
- as class type- Returns:
- Converted object from variable translation.
-
translateVariables
public static Object translateVariables(char open, String expression, ValueStack stack, Class asType, TextParseUtil.ParsedValueEvaluator evaluator) Converted object from variable translation.- Parameters:
open
- open characterexpression
- expression stringstack
- value stackasType
- as class typeevaluator
- value evaluator- Returns:
- Converted object from variable translation.
-
translateVariables
public static Object translateVariables(char[] openChars, String expression, ValueStack stack, Class asType, TextParseUtil.ParsedValueEvaluator evaluator) Converted object from variable translation.- Parameters:
openChars
- open character arrayexpression
- expression stringstack
- value stackasType
- as class typeevaluator
- value evaluator- Returns:
- Converted object from variable translation.
-
translateVariables
public static Object translateVariables(char open, String expression, ValueStack stack, Class asType, TextParseUtil.ParsedValueEvaluator evaluator, int maxLoopCount) Converted object from variable translation.- Parameters:
open
- open characterexpression
- expression stringstack
- value stackasType
- as class typeevaluator
- value evaluatormaxLoopCount
- max loop count- Returns:
- Converted object from variable translation.
-
translateVariables
public static Object translateVariables(char[] openChars, String expression, ValueStack stack, Class asType, TextParseUtil.ParsedValueEvaluator evaluator, int maxLoopCount) Converted object from variable translation.- Parameters:
openChars
- open character arrayexpression
- expression stringstack
- value stackasType
- as class typeevaluator
- value evaluatormaxLoopCount
- max loop count- Returns:
- Converted object from variable translation.
-
translateVariablesCollection
public static Collection<String> translateVariablesCollection(String expression, ValueStack stack, boolean excludeEmptyElements, TextParseUtil.ParsedValueEvaluator evaluator) - Parameters:
expression
- expression stringstack
- value stackexcludeEmptyElements
- Whether empty elements shall be excluded.evaluator
- value evaluator- Returns:
- converted objects
- See Also:
-
translateVariablesCollection
public static Collection<String> translateVariablesCollection(char[] openChars, String expression, ValueStack stack, boolean excludeEmptyElements, TextParseUtil.ParsedValueEvaluator evaluator, int maxLoopCount) Resolves given expression on given ValueStack. If found element is a collection each element will be converted to String. If just a single object is found it is converted to String and wrapped in a collection.- Parameters:
openChars
- open character arrayexpression
- expression stringstack
- value stackevaluator
- value evaluatorexcludeEmptyElements
- Whether empty elements shall be excluded.maxLoopCount
- max loop count- Returns:
- converted objects
-
commaDelimitedStringToSet
Returns a set from comma delimited Strings.- Parameters:
s
- The String to parse.- Returns:
- A set from comma delimited Strings.
-