com.opensymphony.xwork2.util

## Class TextParseUtil

- java.lang.Object
- - com.opensymphony.xwork2.util.TextParseUtil

-     public class TextParseUtil
      extends Object

  Utility class for text parsing.
  Author:
    Jason Carreira, Rainer Hermanns, tm_jee

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `TextParseUtil.ParsedValueEvaluator` A parsed value evaluator for `TextParseUtil`.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TextParseUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Set<String>` | `commaDelimitedStringToSet(String s)` Returns 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 ${...} in `expression` to the value returned by a call to `ValueStack.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 %{...} in `expression` to the value returned by a call to `ValueStack.findValue(java.lang.String)`.
    `static String` | `translateVariables(String expression, ValueStack stack, TextParseUtil.ParsedValueEvaluator evaluator)` Function similarly as `translateVariables(char, String, ValueStack)` except for the introduction of an additional `evaluator` that allows the parsed value to be evaluated by the `evaluator`.
    `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)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TextParseUtil

          public TextParseUtil()

  - ### Method Detail

    - #### translateVariables

          public static String translateVariables(String expression,
                                  ValueStack stack)

      Converts all instances of ${...}, and %{...} in `expression` to the value returned by a call to `ValueStack.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 translated
        `stack` - value stack
      Returns:
        the parsed expression

    - #### translateVariables

          public static String translateVariables(String expression,
                                  ValueStack stack,
                                  TextParseUtil.ParsedValueEvaluator evaluator)

      Function similarly as `translateVariables(char, String, ValueStack)` except for the introduction of an additional `evaluator` that allows the parsed value to be evaluated by the `evaluator`. The `evaluator` could be null, if it is it will just be skipped as if it is just calling `translateVariables(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 string
        `stack` - value stack
        `evaluator` - The parsed Value evaluator (could be null).
      Returns:
        the parsed (and possibly evaluated) variable String.

    - #### translateVariables

          public static String translateVariables(char open,
                                  String expression,
                                  ValueStack stack)

      Converts all instances of ${...} in `expression` to the value returned by a call to `ValueStack.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 character
        `expression` - expression string
        `stack` - 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 character
        `expression` - expression string
        `stack` - value stack
        `asType` - 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 character
        `expression` - expression string
        `stack` - value stack
        `asType` - as class type
        `evaluator` - 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 array
        `expression` - expression string
        `stack` - value stack
        `asType` - as class type
        `evaluator` - 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 character
        `expression` - expression string
        `stack` - value stack
        `asType` - as class type
        `evaluator` - value evaluator
        `maxLoopCount` - 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 array
        `expression` - expression string
        `stack` - value stack
        `asType` - as class type
        `evaluator` - value evaluator
        `maxLoopCount` - 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 string
        `stack` - value stack
        `excludeEmptyElements` - Whether empty elements shall be excluded.
        `evaluator` - value evaluator
      Returns:
        converted objects
      See Also:
        `translateVariablesCollection(char[], String, ValueStack, boolean, ParsedValueEvaluator, int)`

    - #### 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 array
        `expression` - expression string
        `stack` - value stack
        `evaluator` - value evaluator
        `excludeEmptyElements` - Whether empty elements shall be excluded.
        `maxLoopCount` - max loop count
      Returns:
        converted objects

    - #### commaDelimitedStringToSet

          public static Set<String> commaDelimitedStringToSet(String s)

      Returns a set from comma delimited Strings.
      Parameters:
        `s` - The String to parse.
      Returns:
        A set from comma delimited Strings.

Copyright © 2000–2020 Apache Software Foundation. All rights reserved.