public class RouteTokenFormatter extends Object implements TokenFormatter
TokenFormatter
with support for route like place names.
Instead of wiring a hierarchy of several places bound to multiple presenters this implements a flat structure where every history token is bound to a single presenter.
Usage:
Replace the default binding to ParameterTokenFormatter
with RouteTokenFormatter
. In case you use
GWTPs DefaultModule
:
install(new DefaultModule(DefaultPlaceManager.class, RouteTokenFormatter.class));
Now all @NameToken's are treated as routes. Routes are expected to start with an '/' and can contain path parameters as well as query parameters.
@NameToken("/user/{userId}/privacy") // Token for PrivacyPresenter
@NameToken("/user/{userId}/privacy/profile") // Token for PrivacyProfilePresenter
@NameToken("/user/{userId}/privacy/photos") // Token for PrivacyPhotosPresenter
Static-parts of an route tie stronger than parameter-parts. This way following works:
@NameToken("/{vanityId}") // Token for VanityUrlPresenter
@NameToken("/privacy") // Token for PrivacyPresenter
Note: For the moment this is implemented on top of the hierarchical-place API to not an big structural changes prior 1.0 release.
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. |
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.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.Copyright © 2010–2014 Arcbees. All rights reserved.