Example usage for org.springframework.web.servlet.resource ResourceResolverChain resolveUrlPath

List of usage examples for org.springframework.web.servlet.resource ResourceResolverChain resolveUrlPath

Introduction

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

Prototype

@Nullable
String resolveUrlPath(String resourcePath, List<? extends Resource> locations);

Source Link

Document

Resolve the externally facing public URL path for clients to use to access the resource that is located at the given internal resource path.

Usage

From source file:de.codecentric.boot.admin.web.servlet.resource.ConcatenatingResourceResolver.java

@Override
protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations,
        ResourceResolverChain chain) {
    return chain.resolveUrlPath(resourceUrlPath, locations);
}

From source file:de.codecentric.boot.admin.web.servlet.resource.ConcatenatingResourceResolverTest.java

@Test
public void test_resolveUrl() {
    ResourceResolverChain chain = mock(ResourceResolverChain.class);
    when(chain.resolveUrlPath(null, null)).thenReturn("/resources/resource.txt");
    String url = new ConcatenatingResourceResolver(";".getBytes()).resolveUrlPath(null, null, chain);
    assertThat(url, is("/resources/resource.txt"));
}

From source file:com.foilen.smalltools.spring.resourceresolver.BundleResourceResolver.java

@Override
public String resolveUrlPath(String resourcePath, List<? extends Resource> locations,
        ResourceResolverChain chain) {
    if (resourcesByBundleName.containsKey(resourcePath)) {
        return resourcePath;
    }/* w  ww  . ja v a  2  s .  c o m*/

    return chain.resolveUrlPath(resourcePath, locations);
}

From source file:org.broadleafcommerce.common.resource.service.ResourceBundlingServiceImpl.java

@Override
public String resolveBundleResourceName(String requestedBundleName, String mappingPrefix, List<String> files) {

    ResourceHttpRequestHandler resourceRequestHandler = findResourceHttpRequestHandler(requestedBundleName);
    if (resourceRequestHandler != null && CollectionUtils.isNotEmpty(files)) {
        ResourceResolverChain resolverChain = new BroadleafDefaultResourceResolverChain(
                resourceRequestHandler.getResourceResolvers());
        List<Resource> locations = resourceRequestHandler.getLocations();

        StringBuilder combinedPathString = new StringBuilder();
        List<String> filePaths = new ArrayList<String>();
        for (String file : files) {
            String resourcePath = resolverChain.resolveUrlPath(file, locations);
            if (resourcePath == null) {
                // can't find the exact name specified in the bundle, try it with the mappingPrefix
                resourcePath = resolverChain.resolveUrlPath(mappingPrefix + file, locations);
            }/*from ww  w . ja v  a2s  .  c om*/

            if (resourcePath != null) {
                filePaths.add(resourcePath);
                combinedPathString.append(resourcePath);
            } else {
                LOG.warn(new StringBuilder().append("Could not resolve resource path specified in bundle as [")
                        .append(file).append("] or as [").append(mappingPrefix + file)
                        .append("]. Skipping file.").toString());
            }
        }

        int version = Math.abs(combinedPathString.toString().hashCode());
        String versionedBundleName = mappingPrefix
                + addVersion(requestedBundleName, "-" + String.valueOf(version));

        createBundleIfNeeded(versionedBundleName, filePaths, resolverChain, locations);

        return versionedBundleName;
    } else {
        if (LOG.isWarnEnabled()) {
            LOG.warn("");
        }
        return null;
    }
}

From source file:org.broadleafcommerce.common.web.resource.resolver.BLCJSUrlPathResolver.java

@Override
protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations,
        ResourceResolverChain chain) {
    if (resourceUrlPath.contains(BLC_JS_NAME)) {
        Site site = BroadleafRequestContext.getBroadleafRequestContext().getNonPersistentSite();
        if (site != null && site.getId() != null) {
            return addVersion(resourceUrlPath, "-" + site.getId());
        } else {/*  www.j a  v a 2s.c  om*/
            return resourceUrlPath;
        }
    }
    return chain.resolveUrlPath(resourceUrlPath, locations);
}

From source file:org.broadleafcommerce.common.web.resource.resolver.BroadleafCachingResourceResolver.java

@Override
protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations,
        ResourceResolverChain chain) {
    if (resourceCachingEnabled) {
        String key = RESOLVED_URL_PATH_CACHE_KEY_PREFIX_NULL + resourceUrlPath;
        Object nullResource = getCache().get(key, Object.class);
        if (nullResource != null) {
            if (logger.isTraceEnabled()) {
                logger.trace(String.format("Found null reference url path match for '%s'", resourceUrlPath));
            }//ww  w. j a  va 2s  . c om
            return null;
        } else {
            String response = super.resolveUrlPathInternal(resourceUrlPath, locations, chain);
            if (response == null) {
                if (logger.isTraceEnabled()) {
                    logger.trace(String.format("Putting resolved null reference url path in cache for '%s'",
                            resourceUrlPath));
                }
                getCache().put(key, NULL_REFERENCE);
            }
            return response;
        }
    } else {
        return chain.resolveUrlPath(resourceUrlPath, locations);
    }
}

From source file:org.broadleafcommerce.common.web.resource.resolver.BroadleafVersionResourceResolver.java

@Override
protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations,
        ResourceResolverChain chain) {
    if (resourceVersioningEnabled && !bundlingService.checkForRegisteredBundleFile(resourceUrlPath)) {
        String result = super.resolveUrlPathInternal(resourceUrlPath, locations, chain);

        // Spring's default version handler will return null if it doesn't have a strategy
        // for that resource - that seems incorrect.   Overriding here.
        if (result == null) {
            return chain.resolveUrlPath(resourceUrlPath, locations);
        } else {//from  w w  w .  jav  a 2 s . c  om
            return result;
        }
    } else {
        return chain.resolveUrlPath(resourceUrlPath, locations);
    }
}

From source file:org.broadleafcommerce.common.web.resource.resolver.BundleResourceResolver.java

@Override
protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends Resource> locations,
        ResourceResolverChain chain) {
    if (resourceUrlPath != null) {
        if (isBundleFile(resourceUrlPath)) {
            return resourceUrlPath;
        }//from  w  ww  . j  a v a 2s .  c  om
    }

    return chain.resolveUrlPath(resourceUrlPath, locations);

}

From source file:org.broadleafcommerce.openadmin.web.resource.MessagesResourceResolver.java

@Override
public String resolveUrlPath(String resourcePath, List<? extends Resource> locations,
        ResourceResolverChain chain) {
    if (!MESSAGES_JS_PATH.equals(resourcePath)) {
        return chain.resolveUrlPath(resourcePath, locations);
    }// www. ja  v a 2 s.  co m
    return MESSAGES_JS_PATH;
}

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

@Override
public String getPublicUrlPath(String resourceUrlPath, List<Resource> locations, ResourceResolverChain chain) {
    String baseUrl = chain.resolveUrlPath(resourceUrlPath, locations);
    if (StringUtils.hasText(baseUrl)) {
        Resource original = chain.resolveResource(null, resourceUrlPath, locations);
        String hash = calculateHash(original);
        return StringUtils.stripFilenameExtension(baseUrl) + "-" + hash + "."
                + StringUtils.getFilenameExtension(baseUrl);
    }/*  w  w  w . ja v  a 2  s .  c  o m*/
    return baseUrl;
}