Revert "Support {/var} syntax in UriComponentsBuilder"

This reverts commit a57d42829c after the
realization of a weaknesses with the proposed approach.

For example if a path segment contains both a /-prefixed and a regular
URI variable, there is no way to split that into a sequence of path
and path segments. The solution will have to be on the side of
UriComponents at the time of encoding.
This commit is contained in:
Rossen Stoyanchev
2015-03-23 16:44:03 -04:00
parent 95f6e4cc9b
commit 44e8f7b333
3 changed files with 12 additions and 52 deletions

View File

@@ -716,35 +716,18 @@ public class UriComponentsBuilder implements Cloneable {
}
public void addPath(String path) {
if (!StringUtils.hasText(path)) {
return;
if (StringUtils.hasText(path)) {
PathSegmentComponentBuilder psBuilder = getLastBuilder(PathSegmentComponentBuilder.class);
FullPathComponentBuilder fpBuilder = getLastBuilder(FullPathComponentBuilder.class);
if (psBuilder != null) {
path = path.startsWith("/") ? path : "/" + path;
}
if (fpBuilder == null) {
fpBuilder = new FullPathComponentBuilder();
this.builders.add(fpBuilder);
}
fpBuilder.append(path);
}
int startIndex = path.indexOf("{/");
while (startIndex != -1) {
String pathToAdd = path.substring(0, startIndex);
addPathInternal(pathToAdd);
int endIndex = path.indexOf("}", startIndex);
String pathSegmentToAdd = "{" + path.substring(startIndex + 2, endIndex) + "}";
addPathSegments(pathSegmentToAdd);
path = (endIndex >= path.length()) ? "" : path.substring(endIndex + 1);
startIndex = path.indexOf("{/");
}
addPathInternal(path);
}
private void addPathInternal(String path) {
PathSegmentComponentBuilder psBuilder = getLastBuilder(PathSegmentComponentBuilder.class);
FullPathComponentBuilder fpBuilder = getLastBuilder(FullPathComponentBuilder.class);
if (psBuilder != null) {
path = path.startsWith("/") ? path : "/" + path;
}
if (fpBuilder == null) {
fpBuilder = new FullPathComponentBuilder();
this.builders.add(fpBuilder);
}
fpBuilder.append(path);
}
@SuppressWarnings("unchecked")