Add helper method to ResourceHandlerRegistry

This commit is contained in:
Rossen Stoyanchev
2013-10-15 09:44:13 -04:00
parent 079bebcfb5
commit 190bf247a3
2 changed files with 23 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.web.servlet.config.annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -64,6 +65,7 @@ public class ResourceHandlerRegistry {
this.servletContext = servletContext;
}
/**
* Add a resource handler for serving static resources based on the specified URL path patterns.
* The handler will be invoked for every incoming request that matches to one of the specified path patterns.
@@ -75,6 +77,18 @@ public class ResourceHandlerRegistry {
return registration;
}
/**
* Whether a resource handler has already been registered for the given pathPattern.
*/
public boolean hasMappingForPattern(String pathPattern) {
for (ResourceHandlerRegistration registration : registrations) {
if (Arrays.asList(registration.getPathPatterns()).contains(pathPattern)) {
return true;
}
}
return false;
}
/**
* Specify the order to use for resource handling relative to other {@link HandlerMapping}s configured in
* the Spring MVC application context. The default value used is {@code Integer.MAX_VALUE-1}.