public class MessageUtils extends Object
This utility class provides features to replace texts containing variables by looking up values from the resolved or given resource bundle.
If the variable is not found, then it returns the variable name wrapped by '???'.
Modifier and Type | Field and Description |
---|---|
static char |
DEFAULT_ESCAPE
Default escape character to override the default escape character of
StrSubstitutor , '$'. |
Modifier and Type | Method and Description |
---|---|
static String |
replaceMessages(String basename,
String text)
Replaces the given text by looking up values from the resolved resource bundle by the
basename . |
static String |
replaceMessages(String basename,
String text,
String variablePrefix,
String variableSuffix)
Replaces the given text by looking up values from the resolved resource bundle by the
basename . |
static String |
replaceMessages(String basename,
String text,
String variablePrefix,
String variableSuffix,
Character escapeChar)
Replaces the given text by looking up values from the resolved resource bundle by the
basename . |
static String |
replaceMessagesByBundle(ResourceBundle bundle,
String text)
Replaces the given text by looking up values from the given resource bundle.
|
static String |
replaceMessagesByBundle(ResourceBundle bundle,
String text,
String variablePrefix,
String variableSuffix)
Replaces the given text by looking up values from the given resource bundle.
|
static String |
replaceMessagesByBundle(ResourceBundle bundle,
String text,
String variablePrefix,
String variableSuffix,
Character escapeChar)
Replaces the given text by looking up values from the given resource bundle.
|
public static final char DEFAULT_ESCAPE
StrSubstitutor
, '$'.
'\\' is more user friendly than '$' in most use cases.public static String replaceMessages(String basename, String text)
basename
.basename
- resource bundle base nametext
- text to replacepublic static String replaceMessages(String basename, String text, String variablePrefix, String variableSuffix)
basename
.basename
- resource bundle base nametext
- text to replacevariablePrefix
- variable reference prefix. "${" by default.variableSuffix
- variable reference suffix. "}" by default.public static String replaceMessages(String basename, String text, String variablePrefix, String variableSuffix, Character escapeChar)
basename
.basename
- resource bundle base nametext
- text to replacevariablePrefix
- variable reference prefix. "${" by default.variableSuffix
- variable reference suffix. "}" by default.escapeChar
- escape character which can be put just before a variable reference to ignore the expression.public static String replaceMessagesByBundle(ResourceBundle bundle, String text)
bundle
- resource bundletext
- text to replacepublic static String replaceMessagesByBundle(ResourceBundle bundle, String text, String variablePrefix, String variableSuffix)
bundle
- resource bundletext
- text to replacevariablePrefix
- variable reference prefix. "${" by default.variableSuffix
- variable reference suffix. "}" by default.public static String replaceMessagesByBundle(ResourceBundle bundle, String text, String variablePrefix, String variableSuffix, Character escapeChar)
bundle
- resource bundletext
- text to replacevariablePrefix
- variable reference prefix. "${" by default.variableSuffix
- variable reference suffix. "}" by default.escapeChar
- escape character which can be put just before a variable reference to ignore the expression.Copyright © 2008–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.