public class StringReplacer extends Object
The default is to replace ${var}
with
var
from a Map
instance. But there are other ways possible by
using different Pattern
and StringReplacer.ReplaceSource
implementations.
In order to replace a string with the ${var} pattern using Java System Properties use:
String str = StringReplacer.replace ( "Hello ${user.name}!", System.getProperties () );
Modifier and Type | Class and Description |
---|---|
static interface |
StringReplacer.ReplaceSource |
Modifier and Type | Field and Description |
---|---|
static Pattern |
DEFAULT_PATTERN
The default pattern:
${var} |
Constructor and Description |
---|
StringReplacer() |
Modifier and Type | Method and Description |
---|---|
static StringReplacer.ReplaceSource |
newBeansSource(Map<?,?> properties)
Create a new ReplaceSource that handles bean references
|
static StringReplacer.ReplaceSource |
newSource(Map<?,?> properties)
Create a new ReplaceSource for Map sources
|
static String |
replace(String string,
Map<?,?> properties)
Replace with the default pattern of
${var} |
static String |
replace(String string,
StringReplacer.ReplaceSource replaceSource,
Pattern pattern) |
public static final Pattern DEFAULT_PATTERN
${var}
public static String replace(String string, Map<?,?> properties)
${var}
string
- the string which should be processed, may be null
properties
- the properties used for replacingpublic static StringReplacer.ReplaceSource newSource(Map<?,?> properties)
The source will not replace elements that are not found in the map.
properties
- the Map acting as a sourcepublic static StringReplacer.ReplaceSource newBeansSource(Map<?,?> properties)
properties
- the properties to use for replacingpublic static String replace(String string, StringReplacer.ReplaceSource replaceSource, Pattern pattern)