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

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

Introduction

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

Prototype

@Nullable
Resource resolveResource(@Nullable HttpServletRequest request, String requestPath,
        List<? extends Resource> locations);

Source Link

Document

Resolve the supplied request and request path to a Resource that exists under one of the given resource locations.

Usage

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

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {
    try {//from  w w w . j  a va  2s .c  o m
        Resource[] resources = resourcePatternResolver.getResources(pattern);
        return chain.resolveResource(request, requestPath, Arrays.asList(resources));
    } catch (IOException ex) {
        throw new ResourceAccessException("Couldn't resolve resources for \"" + pattern + "\"", ex);
    }
}

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

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {
    List<Resource> newLocations = new ArrayList<Resource>(locations.size());

    for (Resource location : locations) {
        Resource minified = findMinified(location);
        newLocations.add(minified != null ? minified : location);
    }/*from   w w w .  j  a  v a 2s  . c o  m*/

    return chain.resolveResource(request, requestPath, newLocations);
}

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

@Override
public Resource resolveResource(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {

    // Check if exists
    List<String> resources = resourcesByBundleName.get(requestPath);
    if (resources == null) {
        return chain.resolveResource(request, requestPath, locations);
    }/*from ww  w  . jav  a  2 s. c  om*/

    try {
        return cachedResources.get(requestPath);
    } catch (ExecutionException e) {
        logger.error("Could not retrieve the bundle {}", requestPath, e);
        return null;
    }

}

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

protected Resource createBundle(String versionedBundleName, List<String> filePaths,
        ResourceResolverChain resolverChain, List<Resource> locations) {

    HttpServletRequest req = BroadleafRequestContext.getBroadleafRequestContext().getRequest();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] bytes = null;

    // Join all of the resources for this bundle together into a byte[]
    try {/*from  w  w  w  .jav  a2  s . c o  m*/
        for (String fileName : filePaths) {
            Resource r = resolverChain.resolveResource(req, fileName, locations);
            InputStream is = null;

            if (r == null) {
                LOG.warn(new StringBuilder().append("Could not resolve resource specified in bundle as [")
                        .append(fileName)
                        .append("]. Turn on trace logging to determine resolution failure. Skipping file.")
                        .toString());
            } else {
                try {
                    is = r.getInputStream();
                    StreamUtils.copy(is, baos);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    IOUtils.closeQuietly(is);
                }

                // If we're creating a JavaScript bundle, we'll put a semicolon between each
                // file to ensure it won't fail to compile.
                if (versionedBundleName.endsWith(".js")) {
                    baos.write(";".getBytes());
                }
                baos.write(System.getProperty("line.separator").getBytes());
            }
        }
        bytes = baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(baos);
    }

    // Create our GenerateResource that holds our combined bundle
    GeneratedResource r = new GeneratedResource(bytes, versionedBundleName);
    return r;
}

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

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {
    if (requestPath != null && requestPath.contains("BLC")) {
        Matcher matcher = pattern.matcher(requestPath);
        if (matcher.find()) {
            requestPath = matcher.group(1) + "BLC.js";
            Resource resource = chain.resolveResource(request, "BLC.js", locations);
            if (resource == null) {
                requestPath = matcher.group(1) + "BLC.js";
                resource = chain.resolveResource(request, requestPath, locations);
            }//from   ww w . ja  v a 2s.c o  m

            try {
                resource = convertResource(resource, requestPath);
            } catch (IOException ioe) {
                LOG.error("Exception modifying " + BLC_JS_NAME, ioe);
            }
            return resource;
        }
    }
    return chain.resolveResource(request, requestPath, locations);
}

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

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {
    return chain.resolveResource(request, requestPath, locations);
}

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

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {

    Resource resource = chain.resolveResource(request, requestPath, locations);

    if (requestPath.equalsIgnoreCase(BLC_SYSTEM_PROPERTY_FILE)) {
        try {//from  w  w  w . ja  va 2s .c  om
            resource = convertResource(resource, requestPath);
        } catch (IOException ioe) {
            LOG.error("Exception modifying " + BLC_SYSTEM_PROPERTY_FILE, ioe);
        }
    }

    return resource;
}

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

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {
    if (resourceCachingEnabled) {
        Resource resource = super.resolveResourceInternal(request, requestPath, locations, chain);

        if (logger.isDebugEnabled()) {
            if (resource == null) {
                logger.debug("Cache resolver, returned a null resource " + requestPath);
            } else if (!resource.exists()) {
                logger.debug("Cache resolver, returned a resource that doesn't exist " + requestPath + " - "
                        + resource);/*w  w w.java  2  s  . c  o m*/
            }
        }
        return resource;
    } else {
        return chain.resolveResource(request, requestPath, locations);
    }
}

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

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {
    if (resourceVersioningEnabled && !bundlingService.checkForRegisteredBundleFile(requestPath)) {
        return super.resolveResourceInternal(request, requestPath, locations, chain);
    } else {/*from  w  ww .j av  a2s.  c o  m*/
        return chain.resolveResource(request, requestPath, locations);
    }
}

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

@Override
protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath,
        List<? extends Resource> locations, ResourceResolverChain chain) {

    if (requestPath != null) {
        if (isBundleFile(requestPath)) {
            Resource bundle = bundlingService.resolveBundleResource(requestPath);

            logTraceInformation(bundle);
            if (bundle != null && bundle.exists()) {
                return bundle;
            }/*  ww w  .  j ava 2  s.c  om*/
        }
    }

    return chain.resolveResource(request, requestPath, locations);
}