public class PatternsRequestCondition extends AbstractRequestCondition<PatternsRequestCondition>
Constructor and Description |
---|
PatternsRequestCondition(String... patterns)
Creates a new instance with the given URL patterns.
|
PatternsRequestCondition(String[] patterns,
UrlPathHelper urlPathHelper,
PathMatcher pathMatcher,
boolean useTrailingSlashMatch)
Alternative constructor with additional, optional
UrlPathHelper ,
PathMatcher , and whether to automatically match trailing slashes. |
PatternsRequestCondition(String[] patterns,
UrlPathHelper urlPathHelper,
PathMatcher pathMatcher,
boolean useSuffixPatternMatch,
boolean useTrailingSlashMatch)
Deprecated.
as of 5.2.4. See class-level note in
RequestMappingHandlerMapping
on the deprecation of path extension config options. |
PatternsRequestCondition(String[] patterns,
UrlPathHelper urlPathHelper,
PathMatcher pathMatcher,
boolean useSuffixPatternMatch,
boolean useTrailingSlashMatch,
List<String> fileExtensions)
Deprecated.
as of 5.2.4. See class-level note in
RequestMappingHandlerMapping
on the deprecation of path extension config options. |
Modifier and Type | Method and Description |
---|---|
PatternsRequestCondition |
combine(PatternsRequestCondition other)
Returns a new instance with URL patterns from the current instance ("this") and
the "other" instance as follows:
If there are patterns in both instances, combine the patterns in "this" with
the patterns in "other" using
PathMatcher.combine(String, String) . |
int |
compareTo(PatternsRequestCondition other,
HttpServletRequest request)
Compare the two conditions based on the URL patterns they contain.
|
protected Collection<String> |
getContent()
Return the discrete items a request condition is composed of.
|
PatternsRequestCondition |
getMatchingCondition(HttpServletRequest request)
Checks if any of the patterns match the given request and returns an instance
that is guaranteed to contain matching patterns, sorted via
PathMatcher.getPatternComparator(String) . |
List<String> |
getMatchingPatterns(String lookupPath)
Find the patterns matching the given lookup path.
|
Set<String> |
getPatterns() |
protected String |
getToStringInfix()
The notation to use when printing discrete items of content.
|
equals, hashCode, isEmpty, toString
public PatternsRequestCondition(String... patterns)
patterns
- 0 or more URL patterns; if 0 the condition will match to
every request.public PatternsRequestCondition(String[] patterns, @Nullable UrlPathHelper urlPathHelper, @Nullable PathMatcher pathMatcher, boolean useTrailingSlashMatch)
UrlPathHelper
,
PathMatcher
, and whether to automatically match trailing slashes.patterns
- the URL patterns to use; if 0, the condition will match to every request.urlPathHelper
- a UrlPathHelper
for determining the lookup path for a requestpathMatcher
- a PathMatcher
for pattern path matchinguseTrailingSlashMatch
- whether to match irrespective of a trailing slash@Deprecated public PatternsRequestCondition(String[] patterns, @Nullable UrlPathHelper urlPathHelper, @Nullable PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch)
RequestMappingHandlerMapping
on the deprecation of path extension config options.patterns
- the URL patterns to use; if 0, the condition will match to every request.urlPathHelper
- for determining the lookup path of a requestpathMatcher
- for path matching with patternsuseSuffixPatternMatch
- whether to enable matching by suffix (".*")useTrailingSlashMatch
- whether to match irrespective of a trailing slash@Deprecated public PatternsRequestCondition(String[] patterns, @Nullable UrlPathHelper urlPathHelper, @Nullable PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch, @Nullable List<String> fileExtensions)
RequestMappingHandlerMapping
on the deprecation of path extension config options.patterns
- the URL patterns to use; if 0, the condition will match to every request.urlPathHelper
- a UrlPathHelper
for determining the lookup path for a requestpathMatcher
- a PathMatcher
for pattern path matchinguseSuffixPatternMatch
- whether to enable matching by suffix (".*")useTrailingSlashMatch
- whether to match irrespective of a trailing slashfileExtensions
- a list of file extensions to consider for path matchingprotected Collection<String> getContent()
AbstractRequestCondition
For example URL patterns, HTTP request methods, param expressions, etc.
getContent
in class AbstractRequestCondition<PatternsRequestCondition>
null
)protected String getToStringInfix()
AbstractRequestCondition
For example " || "
for URL patterns or " && "
for param expressions.
getToStringInfix
in class AbstractRequestCondition<PatternsRequestCondition>
public PatternsRequestCondition combine(PatternsRequestCondition other)
PathMatcher.combine(String, String)
.
other
- the condition to combine with.@Nullable public PatternsRequestCondition getMatchingCondition(HttpServletRequest request)
PathMatcher.getPatternComparator(String)
.
A matching pattern is obtained by making checks in the following order:
request
- the current requestnull
if no patterns match.public List<String> getMatchingPatterns(String lookupPath)
getMatchingCondition(javax.servlet.http.HttpServletRequest)
.
This method is provided as an alternative to be used if no request is available
(e.g. introspection, tooling, etc).lookupPath
- the lookup path to match to existing patternspublic int compareTo(PatternsRequestCondition other, HttpServletRequest request)
PathMatcher.getPatternComparator(String)
. 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.