final URITemplate template = new URITemplate("http://foo.bar/myPage{?map*}");
public static URITemplate createTemplate(String pathValue) { if (pathValue == null) { return new URITemplate("/"); } if (!pathValue.startsWith("/")) { pathValue = "/" + pathValue; } return new URITemplate(pathValue); }
public static URITemplate createExactTemplate(String pathValue) { URITemplate template = URI_TEMPLATE_CACHE.get(pathValue); if (template == null) { template = new URITemplate(pathValue); if (URI_TEMPLATE_CACHE.size() >= MAX_URI_TEMPLATE_CACHE_SIZE) { URI_TEMPLATE_CACHE.clear(); } URI_TEMPLATE_CACHE.put(pathValue, template); } return template; }
// The template final URITemplate tmpl = new URITemplate("http://my.site/foo{?params*}"); // The query parameters // Uses Maps from Guava since the lib depends on it final Map<String, String> params = Maps.newHashMap(); params.put("site", "http://www.foo.bar/foo/bar"); // The template data expansion final Map<String, VariableValue> data = Maps.newHashMap(); data.put("params", new MapValue(params)); // Expand, build the URL // The expansion takes care of all the encoding for you final URL url = new URL(template.expand(data));
final URITemplate template = new URITemplate("http://www.example.com/fetch.php?title={title}"); final VariableMap varmap = VariableMap.newBuilder() .addScalar("title", "yourtitlehere") .build(); final URL url = template.toURL(varmap);
// Immutable, can be reused as many times as you wish final URITemplate template = new URITemplate("https://graph.facebook.com/{userId}" + "/notifications?template={template}" + "&href=processThis.jsp?param={value}" + "&access_token=abc123"); final Map<String, VariableValue> vars = new HashMap<String, VariableValue>(); vars.put("userId", new ScalarValue("Ankur")); vars.put("template", new ScalarValue("HelloAnkur")); vars.put("value", new ScalarValue("ParamValue"); // Build the expanded string final String expanded = template.expand(vars); // Go with the string
final URITemplate template = new URITemplate("http://dsxsd.com/def/" + "fss/default/files/{filename}"); final VariableMap vars = VariableMap.newBuilder() .addScalarValue("filename", "10 رسم الصباح - 1.mp3") .freeze(); System.out.println(template.toString(vars));
public static void main(final String... args) throws URITemplateException, MalformedURLException { final URITemplate template = new URITemplate("http://www.thomsonlocal.com/Electricians/UK/#{+var}"); final VariableMap map = VariableMap.newBuilder() .addScalarValue("var", "||25") .freeze(); System.out.println(template.toURL(map)); }
final URITemplate template = new URITemplate("http://DOMAIN:PORT/sendmsg?user=test&passwd=test00&text={CONTENT}"); final VariableValue value = new ScalarValue(content); final Map<String, VariableValue> vars = new HashMap<String, VariableValue>(); vars.put("CONTENT", value); // Obtain expanded template final String s = template.expand(vars); // Now build a URL out of it
// Since the lib depends on Guava, might as well use that final List<String> months = ImmutableList.of("jan", "feb", "etc"); // Create the template final URITemplate template = new URITemplate("http://www.asite.com/path/to/something/{int1}/{month}-{int2}"); // Variable values VariableValue int1, month, int2; // Expansion data Map<String, VariableValue> data; // Build the strings for (int i1 = 0; i1 <= 10; i1++) for (final String s: months) for (int i2 = 0; i2 <= 1000; i2++) { int1 = new ScalarValue(Integer.toString(i1)); month = new ScalarValue(s); int2 = new ScalarValue(Integer.toString(i2)); data = ImmutableMap.of("int1", int1, "month", month, "int2", int2); // Print the template System.out.println(template.expand(data)); }
public static boolean checkRequestURI(String servletPath, String uri) { boolean wildcard = uri.endsWith("*"); String theURI = wildcard ? uri.substring(0, uri.length() - 1) : uri; try { URITemplate template = new URITemplate(theURI); MultivaluedMap<String, String> map = new MetadataMap<>(); if (template.match(servletPath, map)) { String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP); if (wildcard || StringUtils.isEmpty(finalGroup) || "/".equals(finalGroup)) { return true; } } } catch (Exception ex) { // ignore } return false; }
public static boolean checkRequestURI(String servletPath, String uri) { boolean wildcard = uri.endsWith("*"); String theURI = wildcard ? uri.substring(0, uri.length() - 1) : uri; try { URITemplate template = new URITemplate(theURI); MultivaluedMap<String, String> map = new MetadataMap<>(); if (template.match(servletPath, map)) { String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP); if (wildcard || StringUtils.isEmpty(finalGroup) || "/".equals(finalGroup)) { return true; } } } catch (Exception ex) { // ignore } return false; }
public static boolean checkRequestURI(String servletPath, String uri) { boolean wildcard = uri.endsWith("*"); String theURI = wildcard ? uri.substring(0, uri.length() - 1) : uri; try { URITemplate template = new URITemplate(theURI); MultivaluedMap<String, String> map = new MetadataMap<>(); if (template.match(servletPath, map)) { String finalGroup = map.getFirst(URITemplate.FINAL_MATCH_GROUP); if (wildcard || StringUtils.isEmpty(finalGroup) || "/".equals(finalGroup)) { return true; } } } catch (Exception ex) { // ignore } return false; }
val = HttpUtils.encodePartiallyEncoded(val, isQuery); } else { val = new URITemplate(val).encodeLiteralCharacters(isQuery);
private String buildPath() { StringBuilder sb = new StringBuilder(); Iterator<PathSegment> iter = paths.iterator(); while (iter.hasNext()) { PathSegment ps = iter.next(); String p = ps.getPath(); if (p.length() != 0 || !iter.hasNext()) { p = new URITemplate(p).encodeLiteralCharacters(false); if (sb.length() == 0 && leadingSlash) { sb.append('/'); } else if (!p.startsWith("/") && sb.length() > 0) { sb.append('/'); } sb.append(p); if (iter.hasNext()) { buildMatrix(sb, ps.getMatrixParameters()); } } } buildMatrix(sb, matrix); return sb.toString(); }
boolean encodePathSlash) { URITemplate templ = new URITemplate(path);
/** * Updates the current URI path with path segment which may contain template variables * @param path new relative path segment * @param values template variable values * @return updated WebClient */ public WebClient path(String path, Object... values) { URI u = new UriBuilderImpl().uri(URI.create("http://tempuri")).path(path).buildFromEncoded(values); getState().setTemplates(getTemplateParametersMap(new URITemplate(path), Arrays.asList(values))); return path(u.getRawPath()); }
/** * Updates the current URI path with path segment which may contain template variables * @param path new relative path segment * @param values template variable values * @return updated WebClient */ public WebClient path(String path, Object... values) { URI u = new UriBuilderImpl().uri(URI.create("http://tempuri")).path(path).buildFromEncoded(values); getState().setTemplates(getTemplateParametersMap(new URITemplate(path), Arrays.asList(values))); return path(u.getRawPath()); }
final URITemplate tmpl = new URITemplate("http://my.site/some/where?word={word}"); final VariableMapBuilder builder = VariableMap.newBuilder(); builder.addScalarValue("word", "Conformément"); tmpl.toString(builder.freeze()); // returns the correct result // Or: tmpl.toURI(builder.freeze()); tmpl.toURL(builder.freeze());
/** * Updates the current URI path with path segment which may contain template variables * @param path new relative path segment * @param values template variable values * @return updated WebClient */ public WebClient path(String path, Object... values) { URI u = new UriBuilderImpl().uri(URI.create("http://tempuri")).path(path).buildFromEncoded(values); getState().setTemplates(getTemplateParametersMap(new URITemplate(path), Arrays.asList(values))); return path(u.getRawPath()); }