org.springframework.web.servlet.mvc.condition

Class PatternsRequestCondition

    • 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 prepended with "/".
        Parameters:
        patterns - 0 or more URL patterns; if 0 the condition will match to every request.
      • PatternsRequestCondition

        public PatternsRequestCondition(java.lang.String[] patterns,
                                        @Nullable
                                        UrlPathHelper urlPathHelper,
                                        @Nullable
                                        PathMatcher pathMatcher,
                                        boolean useSuffixPatternMatch,
                                        boolean useTrailingSlashMatch)
        Additional constructor with flags for using suffix pattern (.*) and trailing slash matches.
        Parameters:
        patterns - the URL patterns to use; if 0, the condition will match to every request.
        urlPathHelper - for determining the lookup path of a request
        pathMatcher - for path matching with patterns
        useSuffixPatternMatch - whether to enable matching by suffix (".*")
        useTrailingSlashMatch - whether to match irrespective of a trailing slash
      • PatternsRequestCondition

        public PatternsRequestCondition(java.lang.String[] patterns,
                                        @Nullable
                                        UrlPathHelper urlPathHelper,
                                        @Nullable
                                        PathMatcher pathMatcher,
                                        boolean useSuffixPatternMatch,
                                        boolean useTrailingSlashMatch,
                                        @Nullable
                                        java.util.List<java.lang.String> fileExtensions)
        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 (".*")
        useTrailingSlashMatch - whether to match irrespective of a trailing slash
        fileExtensions - a list of file extensions to consider for path matching
    • Method Detail

      • getPatterns

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

        public 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).
        • If only one instance has patterns, use them.
        • If neither instance has patterns, use an empty String (i.e. "").
        Parameters:
        other - the condition to combine with.
        Returns:
        a request condition instance that is the result of combining the two condition instances.
      • getMatchingCondition

        @Nullable
        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:

        • Direct match
        • Pattern match with ".*" appended if the pattern doesn't already contain a "."
        • Pattern match
        • Pattern match with "/" appended if the pattern doesn't already end in "/"
        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.
      • getMatchingPatterns

        public java.util.List<java.lang.String> getMatchingPatterns(java.lang.String lookupPath)
        Find the patterns matching the given lookup path. Invoking this method should yield results equivalent to those of calling 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).
        Parameters:
        lookupPath - the lookup path to match to existing patterns
        Returns:
        a collection of matching patterns sorted with the closest match at the top