public Optional < URL > resolve ( String resourcePath ) { for ( Map . Entry < String , List < ResourceLoader > > entry : resourceMappings . entrySet ( ) ) { List < ResourceLoader > loaders = entry . getValue ( ) ; String mapping = entry . getKey ( ) ; if ( ! loaders . isEmpty ( ) && pathMatcher . matches ( mapping , resourcePath ) ) { String path = pathMatcher . extractPathWithinPattern ( mapping , resourcePath ) ; //A request to the root of the mapping if ( StringUtils . isEmpty ( path ) ) { path = INDEX_PAGE ; } if ( path . startsWith ( "/" ) ) { path = path . substring ( 1 ) ; } for ( ResourceLoader loader : loaders ) { Optional < URL > resource = loader . getResource ( path ) ; if ( resource . isPresent ( ) ) { return resource ; } else { if ( path . indexOf ( ' ' ) == - 1 ) { if ( ! path . endsWith ( "/" ) ) { path = path + "/" ; } path += INDEX_PAGE ; resource = loader . getResource ( path ) ; if ( resource . isPresent ( ) ) { return resource ; } } } } } } return Optional . empty ( ) ; }
Resolves a path to a URL .