| java.lang.Object org.restlet.util.Template
Template | public class Template (Code) | | String template with a model is based on a request. 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.
Model property |
Variable name |
Content type |
request.confidential |
c |
boolean (true|false) |
request.clientInfo.address |
cia |
String |
request.clientInfo.agent |
cig |
String |
request.challengeResponse.identifier |
cri |
String |
request.challengeResponse.scheme |
crs |
String |
request.entity.characterSet |
ecs |
String |
response.entity.characterSet |
ECS |
String |
request.entity.encoding |
ee |
String |
response.entity.encoding |
EE |
String |
request.entity.expirationDate |
eed |
Date (HTTP format) |
response.entity.expirationDate |
EED |
Date (HTTP format) |
request.entity.language |
el |
String |
response.entity.language |
EL |
String |
request.entity.modificationDate |
emd |
Date (HTTP format) |
response.entity.modificationDate |
EMD |
Date (HTTP format) |
request.entity.mediaType |
emt |
String |
response.entity.mediaType |
EMT |
String |
request.entity.size |
es |
Integer |
response.entity.size |
ES |
Integer |
request.entity.tag |
et |
String |
response.entity.tag |
ET |
String |
request.referrerRef |
f* |
Reference (see table below variable name sub-parts) |
request.hostRef |
h* |
Reference (see table below variable name sub-parts) |
request.method |
m |
String |
request.rootRef |
o* |
Reference (see table below variable name sub-parts) |
request.protocol |
p |
String |
request.resourceRef |
r* |
Reference (see table below variable name sub-parts) |
response.redirectRef |
R* |
Reference (see table below variable name sub-parts) |
response.status |
S |
Integer |
response.serverInfo.address |
SIA |
String |
response.serverInfo.agent |
SIG |
String |
response.serverInfo.port |
SIP |
Integer |
Below is the list of name sub-parts, for Reference variables, that can
replace the asterix in the variable names above:
Reference property |
Sub-part name |
Content type |
authority |
a |
String |
baseRef |
b* |
Reference |
relativePart |
e |
String |
fragment |
f |
String |
hostIdentifier |
h |
String |
identifier |
i |
String |
path |
p |
String |
query |
q |
String |
remainingPart |
r |
String |
See Also: URI Template
* specification author: Jerome Louvel (contact@noelios.com) |
Constructor Summary | |
public | Template(Logger logger, String pattern) Default constructor. | public | Template(Logger logger, String pattern, int matchingMode) Constructor. | public | Template(Logger logger, String pattern, int matchingMode, int defaultType, String defaultDefaultValue, boolean defaultRequired, boolean defaultFixed) Constructor. |
Method Summary | |
public String | format(Request request, Response response) Creates a formatted string based on the given request.
Parameters: request - The request to use as a model. Parameters: response - The response to use as a model. | public String | format(Map<String, Object> variables) Creates a formatted string based on the given request.
Parameters: variables - The variables to use when formatting. | public Variable | getDefaultVariable() Returns the default variable. | public Logger | getLogger() Returns the logger to use. | public int | getMatchingMode() Returns the matching mode to use when parsing a formatted reference. | public String | getPattern() Returns the pattern to use for formatting or parsing. | public Map<String, Variable> | getVariables() Returns the modifiable map of variables. | public int | match(String formattedString) Indicates if the current pattern matches the given formatted string.
Parameters: formattedString - The formatted string to match. | public int | parse(String formattedString, Request request) Attempts to parse a formatted reference. | public int | parse(String formattedString, Map<String, Object> variables) Attempts to parse a formatted reference. | public void | setMatchingMode(int matchingMode) Sets the matching mode to use when parsing a formatted reference. | public void | setPattern(String pattern) Sets the pattern to use for formatting or parsing. |
MODE_EQUALS | final public static int MODE_EQUALS(Code) | | |
MODE_STARTS_WITH | final public static int MODE_STARTS_WITH(Code) | | |
Template | public Template(Logger logger, String pattern)(Code) | | Default constructor. Each variable matches any sequence of characters by
default. When parsing, the template will attempt to match the whole
template. When formatting, the variable are replaced by an empty string
if they don't exist in the model.
Parameters: logger - The logger to use. Parameters: pattern - The pattern to use for formatting or parsing. |
Template | public Template(Logger logger, String pattern, int matchingMode)(Code) | | Constructor.
Parameters: logger - The logger to use. Parameters: pattern - The pattern to use for formatting or parsing. Parameters: matchingMode - The matching mode to use when parsing a formattedreference. |
Template | public Template(Logger logger, String pattern, int matchingMode, int defaultType, String defaultDefaultValue, boolean defaultRequired, boolean defaultFixed)(Code) | | Constructor.
Parameters: logger - The logger to use. Parameters: pattern - The pattern to use for formatting or parsing. Parameters: matchingMode - The matching mode to use when parsing a formattedreference. Parameters: defaultType - The default type of variables with no descriptor. Parameters: defaultDefaultValue - The default value for null variables with no descriptor. Parameters: defaultRequired - The default required flag for variables with nodescriptor. Parameters: defaultFixed - The default fixed value for variables with no descriptor. |
format | public String format(Request request, Response response)(Code) | | Creates a formatted string based on the given request.
Parameters: request - The request to use as a model. Parameters: response - The response to use as a model. The formatted string. |
format | public String format(Map<String, Object> variables)(Code) | | Creates a formatted string based on the given request.
Parameters: variables - The variables to use when formatting. The formatted string. |
getDefaultVariable | public Variable getDefaultVariable()(Code) | | Returns the default variable.
The default variable. |
getLogger | public Logger getLogger()(Code) | | Returns the logger to use.
The logger to use. |
getMatchingMode | public int getMatchingMode()(Code) | | Returns the matching mode to use when parsing a formatted reference.
The matching mode to use when parsing a formatted reference. |
getPattern | public String getPattern()(Code) | | Returns the pattern to use for formatting or parsing.
The pattern to use for formatting or parsing. |
getVariables | public Map<String, Variable> getVariables()(Code) | | Returns the modifiable map of variables.
The modifiable map of variables. |
match | public int match(String formattedString)(Code) | | Indicates if the current pattern matches the given formatted string.
Parameters: formattedString - The formatted string to match. The number of matched characters or -1 if the match failed. |
parse | public int parse(String formattedString, Request request)(Code) | | Attempts to parse a formatted reference. If the parsing succeeds, the
given request's attributes are updated.
Note that the values parsed are directly extracted from the formatted
reference and are therefore not percent-decoded.
See Also: Reference.decode(String) Parameters: formattedString - The string to parse. Parameters: request - The request to update. The number of matched characters or -1 if no character matched. |
parse | public int parse(String formattedString, Map<String, Object> variables)(Code) | | Attempts to parse a formatted reference. If the parsing succeeds, the
given request's attributes are updated.
Note that the values parsed are directly extracted from the formatted
reference and are therefore not percent-decoded.
See Also: Reference.decode(String) Parameters: formattedString - The string to parse. Parameters: variables - The map of variables to update. The number of matched characters or -1 if no character matched. |
setMatchingMode | public void setMatchingMode(int matchingMode)(Code) | | Sets the matching mode to use when parsing a formatted reference.
Parameters: matchingMode - The matching mode to use when parsing a formattedreference. |
setPattern | public void setPattern(String pattern)(Code) | | Sets the pattern to use for formatting or parsing.
Parameters: pattern - The pattern to use for formatting or parsing. |
|
|