Example usage for org.springframework.web.servlet.resource PathResourceResolver getAllowedLocations

List of usage examples for org.springframework.web.servlet.resource PathResourceResolver getAllowedLocations

Introduction

In this page you can find the example usage for org.springframework.web.servlet.resource PathResourceResolver getAllowedLocations.

Prototype

@Nullable
    public Resource[] getAllowedLocations() 

Source Link

Usage

From source file:org.springframework.web.servlet.resource.ResourceHttpRequestHandler.java

/**
 * Look for a {@code PathResourceResolver} among the configured resource
 * resolvers and set its {@code allowedLocations} property (if empty) to
 * match the {@link #setLocations locations} configured on this class.
 *//*from   w w  w . j ava  2  s .c o m*/
protected void initAllowedLocations() {
    if (CollectionUtils.isEmpty(this.locations)) {
        return;
    }
    for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
        if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
            PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
            if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
                pathResolver.setAllowedLocations(getLocations().toArray(new Resource[getLocations().size()]));
            }
            if (this.urlPathHelper != null) {
                pathResolver.setLocationCharsets(this.locationCharsets);
                pathResolver.setUrlPathHelper(this.urlPathHelper);
            }
            break;
        }
    }
}