org.springframework.web.servlet.mvc.condition
Class PatternsRequestCondition

java.lang.Object
  extended by org.springframework.web.servlet.mvc.condition.AbstractRequestCondition<PatternsRequestCondition>
      extended by org.springframework.web.servlet.mvc.condition.PatternsRequestCondition
All Implemented Interfaces:
RequestCondition<PatternsRequestCondition>

public final class PatternsRequestCondition
extends AbstractRequestCondition<PatternsRequestCondition>

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

Since:
3.1
Author:
Rossen Stoyanchev

Field Summary
private  PathMatcher pathMatcher
           
private  java.util.Set<java.lang.String> patterns
           
private  UrlPathHelper urlPathHelper
           
private  boolean useSuffixPatternMatch
           
 
Constructor Summary
private PatternsRequestCondition(java.util.Collection<java.lang.String> patterns, UrlPathHelper urlPathHelper, PathMatcher pathMatcher, boolean useSuffixPatternMatch)
          Private constructor accepting a collection of patterns.
  PatternsRequestCondition(java.lang.String... patterns)
          Creates a new instance with the given URL patterns.
  PatternsRequestCondition(java.lang.String[] patterns, UrlPathHelper urlPathHelper, PathMatcher pathMatcher, boolean useSuffixPatternMatch)
          Creates a new instance with the given URL patterns.
 
Method Summary
private static java.util.List<java.lang.String> asList(java.lang.String... patterns)
           
 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  java.util.Collection<java.lang.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).
private  java.lang.String getMatchingPattern(java.lang.String pattern, java.lang.String lookupPath)
           
 java.util.Set<java.lang.String> getPatterns()
           
protected  java.lang.String getToStringInfix()
          The notation to use when printing discrete items of content.
private static java.util.Set<java.lang.String> prependLeadingSlash(java.util.Collection<java.lang.String> patterns)
           
 
Methods inherited from class org.springframework.web.servlet.mvc.condition.AbstractRequestCondition
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

patterns

private final java.util.Set<java.lang.String> patterns

urlPathHelper

private final UrlPathHelper urlPathHelper

pathMatcher

private final PathMatcher pathMatcher

useSuffixPatternMatch

private final boolean useSuffixPatternMatch
Constructor Detail

PatternsRequestCondition

public PatternsRequestCondition(java.lang.String... patterns)
Creates a new instance with the given URL patterns. Each pattern that is not empty and does not start with "/" is pre-pended with "/".

Parameters:
patterns - 0 or more URL patterns; if 0 the condition will match to every request.

PatternsRequestCondition

public PatternsRequestCondition(java.lang.String[] patterns,
                                UrlPathHelper urlPathHelper,
                                PathMatcher pathMatcher,
                                boolean useSuffixPatternMatch)
Creates a new instance with the given URL patterns. Each pattern that is not empty and does not start with "/" is pre-pended with "/".

Parameters:
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 request
pathMatcher - a PathMatcher for pattern path matching
useSuffixPatternMatch - whether to enable matching by suffix (".*")

PatternsRequestCondition

private PatternsRequestCondition(java.util.Collection<java.lang.String> patterns,
                                 UrlPathHelper urlPathHelper,
                                 PathMatcher pathMatcher,
                                 boolean useSuffixPatternMatch)
Private constructor accepting a collection of patterns.

Method Detail

asList

private static java.util.List<java.lang.String> asList(java.lang.String... patterns)

prependLeadingSlash

private static java.util.Set<java.lang.String> prependLeadingSlash(java.util.Collection<java.lang.String> patterns)

getPatterns

public java.util.Set<java.lang.String> getPatterns()

getContent

protected java.util.Collection<java.lang.String> getContent()
Description copied from class: AbstractRequestCondition
Return the discrete items a request condition is composed of. For example URL patterns, HTTP request methods, param expressions, etc.

Specified by:
getContent in class AbstractRequestCondition<PatternsRequestCondition>
Returns:
a collection of objects, never null

getToStringInfix

protected java.lang.String getToStringInfix()
Description copied from class: AbstractRequestCondition
The notation to use when printing discrete items of content. For example " || " for URL patterns or " && " for param expressions.

Specified by:
getToStringInfix in class AbstractRequestCondition<PatternsRequestCondition>

combine

public PatternsRequestCondition combine(PatternsRequestCondition other)
Returns a new instance with URL patterns from the current instance ("this") and the "other" instance as follows:

Parameters:
other - the condition to combine with.

getMatchingCondition

public 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).

A matching pattern is obtained by making checks in the following order:

Parameters:
request - the current request
Returns:
the same instance if the condition contains no patterns; or a new condition with sorted matching patterns; or null if no patterns match.

getMatchingPattern

private java.lang.String getMatchingPattern(java.lang.String pattern,
                                            java.lang.String lookupPath)

compareTo

public int compareTo(PatternsRequestCondition other,
                     HttpServletRequest request)
Compare the two conditions based on the URL patterns they contain. Patterns are compared one at a time, from top to bottom via 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.