info.magnolia.cms.util
Class ClasspathResourcesUtil

java.lang.Object
  extended by info.magnolia.cms.util.ClasspathResourcesUtil

public class ClasspathResourcesUtil
extends Object

Util to find resources in the classpath (WEB-INF/lib and WEB-INF/classes).


Nested Class Summary
static interface ClasspathResourcesUtil.Filter
          Filter for filtering the resources.
static class ClasspathResourcesUtil.PatternFilter
          A filter using a regex pattern.
 
Constructor Summary
ClasspathResourcesUtil()
           
 
Method Summary
protected static void collectFromClasspathString(Collection<String> resources, String classpath, ClasspathResourcesUtil.Filter filter)
           
protected static void collectFromFileSystem(ClasspathResourcesUtil.Filter filter, Collection<String> resources)
           
protected static void collectFromURLs(Collection<String> resources, URL[] urls, ClasspathResourcesUtil.Filter filter)
           
static String[] findResources(ClasspathResourcesUtil.Filter filter)
          Return a collection containing the resource names which passed the filter.
static String[] findResources(String regex)
          Return a collection containing the resource names which match the regular expression.
static ClassLoader getCurrentClassLoader()
          From http://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader.
static URL getResource(String name)
          Get the resource using the current class loader.
static InputStream getStream(String name)
           
static InputStream getStream(String name, boolean cache)
          Checks last modified and returns the new content if changed and the cache flag is not set to true.
static File sanitizeToFile(URL url)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathResourcesUtil

public ClasspathResourcesUtil()
Method Detail

findResources

public static String[] findResources(String regex)
Return a collection containing the resource names which match the regular expression.

Returns:
string array of found resources TODO : (lazy) cache ?

findResources

public static String[] findResources(ClasspathResourcesUtil.Filter filter)
Return a collection containing the resource names which passed the filter.

Returns:
string array of found resources TODO : (lazy) cache ?

collectFromURLs

protected static void collectFromURLs(Collection<String> resources,
                                      URL[] urls,
                                      ClasspathResourcesUtil.Filter filter)

collectFromClasspathString

protected static void collectFromClasspathString(Collection<String> resources,
                                                 String classpath,
                                                 ClasspathResourcesUtil.Filter filter)

collectFromFileSystem

protected static void collectFromFileSystem(ClasspathResourcesUtil.Filter filter,
                                            Collection<String> resources)

sanitizeToFile

public static File sanitizeToFile(URL url)

getStream

public static InputStream getStream(String name)
                             throws IOException
Throws:
IOException

getStream

public static InputStream getStream(String name,
                                    boolean cache)
                             throws IOException
Checks last modified and returns the new content if changed and the cache flag is not set to true.

Returns:
the input stream
Throws:
IOException

getCurrentClassLoader

public static ClassLoader getCurrentClassLoader()
From http://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader.

"Each class will use its own classloader to load other classes. So if ClassA.class references ClassB.class then ClassB needs to be on the classpath of the classloader of ClassA, or its parents. The thread context classloader is the current classloader for the current thread. An object can be created from a class in ClassLoaderC and then passed to a thread owned by ClassLoaderD. In this case the object needs to use Thread.currentThread().getContextClassLoader() directly if it wants to load resources that are not available on its own classloader."

Returns:
current classloader

getResource

public static URL getResource(String name)
Get the resource using the current class loader. The leading / is removed as the call to class.getResource() would do.

Returns:
the resource


Copyright © 2003-2014 Magnolia International Ltd.. All Rights Reserved.