public class VariableTable extends Object
This can parse a string that contain variable in form of ${variable-name}
, and substitute them with
defined variables by using defineVariable(String, String)
, etc.
Modifier and Type | Class and Description |
---|---|
static class |
VariableTable.RedefineStrategy
Represents strategies for redefining variables.
|
Constructor and Description |
---|
VariableTable()
Creates a new empty instance.
|
VariableTable(VariableTable.RedefineStrategy redefineStrategy)
Creates a new empty instance.
|
Modifier and Type | Method and Description |
---|---|
static Set<String> |
collectVariableNames(String string)
Collects variable names in the target string.
|
void |
defineVariable(String name,
String replacement)
Adds a new variable into this.
|
void |
defineVariables(Map<String,String> variableMap)
Adds new variables into this.
|
void |
defineVariables(String variableList)
Adds variables from the serialized variable table.
|
Map<String,String> |
getVariables()
Returns the variables names and their replacements in this table.
|
String |
parse(String string)
Substitutes variables in the string and returns the substituted one.
|
String |
parse(String string,
boolean strict)
Substitutes variables in the string and returns the substituted one.
|
String |
toSerialString()
Serializes this variable table.
|
String |
toString() |
static String |
toVariable(String name)
Returns the variable expression for this parser.
|
public VariableTable()
public VariableTable(VariableTable.RedefineStrategy redefineStrategy)
redefineStrategy
- a strategy for redefining variablesIllegalArgumentException
- if the parameter is null
public static String toVariable(String name)
name
- the variable nameIllegalArgumentException
- if the variable name is not validpublic void defineVariable(String name, String replacement)
name
- the variable namereplacement
- the replacementIllegalArgumentException
- if this rejects the target variable, or some parameters are null
public void defineVariables(Map<String,String> variableMap)
variableMap
- the variable map (name -> value
)IllegalArgumentException
- if this rejects some variables, or some parameters are null
public String toSerialString()
defineVariables(String)
.defineVariables(String)
public void defineVariables(String variableList)
VariableList:
VariableList "," Variable
Variable
","
(Empty)
Variable:
Value_key "=" Value_value
Value:
Character*
Character:
any character except ",", "=", "\\"
"\" any character
variableList
- the serialized variable tableIllegalArgumentException
- if this rejects some variables, or some parameters are null
public Map<String,String> getVariables()
public String parse(String string)
string
- the target stringIllegalArgumentException
- if the string contains some undefined variables, or it is null
defineVariable(String, String)
public String parse(String string, boolean strict)
string
- the target stringstrict
- true
to raise error if the string contain undefined variables, or false
to
leave such variablesIllegalArgumentException
- if the string contains some undefined variables (only if strict mode),
or it is null
defineVariable(String, String)
public static Set<String> collectVariableNames(String string)
string
- the target string (nullable)Copyright © 2011–2019 Asakusa Framework Team. All rights reserved.