Search in sources :

Example 1 with PathPattern

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;
}
Also used : PathContainer(cn.taketoday.http.server.PathContainer) PathPattern(cn.taketoday.web.util.pattern.PathPattern) Nullable(cn.taketoday.lang.Nullable)

Example 2 with PathPattern

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;
}
Also used : PathPattern(cn.taketoday.web.util.pattern.PathPattern) Nullable(cn.taketoday.lang.Nullable)

Example 3 with PathPattern

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;
}
Also used : PathPattern(cn.taketoday.web.util.pattern.PathPattern)

Example 4 with PathPattern

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);
}
Also used : RequestPath(cn.taketoday.http.server.RequestPath) PathPattern(cn.taketoday.web.util.pattern.PathPattern) HashMap(java.util.HashMap) HandlerMatchingMetadata(cn.taketoday.web.HandlerMatchingMetadata) Test(org.junit.jupiter.api.Test)

Example 5 with PathPattern

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;
}
Also used : PathPattern(cn.taketoday.web.util.pattern.PathPattern)

Aggregations

PathPattern (cn.taketoday.web.util.pattern.PathPattern)15 RequestPath (cn.taketoday.http.server.RequestPath)6 HandlerMatchingMetadata (cn.taketoday.web.HandlerMatchingMetadata)4 Nullable (cn.taketoday.lang.Nullable)3 PathContainer (cn.taketoday.http.server.PathContainer)2 PathMatchInfo (cn.taketoday.web.util.pattern.PathMatchInfo)2 ActionMappingAnnotationHandler (cn.taketoday.web.handler.method.ActionMappingAnnotationHandler)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1