/** * Check if the current place-token matches the given route and return the associated {@link RouteMatch}. * * @param route The route to check. * @return Associated {@link RouteMatch} or <code>null</code> if the place-token doesn't match the given route. */ RouteMatch matchRoute(String route) { String[] routeParts = route.split("/"); if (placeParts.length != routeParts.length) { return null; } if (placeParts.length == 0) { assert routeIsEmpty(route); return new RouteMatch(route, 0, null); } Map<String, String> recordedParameters = new HashMap<>(); int staticMatches = 0; for (int i = 0; i < placeParts.length; i++) { if (placeParts[i].equals(routeParts[i])) { staticMatches++; } else if (routeParts[i].matches("\\{.*\\}")) { String parameterName = routeParts[i].substring(1, routeParts[i].length() - 1); recordedParameters.put(parameterName, placeParts[i]); } else { return null; } } return new RouteMatch(route, staticMatches, recordedParameters); }
@Override public PlaceRequest toPlaceRequest(String placeToken) throws TokenFormatException { /* * To support the native GWT history as well as HTML pushstate a slash is added when needed. */ if (!placeTokenIsValid(placeToken)) { return toPlaceRequest("/" + placeToken); } int split = placeToken.indexOf('?'); String place = (split != -1) ? placeToken.substring(0, split) : placeToken; String query = (split != -1) ? placeToken.substring(split + 1) : ""; RouteMatcher matcher = new RouteMatcher(place); RouteMatch match = (!matcher.allMatches.isEmpty()) ? matcher.allMatches.last() : new RouteMatch(place, 0, null); match.parameters = decodeEmbeddedParams(match.parameters); match.parameters = parseQueryString(query, match.parameters); return new PlaceRequest.Builder().nameToken(match.route).with(match.parameters).build(); }