public class ParameterTokenFormatter extends Object implements TokenFormatter
String
values to PlaceRequest
and PlaceRequest
hierarchies and vice-versa. The default implementation
uses:
'/'
to separate PlaceRequest
s in a hierarchy;';'
to separate parameters in a PlaceRequest
;'='
to separate the parameter name from its value;'\'
to escape separators inside parameters names and values in a
PlaceRequest
.'\'
character by replacing '/'
with
'\0'
, ';'
with '\1'
, '='
with '\2'
and '\'
with
'\3'
.
Before decoding a String
URL fragment into a PlaceRequest
or a
PlaceRequest
hierarchy, ParameterTokenFormatter
will first pass the
String
through URL#decodeQueryString(String)
so that if the URL was URL-encoded
by some user agent, like a mail user agent, it is still parsed correctly.
For example, ParameterTokenFormatter
would parse any of the following:
nameToken1%3Bparam1.1%3Dvalue1.1%3Bparam1.2%3Dvalue1.2%2FnameToken2%2FnameToken3%3Bparam3.1%3Dvalue%03%11 nameToken1;param1.1=value1.1;param1.2=value1.2/nameToken2/nameToken3;param3.1=value\03\21Into the following hierarchy of
PlaceRequest
:
{ { "nameToken1", { {"param1.1", "value1.1"}, {"parame1.2","value1.2"} }, "nameToken2", {}, "nameToken3", { {"param3.1", "value/3=1"} } } }If you want to use different symbols as separator, use the
#ParameterTokenFormatter(String, String, String)
constructor.Modifier and Type | Field and Description |
---|---|
protected static String |
DEFAULT_HIERARCHY_SEPARATOR |
protected static String |
DEFAULT_PARAM_SEPARATOR |
protected static String |
DEFAULT_VALUE_SEPARATOR |
protected static char |
ESCAPE_CHARACTER |
protected static String |
ESCAPED_ESCAPE_CHAR |
protected static String |
ESCAPED_HIERARCHY_SEPARATOR |
protected static String |
ESCAPED_PARAM_SEPARATOR |
protected static String |
ESCAPED_VALUE_SEPARATOR |
Constructor and Description |
---|
ParameterTokenFormatter(UrlUtils urlUtils)
Builds a
ParameterTokenFormatter using the default separators and escape character. |
ParameterTokenFormatter(UrlUtils urlUtils,
String hierarchySeparator,
String paramSeparator,
String valueSeparator)
This constructor makes it possible to use custom separators in your token formatter.
|
Modifier and Type | Method and Description |
---|---|
String |
toHistoryToken(List<PlaceRequest> placeRequestHierarchy)
Converts a place request hierarchy (a list of
PlaceRequest ) into a history token. |
PlaceRequest |
toPlaceRequest(String placeToken)
Converts a place token into a
PlaceRequest . |
List<PlaceRequest> |
toPlaceRequestHierarchy(String historyToken)
Converts a history token into a place request hierarchy (a list of
PlaceRequest ). |
String |
toPlaceToken(PlaceRequest placeRequest)
Converts a
PlaceRequest into a place token. |
protected static final String DEFAULT_HIERARCHY_SEPARATOR
protected static final String DEFAULT_PARAM_SEPARATOR
protected static final String DEFAULT_VALUE_SEPARATOR
protected static final char ESCAPE_CHARACTER
protected static final String ESCAPED_HIERARCHY_SEPARATOR
protected static final String ESCAPED_PARAM_SEPARATOR
protected static final String ESCAPED_VALUE_SEPARATOR
protected static final String ESCAPED_ESCAPE_CHAR
@Inject public ParameterTokenFormatter(UrlUtils urlUtils)
ParameterTokenFormatter
using the default separators and escape character.public ParameterTokenFormatter(UrlUtils urlUtils, String hierarchySeparator, String paramSeparator, String valueSeparator)
URL#encodeQueryString(String)
).hierarchySeparator
- The symbol used to separate PlaceRequest
in a hierarchy.
Must be a 1-character string and can't be %
.paramSeparator
- The symbol used to separate parameters in a PlaceRequest
. Must
be a 1-character string and can't be %
.valueSeparator
- The symbol used to separate the parameter name from its value. Must be
a 1-character string and can't be %
.public String toHistoryToken(List<PlaceRequest> placeRequestHierarchy) throws TokenFormatException
TokenFormatter
PlaceRequest
) into a history token. The
history token will not be fully query encoded, it may still contain some unescaped separators.
However, these separators can be encoded and it will still work, making the scheme robust to
systems that force encoding these characters like some email apps.toHistoryToken
in interface TokenFormatter
placeRequestHierarchy
- The place request hierarchy.TokenFormatException
- if there is an error converting.public PlaceRequest toPlaceRequest(String placeToken) throws TokenFormatException
TokenFormatter
PlaceRequest
. A place token is different than a history
token, since the history token can contain a hierarchy of different place requests.toPlaceRequest
in interface TokenFormatter
placeToken
- The place token.TokenFormatException
- if there is an error converting.public List<PlaceRequest> toPlaceRequestHierarchy(String historyToken) throws TokenFormatException
TokenFormatter
PlaceRequest
).toPlaceRequestHierarchy
in interface TokenFormatter
historyToken
- The history token.TokenFormatException
- if there is an error converting.public String toPlaceToken(PlaceRequest placeRequest) throws TokenFormatException
TokenFormatter
PlaceRequest
into a place token. A place token is different than a history
token, since the history token can contain a hierarchy of different place requests. The history
token will not be fully query encoded, it may still contain some unescaped separators.
However, these separators can be encoded and it will still work, making the scheme robust to
systems that force encoding these characters like some email apps.toPlaceToken
in interface TokenFormatter
placeRequest
- The place request.TokenFormatException
- if there is an error converting.Copyright © 2010–2014 Arcbees. All rights reserved.