/** * Create a selector from the given uri template string. * * @param uriPathTmpl The string to compile into a {@link UriPathTemplate}. */ public UriPathSelector(String uriPathTmpl) { super(new UriPathTemplate(uriPathTmpl)); }
/** * Tests the given {@code uri} against this template, returning {@code true} if the * uri matches the template, {@code false} otherwise. * * @param uri The uri to match * * @return {@code true} if there's a match, {@code false} otherwise */ public boolean matches(String uri) { return matcher(uri).matches(); }
@Nullable @Override public Map<String, Object> resolve(Object key) { Map<String, Object> headers = getObject().match(key.toString()); if (null != headers && !headers.isEmpty()) { return headers; } return null; } };
@Override public boolean matches(Object path) { return String.class.isAssignableFrom(path.getClass()) && getObject().matches((String)path); }
/** * Matches the template against the given {@code uri} returning a map of path parameters * extracted from the uri, keyed by the names in the template. If the uri does not match, * or there are no path parameters, an empty map is returned. * * @param uri The uri to match * * @return the path parameters from the uri. Never {@code null}. */ public Map<String, Object> match(String uri) { Map<String, Object> pathParameters = vars.get(uri); if (null != pathParameters) { return pathParameters; } pathParameters = new HashMap<String, Object>(); Matcher m = matcher(uri); if (m.matches()) { int i = 1; for (String name : pathVariables) { String val = m.group(i++); pathParameters.put(name, val); } } synchronized (vars) { vars.put(uri, pathParameters); } return pathParameters; }