Removing remaining use of PathPattern with String path

This commit is contained in:
Rossen Stoyanchev
2017-07-07 19:11:13 +02:00
parent 00f4c36d7a
commit 9640cedeae
11 changed files with 90 additions and 79 deletions

View File

@@ -60,7 +60,19 @@ public interface PathContainer {
* @return the sub-path
*/
static PathContainer subPath(PathContainer path, int index) {
return DefaultPathContainer.subPath(path, index, path.elements().size());
return subPath(path, index, path.elements().size());
}
/**
* Extract a sub-path from the given start offset (inclusive) into the path
* element list and to the end offset (exclusive).
* @param path the path to extract from
* @param startIndex the start element index (inclusive)
* @param endIndex the end element index (exclusive)
* @return the sub-path
*/
static PathContainer subPath(PathContainer path, int startIndex, int endIndex) {
return DefaultPathContainer.subPath(path, startIndex, endIndex);
}

View File

@@ -19,6 +19,7 @@ package org.springframework.web.cors.reactive;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.http.server.reactive.PathContainer;
import org.springframework.lang.Nullable;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.server.ServerWebExchange;
@@ -66,10 +67,10 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
@Override
public CorsConfiguration getCorsConfiguration(ServerWebExchange exchange) {
String lookupPath = exchange.getRequest().getPath().pathWithinApplication().value();
PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();
return this.corsConfigurations.entrySet().stream()
.filter(entry -> entry.getKey().matches(lookupPath))
.map(entry -> entry.getValue())
.map(Map.Entry::getValue)
.findFirst()
.orElse(null);
}

View File

@@ -73,7 +73,8 @@ public class ParsingPathMatcher implements PathMatcher {
@Override
public String extractPathWithinPattern(String pattern, String path) {
PathPattern pathPattern = getPathPattern(pattern);
return pathPattern.extractPathWithinPattern(path);
PathContainer pathContainer = PathContainer.parse(path, StandardCharsets.UTF_8);
return pathPattern.extractPathWithinPattern(pathContainer).value();
}
@Override

View File

@@ -158,22 +158,6 @@ public class PathPattern implements Comparable<PathPattern> {
}
// TODO: remove String-variants
public boolean matches(String path) {
return matches(PathContainer.parse(path, StandardCharsets.UTF_8));
}
public PathMatchResult matchAndExtract(String path) {
return matchAndExtract(PathContainer.parse(path, StandardCharsets.UTF_8));
}
@Nullable
public PathRemainingMatchInfo getPathRemaining(String path) {
return getPathRemaining(PathContainer.parse(path, StandardCharsets.UTF_8));
}
/**
* @param pathContainer the candidate path container to attempt to match against this pattern
* @return true if the path matches this pattern
@@ -262,13 +246,6 @@ public class PathPattern implements Comparable<PathPattern> {
}
}
// TODO: implement extractPathWithinPattern natively for PathContainer
public PathContainer extractPathWithinPattern(PathContainer path) {
String result = extractPathWithinPattern(path.value());
return PathContainer.parse(result, StandardCharsets.UTF_8);
}
/**
* Given a full path, determine the pattern-mapped part. <p>For example: <ul>
* <li>'{@code /docs/cvs/commit.html}' and '{@code /docs/cvs/commit.html} -> ''</li>
@@ -283,7 +260,14 @@ public class PathPattern implements Comparable<PathPattern> {
* @param path a path that matches this pattern
* @return the subset of the path that is matched by pattern or "" if none of it is matched by pattern elements
*/
public String extractPathWithinPattern(String path) {
public PathContainer extractPathWithinPattern(PathContainer path) {
String result = extractPathWithinPattern(path.value());
return PathContainer.parse(result, StandardCharsets.UTF_8);
}
// TODO: implement extractPathWithinPattern natively for PathContainer
private String extractPathWithinPattern(String path) {
// assert this.matches(path)
PathElement elem = head;
int separatorCount = 0;
@@ -517,7 +501,7 @@ public class PathPattern implements Comparable<PathPattern> {
}
/**
* A holder for the result of a {@link PathPattern#getPathRemaining(String)} call. Holds
* A holder for the result of a {@link PathPattern#getPathRemaining} call.Holds
* information on the path left after the first part has successfully matched a pattern
* and any variables bound in that first part that matched.
*/