From 801237aec1aba0a2fb8d666fa2d0313dac4aa3aa Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 27 Feb 2014 16:27:40 -0500 Subject: [PATCH] Add getMatchingPatterns method to Patterns condition Issue: SPR-11484 --- .../condition/PatternsRequestCondition.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java index 69f10ad3bc..4ccd60391e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java @@ -201,11 +201,30 @@ public final class PatternsRequestCondition extends AbstractRequestCondition matches = getMatchingPatterns(lookupPath); + + return matches.isEmpty() ? null : + new PatternsRequestCondition(matches, this.pathHelper, this.pathMatcher, this.useSuffixPatternMatch, + this.useTrailingSlashMatch, this.fileExtensions); + } + + /** + * Find the patterns matching the given lookup path. Invoking this method should + * yield results equivalent to those of calling + * {@link #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). + * + * @param lookupPath the lookup path to match to existing patterns + * @return a collection of matching patterns sorted with the closest match at the top + */ + public List getMatchingPatterns(String lookupPath) { List matches = new ArrayList(); for (String pattern : this.patterns) { String match = getMatchingPattern(pattern, lookupPath); @@ -214,9 +233,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition