Top Description Fields Constructors Methods
org.springframework.web.servlet.mvc.condition

public final Class PathPatternsRequestCondition

extends AbstractRequestCondition<PathPatternsRequestCondition>
Class Inheritance
Imports
java.util.Collection, .Collections, .HashSet, .Iterator, .List, .Set, .SortedSet, .TreeSet, java.util.stream.Collectors, jakarta.servlet.http.HttpServletRequest, org.springframework.http.server.PathContainer, org.springframework.lang.Nullable, org.springframework.util.StringUtils, org.springframework.web.util.ServletRequestPathUtils, org.springframework.web.util.pattern.PathPattern, .PathPatternParser

A logical disjunction (' || ') request condition that matches a request against a set of URL path patterns.

In contrast to PatternsRequestCondition, this condition uses parsed PathPatterns instead of String pattern matching with AntPathMatcher.

Author
Rossen Stoyanchev
Since
5.3

Field Summary

Modifier and TypeField and Description
private static final Set<String>
private static final SortedSet<PathPattern>
private final SortedSet<PathPattern>
private static final SortedSet<PathPattern>

Constructor Summary

AccessConstructor and Description
public
PathPatternsRequestCondition()

Default constructor resulting in an "" (empty path) mapping.

public
PathPatternsRequestCondition(PathPatternParser parser, String... patterns)

Constructor with patterns to use.

private

Method Summary

Modifier and TypeMethod and Description
public PathPatternsRequestCondition
combine(PathPatternsRequestCondition
the condition to combine with.
other
)

Implements org.springframework.web.servlet.mvc.condition.RequestCondition.combine.

Combine the patterns of the current and of the other instances as follows:

  • If only one instance has patterns, use those.
  • If both have patterns, combine patterns from "this" instance with patterns from the other instance via PathPattern#combine(PathPattern).
  • If neither has patterns, use "" and "/" as root path patterns.
public int
compareTo(PathPatternsRequestCondition other, HttpServletRequest request)

Implements org.springframework.web.servlet.mvc.condition.RequestCondition.compareTo.

Compare the two conditions based on the URL patterns they contain.

protected Collection<PathPattern>
getContent()

Implements abstract org.springframework.web.servlet.mvc.condition.AbstractRequestCondition.getContent.

Return the discrete items a request condition is composed of.

public Set<String>
getDirectPaths()

Return the mapping paths that are not patterns.

public PathPattern
getFirstPattern()

Return the first pattern.

public PathPatternsRequestCondition

Returns:

the same instance if the condition contains no patterns; or a new condition with sorted matching patterns; or null if no patterns match.
getMatchingCondition
(HttpServletRequest
the current request
request
)

Implements org.springframework.web.servlet.mvc.condition.RequestCondition.getMatchingCondition.

Checks if any of the patterns match the given request and returns an instance that is guaranteed to contain matching patterns, sorted.

private SortedSet<PathPattern>
public Set<PathPattern>
getPatterns()

Return the patterns in this condition.

public Set<String>
getPatternValues()

Return the getPatterns() mapped to Strings.

protected String
getToStringInfix()

Implements abstract org.springframework.web.servlet.mvc.condition.AbstractRequestCondition.getToStringInfix.

The notation to use when printing discrete items of content.

public boolean
isEmptyPathMapping()

Whether the condition is the "" (empty path) mapping.

private static SortedSet<PathPattern>
parse(PathPatternParser parser, String... patterns)

Inherited from org.springframework.web.servlet.mvc.condition.AbstractRequestCondition:
equalshashCodeisEmptytoString

Field Detail

EMPTY_PATHback to summary
private static final Set<String> EMPTY_PATH
EMPTY_PATH_PATTERNback to summary
private static final SortedSet<PathPattern> EMPTY_PATH_PATTERN
patternsback to summary
private final SortedSet<PathPattern> patterns
ROOT_PATH_PATTERNSback to summary
private static final SortedSet<PathPattern> ROOT_PATH_PATTERNS

Constructor Detail

