public KeycloakUriBuilder replacePath(String path) { if (path == null) { this.path = null; return this; } this.path = Encode.encodePath(path); return this; }
protected StringBuffer replacePathParameter(String name, String value, boolean isEncoded, String string, StringBuffer buffer, boolean encodeSlash) { Matcher matcher = createUriParamMatcher(string); while (matcher.find()) { String param = matcher.group(1); if (!param.equals(name)) continue; if (!isEncoded) { if (encodeSlash) value = Encode.encodePath(value); else value = Encode.encodePathSegment(value); } else { value = Encode.encodeNonCodes(value); } // if there is a $ then we must backslash it or it will screw up regex group substitution value = value.replace("$", "\\$"); matcher.appendReplacement(buffer, value); } matcher.appendTail(buffer); return buffer; }
public KeycloakUriBuilder replaceMatrix(String matrix) throws IllegalArgumentException { if (matrix == null) matrix = ""; if (!matrix.startsWith(";")) matrix = ";" + matrix; matrix = Encode.encodePath(matrix); if (path == null) { path = matrix; } else { int start = path.lastIndexOf('/'); if (start < 0) start = 0; int matrixIndex = path.indexOf(';', start); if (matrixIndex > -1) path = path.substring(0, matrixIndex) + matrix; else path += matrix; } return this; }
protected static String paths(boolean encode, String basePath, String... segments) { String path = basePath; if (path == null) path = ""; for (String segment : segments) { if ("".equals(segment)) continue; if (path.endsWith("/")) { if (segment.startsWith("/")) { segment = segment.substring(1); if ("".equals(segment)) continue; } if (encode) segment = Encode.encodePath(segment); path += segment; } else { if (encode) segment = Encode.encodePath(segment); if ("".equals(path)) { path = segment; } else if (segment.startsWith("/")) { path += segment; } else { path += "/" + segment; } } } return path; }