|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.restlet.util.Template
public class Template
String template with a pluggable model. Supports both formatting and parsing.
The template variables can be inserted using the "{name}" syntax and
described using the modifiable map of variable descriptors. When no
descriptor is found for a given variable, the template logic uses its default
variable property initialized using the default Variable constructor.
Note that the variable descriptors can be changed before the first parsing or
matching call. After that point, changes won't be taken into account.
Format and parsing methods are specially available to deal with requests and
response. See format(Request, Response) and
parse(String, Request).
Resolver,
URI Template
specification| Field Summary | |
|---|---|
static int |
MODE_EQUALS
|
static int |
MODE_STARTS_WITH
|
| Constructor Summary | |
|---|---|
Template(Logger logger,
String pattern)
Default constructor. |
|
Template(Logger logger,
String pattern,
int matchingMode)
Constructor. |
|
Template(Logger logger,
String pattern,
int matchingMode,
int defaultType,
String defaultDefaultValue,
boolean defaultRequired,
boolean defaultFixed)
Constructor. |
|
Template(String pattern)
Default constructor. |
|
Template(String pattern,
int matchingMode)
Constructor. |
|
Template(String pattern,
int matchingMode,
int defaultType,
String defaultDefaultValue,
boolean defaultRequired,
boolean defaultFixed)
Constructor. |
|
| Method Summary | |
|---|---|
String |
format(Map<String,Object> values)
Creates a formatted string based on the given map of values. |
String |
format(Request request,
Response response)
Creates a formatted string based on the given request and response. |
String |
format(Resolver<String> resolver)
Creates a formatted string based on the given variable resolver. |
Variable |
getDefaultVariable()
Returns the default variable. |
Logger |
getLogger()
Returns the logger to use. |
int |
getMatchingMode()
Returns the matching mode to use when parsing a formatted reference. |
String |
getPattern()
Returns the pattern to use for formatting or parsing. |
List<String> |
getVariableNames()
Returns the list of variable names in the template. |
Map<String,Variable> |
getVariables()
Returns the modifiable map of variable descriptors. |
int |
match(String formattedString)
Indicates if the current pattern matches the given formatted string. |
int |
parse(String formattedString,
Map<String,Object> variables)
Attempts to parse a formatted reference. |
int |
parse(String formattedString,
Request request)
Attempts to parse a formatted reference. |
void |
setDefaultVariable(Variable defaultVariable)
Sets the variable to use, if no variable is given. |
void |
setLogger(Logger logger)
Sets the logger to use. |
void |
setMatchingMode(int matchingMode)
Sets the matching mode to use when parsing a formatted reference. |
void |
setPattern(String pattern)
Sets the pattern to use for formatting or parsing. |
void |
setVariables(Map<String,Variable> variables)
Sets the modifiable map of variables. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MODE_EQUALS
public static final int MODE_STARTS_WITH
| Constructor Detail |
|---|
public Template(Logger logger,
String pattern)
logger - The logger to use.pattern - The pattern to use for formatting or parsing.
public Template(Logger logger,
String pattern,
int matchingMode)
logger - The logger to use.pattern - The pattern to use for formatting or parsing.matchingMode - The matching mode to use when parsing a formatted
reference.
public Template(Logger logger,
String pattern,
int matchingMode,
int defaultType,
String defaultDefaultValue,
boolean defaultRequired,
boolean defaultFixed)
logger - The logger to use.pattern - The pattern to use for formatting or parsing.matchingMode - The matching mode to use when parsing a formatted
reference.defaultType - The default type of variables with no descriptor.defaultDefaultValue - The default value for null variables with no descriptor.defaultRequired - The default required flag for variables with no
descriptor.defaultFixed - The default fixed value for variables with no descriptor.public Template(String pattern)
pattern - The pattern to use for formatting or parsing.
public Template(String pattern,
int matchingMode)
pattern - The pattern to use for formatting or parsing.matchingMode - The matching mode to use when parsing a formatted
reference.
public Template(String pattern,
int matchingMode,
int defaultType,
String defaultDefaultValue,
boolean defaultRequired,
boolean defaultFixed)
pattern - The pattern to use for formatting or parsing.matchingMode - The matching mode to use when parsing a formatted
reference.defaultType - The default type of variables with no descriptor.defaultDefaultValue - The default value for null variables with no descriptor.defaultRequired - The default required flag for variables with no
descriptor.defaultFixed - The default fixed value for variables with no descriptor.| Method Detail |
|---|
public String format(Map<String,Object> values)
values - The values to use when formatting.
Resolver.createResolver(Map)
public String format(Request request,
Response response)
request - The request to use as a model.response - The response to use as a model.
Resolver.createResolver(Request, Response)public String format(Resolver<String> resolver)
resolver - The variable resolver to use.
public Variable getDefaultVariable()
public Logger getLogger()
public int getMatchingMode()
public String getPattern()
public List<String> getVariableNames()
public Map<String,Variable> getVariables()
public int match(String formattedString)
formattedString - The formatted string to match.
public int parse(String formattedString,
Map<String,Object> variables)
formattedString - The string to parse.variables - The map of variables to update.
Reference.decode(String)
public int parse(String formattedString,
Request request)
formattedString - The string to parse.request - The request to update.
Reference.decode(String)public void setDefaultVariable(Variable defaultVariable)
defaultVariable - public void setLogger(Logger logger)
logger - The logger to use.public void setMatchingMode(int matchingMode)
matchingMode - The matching mode to use when parsing a formatted
reference.public void setPattern(String pattern)
pattern - The pattern to use for formatting or parsing.public void setVariables(Map<String,Variable> variables)
variables - The modifiable map of variables.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||