Example usage for org.springframework.util ResourceUtils JAR_URL_SEPARATOR

List of usage examples for org.springframework.util ResourceUtils JAR_URL_SEPARATOR

Introduction

In this page you can find the example usage for org.springframework.util ResourceUtils JAR_URL_SEPARATOR.

Prototype

String JAR_URL_SEPARATOR

To view the source code for org.springframework.util ResourceUtils JAR_URL_SEPARATOR.

Click Source Link

Document

Separator between JAR URL and file path within the JAR: "!/".

Usage

From source file:com.gzj.tulip.load.vfs.JarFileObject.java

JarFileObject(FileSystemManager fs, URL url) throws FileNotFoundException, IOException {
    this.fs = fs;
    String urlString = url.toString();
    String entryName = urlString.substring(
            urlString.indexOf(ResourceUtils.JAR_URL_SEPARATOR) + ResourceUtils.JAR_URL_SEPARATOR.length());
    if (entryName.length() == 0) {
        this.root = this;
        int beginIndex = urlString.indexOf(ResourceUtils.FILE_URL_PREFIX)
                + ResourceUtils.FILE_URL_PREFIX.length();
        int endIndex = urlString.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
        this.jarFile = new JarFile(urlString.substring(beginIndex, endIndex));
    } else {/*from   www . j  ava  2 s  .  c o m*/
        this.root = (JarFileObject) fs.resolveFile(urlString.substring(//
                0,
                urlString.indexOf(ResourceUtils.JAR_URL_SEPARATOR) + ResourceUtils.JAR_URL_SEPARATOR.length()));
        this.jarFile = root.jarFile;
    }
    this.entry = jarFile.getJarEntry(entryName);
    this.url = url;
    this.urlString = urlString;
    int indexSep = entryName.lastIndexOf('/');
    if (indexSep == -1) {
        this.fileName = new FileNameImpl(this, entryName);
    } else {
        if (entryName.endsWith("/")) {
            int index = entryName.lastIndexOf('/', entryName.length() - 2);
            this.fileName = new FileNameImpl(this, entryName.substring(index + 1, indexSep));
        } else {
            this.fileName = new FileNameImpl(this, entryName.substring(indexSep + 1));
        }
    }
}

From source file:com.asual.summer.core.resource.MessageResource.java

