info.magnolia.cms.util
Class ClasspathResourcesUtil

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

public class ClasspathResourcesUtil
extends java.lang.Object

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

Version:
$Revision: 41137 $ ($Author: gjoseph $)
Author:
Philipp Bracher, Fabrizio Giustina

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(java.util.Collection<java.lang.String> resources, java.lang.String classpath, ClasspathResourcesUtil.Filter filter)
           
protected static void collectFromFileSystem(ClasspathResourcesUtil.Filter filter, java.util.Collection<java.lang.String> resources)
           
protected static void collectFromURLs(java.util.Collection<java.lang.String> resources, java.net.URL[] urls, ClasspathResourcesUtil.Filter filter)
           
static java.lang.String[] findResources(ClasspathResourcesUtil.Filter filter)
          Return a collection containing the resource names which passed the filter.
static java.lang.String[] findResources(java.lang.String regex)
          Return a collection containing the resource names which match the regular expression.
static java.net.URL getResource(java.lang.String name)
          Get the resource using the current class loader.
static java.io.InputStream getStream(java.lang.String name)
           
static java.io.InputStream getStream(java.lang.String name, boolean cache)
          Checks last modified and returns the new content if changed and the cache flag is not set to true.
protected static java.io.File sanitizeToFile(java.net.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 java.lang.String[] findResources(java.lang.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 java.lang.String[] findResources(ClasspathResourcesUtil.Filter filter)
Return a collection containing the resource names which passed the filter.

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

collectFromURLs

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

collectFromClasspathString

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

collectFromFileSystem

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

sanitizeToFile

protected static java.io.File sanitizeToFile(java.net.URL url)

getStream

public static java.io.InputStream getStream(java.lang.String name)
                                     throws java.io.IOException
Throws:
java.io.IOException

getStream

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

Parameters:
name -
Returns:
the input stream
Throws:
java.io.IOException

getResource

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

Parameters:
name -
Returns:
the resource


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