/** * Encoded literal characters surrounding template variables, * ex. "a {id} b" will be encoded to "a%20{id}%20b" * @return encoded value */ public String encodeLiteralCharacters(boolean isQuery) { final float encodedRatio = 1.5f; StringBuilder sb = new StringBuilder((int)(encodedRatio * template.length())); for (UriChunk chunk : uriChunks) { String val = chunk.getValue(); if (chunk instanceof Literal) { sb.append(HttpUtils.encodePartiallyEncoded(val, isQuery)); } else { sb.append(val); } } return sb.toString(); }
/** * Encoded literal characters surrounding template variables, * ex. "a {id} b" will be encoded to "a%20{id}%20b" * @return encoded value */ public String encodeLiteralCharacters(boolean isQuery) { final float encodedRatio = 1.5f; StringBuilder sb = new StringBuilder((int)(encodedRatio * template.length())); for (UriChunk chunk : uriChunks) { String val = chunk.getValue(); if (chunk instanceof Literal) { sb.append(HttpUtils.encodePartiallyEncoded(val, isQuery)); } else { sb.append(val); } } return sb.toString(); }
@Override public URI buildFromEncodedMap(Map<String, ?> map) throws IllegalArgumentException, UriBuilderException { Map<String, String> decodedMap = new HashMap<>(map.size()); for (Map.Entry<String, ? extends Object> entry : map.entrySet()) { if (entry.getValue() == null) { throw new IllegalArgumentException("Value is null"); } String theValue = entry.getValue().toString(); if (theValue.contains("/")) { // protecting '/' from being encoded here assumes that a given value may constitute multiple // path segments - very questionable especially given that queries and fragments may also // contain template vars - technically this can be covered by checking where a given template // var is coming from and act accordingly. Confusing nonetheless. StringBuilder buf = new StringBuilder(); String[] values = theValue.split("/"); for (int i = 0; i < values.length; i++) { buf.append(HttpUtils.encodePartiallyEncoded(values[i], false)); if (i + 1 < values.length) { buf.append("/"); } } decodedMap.put(entry.getKey(), buf.toString()); } else { decodedMap.put(entry.getKey(), HttpUtils.encodePartiallyEncoded(theValue, false)); } } return doBuildFromMap(decodedMap, true, false); }
boolean templateValue = val.startsWith("{") && val.endsWith("}"); if (!templateValue) { val = HttpUtils.encodePartiallyEncoded(val, isQuery); if (!isQuery) { val = val.replaceAll("/", "%2F");
String[] values = StringUtils.split(theValue, "/"); for (int i = 0; i < values.length; i++) { buf.append(HttpUtils.encodePartiallyEncoded(values[i], false)); if (i + 1 < values.length) { buf.append("/"); decodedMap.put(entry.getKey(), HttpUtils.encodePartiallyEncoded(theValue, false));
boolean templateValue = val.startsWith("{") && val.endsWith("}"); if (!templateValue) { val = HttpUtils.encodePartiallyEncoded(val, isQuery); } else { val = new URITemplate(val).encodeLiteralCharacters(isQuery);
oval = HttpUtils.encodePartiallyEncoded(oval.toString(), isQuery); } else { oval = isQuery ? HttpUtils.queryEncode(oval.toString()) : HttpUtils.pathEncode(oval.toString());
oval = HttpUtils.encodePartiallyEncoded(oval.toString(), isQuery); } else { oval = isQuery ? HttpUtils.queryEncode(oval.toString()) : HttpUtils.pathEncode(oval.toString());
value = HttpUtils.encodePartiallyEncoded(value, isQuery); } else { value = isQuery ? HttpUtils.queryEncode(value) : HttpUtils.pathEncode(value);
value = HttpUtils.encodePartiallyEncoded(value, isQuery); } else { value = isQuery ? HttpUtils.queryEncode(value) : HttpUtils.pathEncode(value);
uriChunks.add(chunk); if (chunk instanceof Literal) { String encodedValue = HttpUtils.encodePartiallyEncoded(chunk.getValue(), false); String substr = escapeCharacters(encodedValue); literalChars.append(substr);
uriChunks.add(chunk); if (chunk instanceof Literal) { String encodedValue = HttpUtils.encodePartiallyEncoded(chunk.getValue(), false); String substr = escapeCharacters(encodedValue); literalChars.append(substr);