public void setWildcardLocations(String[] locations) {

    super.setLocations(locations);

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    List<Resource[]> resourceLocations = new ArrayList<Resource[]>();

    List<String> fileBasenames = new ArrayList<String>();
    List<String> jarBasenames = new ArrayList<String>();

    for (String location : locations) {
        try {/*from   w  w  w.  ja va 2  s  .  co m*/
            Resource[] wildcard = (Resource[]) ArrayUtils.addAll(
                    resolver.getResources(location + "*.properties"),
                    resolver.getResources(location + "*.xml"));
            if (wildcard != null && wildcard.length > 0) {
                resourceLocations.add(wildcard);
            }
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }

    int i = 0;
    boolean entries = true;

    while (entries) {
        entries = false;
        for (Resource[] location : resourceLocations) {
            if (location.length > i) {
                try {
                    URL url = location[i].getURL();
                    boolean isJar = ResourceUtils.isJarURL(url);
                    String basename = "classpath:" + url.getFile()
                            .replaceFirst(isJar ? "^.*" + ResourceUtils.JAR_URL_SEPARATOR
                                    : "^(.*/test-classes|.*/classes|.*/resources)/", "")
                            .replaceAll("(_\\w+){0,3}\\.(properties|xml)", "");
                    if (isJar) {
                        if (!jarBasenames.contains(basename)) {
                            jarBasenames.add(basename);
                        }
                    } else {
                        if (!fileBasenames.contains(basename)) {
                            fileBasenames.add(basename);
                        }
                    }
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                }
                entries = true;
            }
        }
        i++;
    }

    fileBasenames.addAll(jarBasenames);

    rbms.clearCache();
    rbms.setBasenames(fileBasenames.toArray(new String[fileBasenames.size()]));
}

From source file:org.shept.util.JarUtils.java

/**
 * Copy resources from a classPath, typically within a jar file 
 * to a specified destination, typically a resource directory in
 * the projects webApp directory (images, sounds, e.t.c. )
 * //w w w  .j a  v a2 s  .c o  m
 * Copies resources only if the destination file does not exist and
 * the specified resource is available.
 * 
 * The ClassPathResource will be scanned for all resources in the path specified by the resource.
 * For example  a path like:
 *    new ClassPathResource("resource/images/pager/", SheptBaseController.class);
 * takes all the resources in the path 'resource/images/pager' (but not in sub-path)
 * from the specified clazz 'SheptBaseController'
 * 
 * @param cpr ClassPathResource specifying the source location on the classPath (maybe within a jar)
 * @param webAppDestPath Full path String to the fileSystem destination directory   
 * @throws IOException when copying on copy error
 * @throws URISyntaxException 
 */
public static void copyResources(ClassPathResource cpr, String webAppDestPath)
        throws IOException, URISyntaxException {
    String dstPath = webAppDestPath; //  + "/" + jarPathInternal(cpr.getURL());
    File dir = new File(dstPath);
    dir.mkdirs();

    URL url = cpr.getURL();
    // jarUrl is the URL of the containing lib, e.g. shept.org in this case
    URL jarUrl = ResourceUtils.extractJarFileURL(url);
    String urlFile = url.getFile();
    String resPath = "";
    int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
    if (separatorIndex != -1) {
        // just copy the the location path inside the jar without leading separators !/
        resPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length());
    } else {
        return; // no resource within jar to copy
    }

    File f = new File(ResourceUtils.toURI(jarUrl));
    JarFile jf = new JarFile(f);

    Enumeration<JarEntry> entries = jf.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String path = entry.getName();
        if (path.startsWith(resPath) && entry.getSize() > 0) {
            String fileName = path.substring(path.lastIndexOf("/"));
            File dstFile = new File(dstPath, fileName); //  (StringUtils.applyRelativePath(dstPath, fileName));
            Resource fileRes = cpr.createRelative(fileName);
            if (!dstFile.exists() && fileRes.exists()) {
                FileOutputStream fos = new FileOutputStream(dstFile);
                FileCopyUtils.copy(fileRes.getInputStream(), fos);
                logger.info("Successfully copied file " + fileName + " from " + cpr.getPath() + " to "
                        + dstFile.getPath());
            }
        }
    }

    if (jf != null) {
        jf.close();
    }

}

From source file:net.paoding.rose.scanner.ModuleResourceProviderImpl.java

@Override
public List<ModuleResource> findModuleResources(LoadScope scope) throws IOException {

    Local local = new Local();
    String[] controllersScope = scope.getScope("controllers");
    if (logger.isInfoEnabled()) {
        logger.info("[moduleResource] starting ...");
        logger.info("[moduleResource] call 'findFiles':" + " to find classes or jar files by scope "//
                + Arrays.toString(controllersScope));
    }//from w  w  w  . j ava2  s. co  m

    List<ResourceRef> refers = RoseScanner.getInstance().getJarOrClassesFolderResources(controllersScope);

    if (logger.isInfoEnabled()) {
        logger.info("[moduleResource] exits from 'findFiles'");
        logger.info(
                "[moduleResource] going to scan controllers" + " from these folders or jar files:" + refers);
    }

    FileSystemManager fileSystem = new FileSystemManager();

    for (ResourceRef refer : refers) {
        Resource resource = refer.getResource();
        if (!refer.hasModifier("controllers")) {
            if (logger.isDebugEnabled()) {
                logger.debug("[moduleResource] Ignored because not marked as 'controllers'"
                        + " in META-INF/rose.properties or META-INF/MANIFEST.MF: " + resource.getURI());
            }
            continue;
        }
        File resourceFile = resource.getFile();
        String urlString;
        if ("jar".equals(refer.getProtocol())) {
            urlString = ResourceUtils.URL_PROTOCOL_JAR + ":" + resourceFile.toURI()
                    + ResourceUtils.JAR_URL_SEPARATOR;
        } else {
            urlString = resourceFile.toURI().toString();
        }
        FileObject rootObject = fileSystem.resolveFile(urlString);
        if (rootObject == null || !rootObject.exists()) {
            if (logger.isDebugEnabled()) {
                logger.debug("[moduleResource] Ignored because not exists: " + urlString);
            }
            continue;
        }

        if (logger.isInfoEnabled()) {
            logger.info("[moduleResource] start to scan moduleResource in file: " + rootObject);
        }

        try {
            int oldSize = local.moduleResourceList.size();

            deepScanImpl(local, rootObject, rootObject);

            int newSize = local.moduleResourceList.size();

            if (logger.isInfoEnabled()) {
                logger.info("[moduleResource] got " + (newSize - oldSize) + " modules in " + rootObject);
            }

        } catch (Exception e) {
            logger.error("[moduleResource] error happend when scanning " + rootObject, e);
        }

        fileSystem.clearCache();
    }

    afterScanning(local);

    logger.info("[moduleResource] found " + local.moduleResourceList.size() + " module resources ");

    return local.moduleResourceList;
}

