use of cn.taketoday.web.util.pattern.PathPattern in project today-infrastructure by TAKETODAY.
the class PathPatternsRequestCondition method getMatchingCondition.
/**
* Checks if any of the patterns match the given request and returns an
* instance that is guaranteed to contain matching patterns, sorted.
*
* @param request the current request
* @return the same instance if the condition contains no patterns;
* or a new condition with sorted matching patterns;
* or {@code null} if no patterns match.
*/
@Override
@Nullable
public PathPatternsRequestCondition getMatchingCondition(RequestContext request) {
PathContainer path = request.getLookupPath().pathWithinApplication();
SortedSet<PathPattern> matches = getMatchingPatterns(path);
return matches != null ? new PathPatternsRequestCondition(matches) : null;
}
use of cn.taketoday.web.util.pattern.PathPattern in project today-infrastructure by TAKETODAY.
the class PathPatternsRequestCondition method getMatchingPatterns.
@Nullable
private SortedSet<PathPattern> getMatchingPatterns(PathContainer path) {
TreeSet<PathPattern> result = null;
for (PathPattern pattern : this.patterns) {
if (pattern.matches(path)) {
result = (result != null ? result : new TreeSet<>());
result.add(pattern);
}
}
return result;
}
use of cn.taketoday.web.util.pattern.PathPattern in project today-infrastructure by TAKETODAY.
the class HandlerMatchingMetadata method getBestMatchingPattern.
public PathPattern getBestMatchingPattern() {
PathPattern bestMatchingPattern = this.bestMatchingPattern;
if (bestMatchingPattern == null) {
bestMatchingPattern = patternParser.parse(directPath);
this.bestMatchingPattern = bestMatchingPattern;
}
return bestMatchingPattern;
}
use of cn.taketoday.web.util.pattern.PathPattern in project today-framework by TAKETODAY.
the class PathVariableMapMethodArgumentResolverTests method resolveArgument.
@Test
public void resolveArgument() throws Throwable {
applyTemplateVars();
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("name1", "value1");
uriTemplateVars.put("name2", "value2");
RequestPath requestPath = RequestPath.parse("/mock/value1/value2", null);
PathPattern pathPattern = PathPatternParser.defaultInstance.parse("/mock/{name1}/{name2}");
HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(new Object(), "/mock", requestPath, pathPattern, PathPatternParser.defaultInstance);
webRequest.setMatchingMetadata(matchingMetadata);
Object result = resolver.resolveArgument(webRequest, paramMap);
assertThat(result).isEqualTo(uriTemplateVars);
}
use of cn.taketoday.web.util.pattern.PathPattern in project today-framework by TAKETODAY.
the class HandlerMatchingMetadata method getBestMatchingPattern.
public PathPattern getBestMatchingPattern() {
PathPattern bestMatchingPattern = this.bestMatchingPattern;
if (bestMatchingPattern == null) {
bestMatchingPattern = patternParser.parse(directPath);
this.bestMatchingPattern = bestMatchingPattern;
}
return bestMatchingPattern;
}
Aggregations