Interface IWorkflowPlaceholderHandler
-
public interface IWorkflowPlaceholderHandler
Interface for the workflow placeholder handler that lets you replace placeholders in strings easily. Usually you only want to usereplaceStringFields
or possibly alsoreplaceAll
-- the other methods are provided for advanced usage.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description DefaultReplacerParameters
createReplacerParams(IContextReplacerParams contextParams)
Creates aDefaultReplacerParameters
with the given replacer context.String
replaceAll(String text, IPlaceholderEscaper syntax)
Replaces all placeholders in the given string, regardless of their type.String
replaceAll(String text, IPlaceholderEscaper syntax, IContextReplacerParams contextParams)
Replaces all placeholders in the given string, regardless of their type.String
replaceContext(String text, IPlaceholderEscaper syntax, IContextReplacerParams contextParams)
Replaces all context placeholders in the given string.String
replaceForm(String text, IPlaceholderEscaper syntax)
Replaces all form placeholders in the given string.String
replaceI18n(String text, IPlaceholderEscaper syntax)
Replaces all i18n placeholders in the given string.String
replaceSession(String text, IPlaceholderEscaper syntax)
Replaces all session placeholders in the given string.void
replaceStringFields(Object model)
Replaces all placeholders in the fields of given model, provided they are annotated withPlaceholder
.void
replaceStringFields(Object model, IContextReplacerParams contextParams)
Replaces all placeholders in the fields of given model, provided they are annotated withPlaceholder
.String
replaceSystem(String text, IPlaceholderEscaper syntax)
Replaces all system placeholders in the given string.String
replaceTemplate(String text, IPlaceholderEscaper syntax)
Replaces all template placeholders in the given string.
-
-
-
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 withPlaceholder
.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 aPlaceholder
annotation is present: reads the value of that field, replaces all placeholders in the field value as configured by thePlaceholder
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 aPlaceholder
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:- If the field
declares an annotation
of typePlaceholder
, that annotation is present. - Otherwise, when the
declaring class
of the fielddeclares an annotation
of typePlaceholder
, that annotation is present. - Otherwise, if the
declaring class
was reached during analysis while traversing the field of another class, repeat the above process for that field. - Otherwise, no annotation of
Placeholder
is present
Placeholder
on a field of typeUserCredentials
, all string fields in theUserCredentials
are replaced.Placeholder of type
context
are not replaced. If you wish to do that, use thetwo-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 isnull
.- Throws:
RuntimeException
- When reflective access to a field fails (usually due to aSecurityManager
), or when acustomSyntax
provider could not be instantiated.- See Also:
Placeholder
- For each field whose declared type is exactly
-
replaceStringFields
void replaceStringFields(Object model, IContextReplacerParams contextParams) throws RuntimeException
Replaces all placeholders in the fields of given model, provided they are annotated withPlaceholder
.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 aPlaceholder
annotation is present: reads the value of that field, replaces all placeholders in the field value as configured by thePlaceholder
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 aPlaceholder
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:- If the field
declares an annotation
of typePlaceholder
, that annotation is present. - Otherwise, when the
declaring class
of the fielddeclares an annotation
of typePlaceholder
, that annotation is present. - Otherwise, if the
declaring class
was reached during analysis while traversing the field of another class, repeat the above process for that field. - Otherwise, no annotation of
Placeholder
is present
Placeholder
on a field of typeUserCredentials
, all string fields in theUserCredentials
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 isnull
.contextParams
- A map with context values to use for the replacement of context placeholders. Ifnull
, no context parameters are replaced.- Throws:
RuntimeException
- When reflective access to a field fails (usually due to aSecurityManager
), or when acustomSyntax
provider could not be instantiated.- See Also:
Placeholder
- For each field whose declared type is exactly
-
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.
-
createReplacerParams
DefaultReplacerParameters createReplacerParams(IContextReplacerParams contextParams)
Creates aDefaultReplacerParameters
with the given replacer context.- Parameters:
contextParams
- the replacer context parameter- Returns:
DefaultReplacerParameters
with all context references for the replacer process.
-
-