From source file:com.sinosoft.one.mvc.scanner.ModuleResourceProviderImpl.java

public List<ModuleResource> findModuleResources(LoadScope scope) throws IOException {

    Local local = new Local();
    String[] controllersScope = scope.getScope("controllers");
    if (logger.isInfoEnabled()) {
        logger.info("[moduleResource] starting ...");
        logger.info("[moduleResource] call 'findFiles':" + " to find classes or jar files by scope "//
                + Arrays.toString(controllersScope));
    }//  ww w  .  j  av  a 2  s . co m

    List<ResourceRef> refers = MvcScanner.getInstance().getJarOrClassesFolderResources(controllersScope);

    if (logger.isInfoEnabled()) {
        logger.info("[moduleResource] exits from 'findFiles'");
        logger.info(
                "[moduleResource] going to scan controllers" + " from these folders or jar files:" + refers);
    }

    FileSystemManager fileSystem = new FileSystemManager();

    for (ResourceRef refer : refers) {
        Resource resource = refer.getResource();
        if (!refer.hasModifier("controllers")) {
            if (logger.isDebugEnabled()) {
                logger.debug("[moduleResource] Ignored because not marked as 'controllers'"
                        + " in META-INF/mvc.properties or META-INF/MANIFEST.MF: " + resource.getURI());
            }
            continue;
        }
        File resourceFile = resource.getFile();
        String urlString;
        if ("jar".equals(refer.getProtocol())) {
            urlString = ResourceUtils.URL_PROTOCOL_JAR + ":" + resourceFile.toURI()
                    + ResourceUtils.JAR_URL_SEPARATOR;
        } else {
            urlString = resourceFile.toURI().toString();
        }
        FileObject rootObject = fileSystem.resolveFile(urlString);
        if (rootObject == null || !rootObject.exists()) {
            if (logger.isDebugEnabled()) {
                logger.debug("[moduleResource] Ignored because not exists: " + urlString);
            }
            continue;
        }

        if (logger.isInfoEnabled()) {
            logger.info("[moduleResource] start to scan moduleResource in file: " + rootObject);
        }

        try {
            int oldSize = local.moduleResourceList.size();

            deepScanImpl(local, rootObject, rootObject);

            int newSize = local.moduleResourceList.size();

            if (logger.isInfoEnabled()) {
                logger.info("[moduleResource] got " + (newSize - oldSize) + " modules in " + rootObject);
            }

        } catch (Exception e) {
            logger.error("[moduleResource] error happend when scanning " + rootObject, e);
        }

        fileSystem.clearCache();
    }

    afterScanning(local);

    logger.info("[moduleResource] found " + local.moduleResourceList.size() + " module resources ");

    return local.moduleResourceList;
}

From source file:com.laxser.blitz.scanner.ModuleResourceProviderImpl.java

