Example usage for org.springframework.web.context.support ServletContextResource getServletContext

List of usage examples for org.springframework.web.context.support ServletContextResource getServletContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support ServletContextResource getServletContext.

Prototype

public final ServletContext getServletContext() 

Source Link

Document

Return the ServletContext for this resource.

Usage

From source file:org.springframework.web.context.support.ServletContextResourcePatternResolver.java

/**
 * Overridden version which checks for ServletContextResource
 * and uses {@code ServletContext.getResourcePaths} to find
 * matching resources below the web application root directory.
 * In case of other resources, delegates to the superclass version.
 * @see #doRetrieveMatchingServletContextResources
 * @see ServletContextResource//from   w  ww .  ja v a2  s  . c om
 * @see javax.servlet.ServletContext#getResourcePaths
 */
@Override
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
        throws IOException {

    if (rootDirResource instanceof ServletContextResource) {
        ServletContextResource scResource = (ServletContextResource) rootDirResource;
        ServletContext sc = scResource.getServletContext();
        String fullPattern = scResource.getPath() + subPattern;
        Set<Resource> result = new LinkedHashSet<>(8);
        doRetrieveMatchingServletContextResources(sc, fullPattern, scResource.getPath(), result);
        return result;
    } else {
        return super.doFindPathMatchingFileResources(rootDirResource, subPattern);
    }
}