Example usage for org.springframework.core.io UrlResource UrlResource

List of usage examples for org.springframework.core.io UrlResource UrlResource

Introduction

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

Prototype

public UrlResource(String protocol, String location) throws MalformedURLException 

Source Link

Document

Create a new UrlResource based on a URI specification.

Usage

From source file:org.springframework.web.context.support.ServletContextResourcePatternResolver.java

/**
 * Extract entries from the given jar by pattern.
 * @param jarFilePath the path to the jar file
 * @param entryPattern the pattern for jar entries to match
 * @param result the Set of matching Resources to add to
 *//*from  w  w w.jav  a  2s . co  m*/
private void doRetrieveMatchingJarEntries(String jarFilePath, String entryPattern, Set<Resource> result) {
    if (logger.isDebugEnabled()) {
        logger.debug("Searching jar file [" + jarFilePath + "] for entries matching [" + entryPattern + "]");
    }
    try {
        JarFile jarFile = new JarFile(jarFilePath);
        try {
            for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
                JarEntry entry = entries.nextElement();
                String entryPath = entry.getName();
                if (getPathMatcher().match(entryPattern, entryPath)) {
                    result.add(new UrlResource(ResourceUtils.URL_PROTOCOL_JAR, ResourceUtils.FILE_URL_PREFIX
                            + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath));
                }
            }
        } finally {
            jarFile.close();
        }
    } catch (IOException ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("Cannot search for matching resources in jar file [" + jarFilePath
                    + "] because the jar cannot be opened through the file system", ex);
        }
    }
}