@Override
public List<ModuleResource> findModuleResources(LoadScope scope) throws IOException {

    Local local = new Local();
    String[] controllersScope = scope.getScope("controllers");
    if (logger.isInfoEnabled()) {
        logger.info("[moduleResource] starting ...");
        logger.info("[moduleResource] call 'findFiles':" + " to find classes or jar files by scope "//
                + Arrays.toString(controllersScope));
    }//  w w w . ja va  2s .  c o  m

    List<ResourceRef> refers = BlitzScanner.getInstance().getJarOrClassesFolderResources(controllersScope);

    if (logger.isInfoEnabled()) {
        logger.info("[moduleResource] exits from 'findFiles'");
        logger.info(
                "[moduleResource] going to scan controllers" + " from these folders or jar files:" + refers);
    }

    FileSystemManager fileSystem = new FileSystemManager();

    for (ResourceRef refer : refers) {
        Resource resource = refer.getResource();
        if (!refer.hasModifier("controllers")) {
            if (logger.isDebugEnabled()) {
                logger.debug("[moduleResource] Ignored because not marked as 'controllers'"
                        + " in META-INF/blitz.properties or META-INF/MANIFEST.MF: " + resource.getURI());
            }
            continue;
        }
        File resourceFile = resource.getFile();
        String urlString;
        if ("jar".equals(refer.getProtocol())) {
            urlString = ResourceUtils.URL_PROTOCOL_JAR + ":" + resourceFile.toURI()
                    + ResourceUtils.JAR_URL_SEPARATOR;
        } else {
            urlString = resourceFile.toURI().toString();
        }
        FileObject rootObject = fileSystem.resolveFile(urlString);
        if (rootObject == null || !rootObject.exists()) {
            if (logger.isDebugEnabled()) {
                logger.debug("[moduleResource] Ignored because not exists: " + urlString);
            }
            continue;
        }

        if (logger.isInfoEnabled()) {
            logger.info("[moduleResource] start to scan moduleResource in file: " + rootObject);
        }

        try {
            int oldSize = local.moduleResourceList.size();

            deepScanImpl(local, rootObject, rootObject);

            int newSize = local.moduleResourceList.size();

            if (logger.isInfoEnabled()) {
                logger.info("[moduleResource] got " + (newSize - oldSize) + " modules in " + rootObject);
            }

        } catch (Exception e) {
            logger.error("[moduleResource] error happend when scanning " + rootObject, e);
        }

        fileSystem.clearCache();
    }

    afterScanning(local);

    logger.info("[moduleResource] found " + local.moduleResourceList.size() + " module resources ");

    return local.moduleResourceList;
}

From source file:com.gzj.tulip.load.ResourceRef.java

public String getInnerResourcePattern(String subPath) throws IOException {
    Assert.isTrue(!subPath.startsWith("/"), subPath);
    String rootPath = resource.getURI().getPath();
    if (getProtocol().equals("jar")) {
        subPath = "jar:file:" + rootPath + ResourceUtils.JAR_URL_SEPARATOR + subPath;
    } else {/*from w w w.  j  a  v  a2s . co m*/
        subPath = "file:" + rootPath + subPath;
    }
    return subPath;
}

From source file:org.shept.util.JarUtils.java

/**
 * Extract the URL-String for the internal resource path from the given URL
 * (which points to a resource in a jar file).
 * This methods complements {@link ResourceUtils#extractJarFileURL(URL)}
 * /*from w  w  w  .  j  av a2 s .co  m*/
 * @return empty String if no such internal jar path is found
 * @param jarPathUrl
 */
public static String jarPathInternal(URL jarPathUrl) {
    String urlFile = jarPathUrl.getFile();
    int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
    if (separatorIndex != -1) {
        separatorIndex = separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length();
        return urlFile.substring(separatorIndex, urlFile.length());
    }
    return "";
}

From source file:com.gzj.tulip.jade.context.spring.JadeBeanFactoryPostProcessor.java

private List<String> findJadeResources(final List<ResourceRef> resources) {
    List<String> urls = new LinkedList<String>();
    for (ResourceRef ref : resources) {
        if (ref.hasModifier("dao") || ref.hasModifier("DAO")) {
            try {
                Resource resource = ref.getResource();
                File resourceFile = resource.getFile();
                if (resourceFile.isFile()) {
                    urls.add("jar:file:" + resourceFile.toURI().getPath() + ResourceUtils.JAR_URL_SEPARATOR);
                } else if (resourceFile.isDirectory()) {
                    urls.add(resourceFile.toURI().toString());
                }/*  w ww. jav  a 2s.  c  o m*/
            } catch (IOException e) {
                throw new ApplicationContextException("error on resource.getFile", e);
            }
        }
    }
    if (logger.isInfoEnabled()) {
        logger.info("[jade] found " + urls.size() + " jade urls: " + urls);
    }
    return urls;
}