Interface IWorkflowPlaceholderHandler


  • public interface IWorkflowPlaceholderHandler
    Interface for the workflow placeholder handler that lets you replace placeholders in strings easily. Usually you only want to use replaceStringFields or possibly also replaceAll -- the other methods are provided for advanced usage.
    Since:
    7.0.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • replaceAll

        String replaceAll​(String text,
                          IPlaceholderEscaper syntax)
        Replaces all placeholders in the given string, regardless of their type.
        Parameters:
        text - Text that may contain placeholders.
        syntax - Syntax indicating how placeholders are inserted into the text body.
        Returns:
        The given text, with all placeholders replaced.
      • replaceAll

        String replaceAll​(String text,
                          IPlaceholderEscaper syntax,
                          IContextReplacerParams contextParams)
        Replaces all placeholders in the given string, regardless of their type.
        Parameters:
        text - Text that may contain placeholders.
        contextParams - A map with context values to use for the replacement of context placeholders.
        syntax - Syntax indicating how placeholders are inserted into the text body.
        Returns:
        The given text, with all placeholders replaced.
      • replaceContext

        String replaceContext​(String text,
                              IPlaceholderEscaper syntax,
                              IContextReplacerParams contextParams)
        Replaces all context placeholders in the given string.
        Parameters:
        text - Text that may contain context placeholders.
        contextParams - A map with context values to use for the replacement.
        syntax - Syntax indicating how placeholders are inserted into the text body.
        Returns:
        The given text, with all context placeholders replaced.
      • replaceForm

        String replaceForm​(String text,
                           IPlaceholderEscaper syntax)
        Replaces all form placeholders in the given string.
        Parameters:
        text - Text that may contain form placeholders.
        syntax - Syntax indicating how placeholders are inserted into the text body.
        Returns:
        The given text, with all form placeholders replaced.
      • replaceI18n

        String replaceI18n​(String text,
                           IPlaceholderEscaper syntax)
        Replaces all i18n placeholders in the given string.
        Parameters:
        text - Text that may contain i18n placeholders.
        syntax - Syntax indicating how placeholders are inserted into the text body.
        Returns:
        The given text, with all i18n placeholders replaced.
      • replaceSession

        String replaceSession​(String text,
                              IPlaceholderEscaper syntax)
        Replaces all session placeholders in the given string.
        Parameters:
        text - Text that may contain session placeholders.
        syntax - Syntax indicating how placeholders are inserted into the text body.
        Returns:
        The given text, with all session placeholders replaced.
      • replaceStringFields

        void replaceStringFields​(Object model)
                          throws RuntimeException
        Replaces all placeholders in the fields of given model, provided they are annotated with Placeholder.

        Specifically, this method iterates over all non-static, non-final, non-transient instance fields of the runtime class of the given model, including all its super classes. Access control is ignored, i.e. all public, protected, package-private, and private fields are considered. Then:

        • For each field whose declared type is exactly String and for which a Placeholder annotation is present: reads the value of that field, replaces all placeholders in the field value as configured by the Placeholder annotation instance on the field, and writes back the replaced value to that field.
        • For each field whose declared type is assignable to List<String> and for which a Placeholder annotation is present, proceed as outlined above for each element in the list.
        • For each field whose declared type is not assignable to List<String>, reads the list value of that field and applies this method to each item in the list.

        The presence of a Placeholder annotation is resolved as follows:

        So for example, when you place Placeholder on a field of type UserCredentials, all string fields in the UserCredentials are replaced.

        Placeholder of type context are not replaced. If you wish to do that, use the two-arg replaceStringFields method.

        Note: This method mutates the fields of the passed model instance. This was an intentional decision in accordance with the single responsibility principle to keep cloning logic out of scope for this method. Create a clone and pass it to this method to avoid modifying the original value.

        Parameters:
        model - Model with data that may contain placeholders. This method is a no-op when this is null.
        Throws:
        RuntimeException - When reflective access to a field fails (usually due to a SecurityManager), or when a customSyntax provider could not be instantiated.
        See Also:
        Placeholder
      • replaceStringFields

        void replaceStringFields​(Object model,
                                 IContextReplacerParams contextParams)
                          throws RuntimeException
        Replaces all placeholders in the fields of given model, provided they are annotated with Placeholder.

        Specifically, this method iterates over all non-static, non-final, non-transient instance fields of the runtime class of the given model, including all its super classes. Access control is ignored, i.e. all public, protected, package-private, and private fields are considered. Then:

        • For each field whose declared type is exactly String and or which a Placeholder annotation is present: reads the value of that field, replaces all placeholders in the field value as configured by the Placeholder annotation instance on the field, and writes back the replaced value to that field.
        • For each field whose declared type is assignable to List<String> and for which a Placeholder annotation is present, proceed as outlined above for each element in the list.
        • For each field whose declared type is not assignable to List<String>, read the list value of that field and apply this method to each item in the list.

        The presence of a Placeholder annotation is resolved as follows:

        So for example, when you place Placeholder on a field of type UserCredentials, all string fields in the UserCredentials are replaced.

        Note: This method mutates the fields of the passed model instance. This was an intentional decision in accordance with the single responsibility principle to keep cloning logic out of scope for this method. Create a clone and pass it to this method to avoid modifying the original value.

        Parameters:
        model - Model with data that may contain placeholders. This method is a no-op when this is null.
        contextParams - A map with context values to use for the replacement of context placeholders. If null, no context parameters are replaced.
        Throws:
        RuntimeException - When reflective access to a field fails (usually due to a SecurityManager), or when a customSyntax provider could not be instantiated.
        See Also:
        Placeholder
      • replaceSystem

        String replaceSystem​(String text,
                             IPlaceholderEscaper syntax)
        Replaces all system placeholders in the given string.
        Parameters:
        text - Text that may contain system placeholders.
        syntax - Syntax indicating how placeholders are inserted into the text body.
        Returns:
        The given text, with all system placeholders replaced.
      • replaceTemplate

        String replaceTemplate​(String text,
                               IPlaceholderEscaper syntax)
        Replaces all template placeholders in the given string.
        Parameters:
        text - Text that may contain template placeholders.
        syntax - Syntax indicating how placeholders are inserted into the text body.
        Returns:
        The given text, with all template placeholders replaced.