Example usage for org.springframework.core.io DescriptiveResource getURL

List of usage examples for org.springframework.core.io DescriptiveResource getURL

Introduction

In this page you can find the example usage for org.springframework.core.io DescriptiveResource getURL.

Prototype

@Override
public URL getURL() throws IOException 

Source Link

Document

This implementation throws a FileNotFoundException, assuming that the resource cannot be resolved to a URL.

Usage

From source file:ch.rasc.edsutil.optimizer.WebResourceProcessor.java

private List<WebResource> createWebResources(VariableConfig variableConfig) {

    List<WebResource> webResources = new ArrayList<>();
    String varName = variableConfig.variable;

    for (WebResourceConfig config : variableConfig.resources) {
        String path = replaceVariables(config.path);

        if (!this.production && config.isDevScriptOrLink()) {
            DescriptiveResource resource = new DescriptiveResource(path);
            webResources.add(new WebResource(varName, path, resource, false));
        } else if (this.production && config.isProd()) {
            if (config.isProdScriptOrLink()) {
                DescriptiveResource resource = new DescriptiveResource(path);
                webResources.add(new WebResource(varName, path, resource, false));
            } else {
                try {
                    boolean jsProcessing = varName.endsWith(JS_EXTENSION);
                    List<Resource> enumeratedResources;
                    String suffix = jsProcessing ? ".js" : ".css";
                    if (StringUtils.hasText(config.classpath)) {
                        enumeratedResources = enumerateResourcesFromClasspath(config.classpath, path, suffix);
                    } else {
                        enumeratedResources = enumerateResourcesFromWebapp(path, suffix);
                    }/* w ww.j  a va2  s .co  m*/
                    if (jsProcessing && enumeratedResources.size() > 1) {
                        enumeratedResources = reorder(enumeratedResources);
                    }

                    for (Resource resource : enumeratedResources) {
                        String resourcePath = resource.getURL().toString();

                        int pathIx = resourcePath.indexOf(path);
                        if (pathIx != -1) {
                            resourcePath = resourcePath.substring(pathIx);
                        }

                        webResources.add(new WebResource(varName, resourcePath, resource, true));
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    return webResources;
}