PathPatternsRequestConditionback to summary
public PathPatternsRequestCondition()

Default constructor resulting in an "" (empty path) mapping.

PathPatternsRequestConditionback to summary
public PathPatternsRequestCondition(PathPatternParser parser, String... patterns)

Constructor with patterns to use.

PathPatternsRequestConditionback to summary
private PathPatternsRequestCondition(SortedSet<PathPattern> patterns)

Method Detail

combineback to summary
public PathPatternsRequestCondition combine(PathPatternsRequestCondition other)

Implements org.springframework.web.servlet.mvc.condition.RequestCondition.combine.

Combine the patterns of the current and of the other instances as follows:

  • If only one instance has patterns, use those.
  • If both have patterns, combine patterns from "this" instance with patterns from the other instance via PathPattern#combine(PathPattern).
  • If neither has patterns, use "" and "/" as root path patterns.
Parameters
other:PathPatternsRequestCondition

Doc from org.springframework.web.servlet.mvc.condition.RequestCondition.combine.

the condition to combine with.

Returns:PathPatternsRequestCondition

Doc from org.springframework.web.servlet.mvc.condition.RequestCondition.combine.

a request condition instance that is the result of combining the two condition instances.

Annotations
@Override
compareToback to summary
public int compareTo(PathPatternsRequestCondition other, HttpServletRequest request)

Implements org.springframework.web.servlet.mvc.condition.RequestCondition.compareTo.

Compare the two conditions based on the URL patterns they contain. Patterns are compared one at a time, from top to bottom. If all compared patterns match equally, but one instance has more patterns, it is considered a closer match.

It is assumed that both instances have been obtained via getMatchingCondition(HttpServletRequest) to ensure they contain only patterns that match the request and are sorted with the best matches on top.

Annotations
@Override
getContentback to summary
protected Collection<PathPattern> getContent()

Implements abstract org.springframework.web.servlet.mvc.condition.AbstractRequestCondition.getContent.

Doc from org.springframework.web.servlet.mvc.condition.AbstractRequestCondition.getContent.

Return the discrete items a request condition is composed of.

For example URL patterns, HTTP request methods, param expressions, etc.

Returns:Collection<PathPattern>

a collection of objects (never null)

Annotations
@Override
getDirectPathsback to summary
public Set<String> getDirectPaths()

Return the mapping paths that are not patterns.

getFirstPatternback to summary
public PathPattern getFirstPattern()

Return the first pattern.

getMatchingConditionback to summary
public PathPatternsRequestCondition getMatchingCondition(HttpServletRequest request)

Implements org.springframework.web.servlet.mvc.condition.RequestCondition.getMatchingCondition.

Checks if any of the patterns match the given request and returns an instance that is guaranteed to contain matching patterns, sorted.

Parameters
request:HttpServletRequest

the current request

Returns:PathPatternsRequestCondition

the same instance if the condition contains no patterns; or a new condition with sorted matching patterns; or null if no patterns match.

Annotations
@Override
@Nullable
getMatchingPatternsback to summary
private SortedSet<PathPattern> getMatchingPatterns(PathContainer path)
Annotations
@Nullable
getPatternsback to summary
public Set<PathPattern> getPatterns()

Return the patterns in this condition. If only the first (top) pattern is needed use getFirstPattern().

getPatternValuesback to summary
public Set<String> getPatternValues()

Return the getPatterns() mapped to Strings.

getToStringInfixback to summary
protected String getToStringInfix()

Implements abstract org.springframework.web.servlet.mvc.condition.AbstractRequestCondition.getToStringInfix.

Doc from org.springframework.web.servlet.mvc.condition.AbstractRequestCondition.getToStringInfix.

The notation to use when printing discrete items of content.

For example " || " for URL patterns or " && " for param expressions.

Annotations
@Override
isEmptyPathMappingback to summary
public boolean isEmptyPathMapping()

Whether the condition is the "" (empty path) mapping.

parseback to summary
private static SortedSet<PathPattern> parse(PathPatternParser parser, String... patterns)