org.specrunner.util.resources
Class ResourceFinder

java.lang.Object
  extended by org.specrunner.util.resources.ResourceFinder

public class ResourceFinder
extends Object

Resources utilities.

Author:
Thiago Santos

Field Summary
protected static ICache<String,List<URL>> cache
          Cache of resources.
static String FEATURE_COMPARATOR
          Comparator feature.
 
Constructor Summary
ResourceFinder()
           
 
Method Summary
 List<URL> filter(List<URL> resources)
          Filter resources.
 List<URL> getAllResources(String resource)
          List of all resource URLs associated to a given file, including its suffix '_default' corresponding version.
 Comparator<URL> getComparator()
          Get the resources comparator.
 String getDefault(String resource)
          Get default name for resource files.
 List<URL> getResources(String resource)
          Find a given file in classloader.
 URL getSpecific(String resource)
          Get the most specific file.
protected  void log(String msg, List<URL> files)
          Print load information.
 void setComparator(Comparator<URL> comparator)
          Set the comparator.
 List<URL> sort(List<URL> resources)
          Sort the resources using reverse order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FEATURE_COMPARATOR

public static final String FEATURE_COMPARATOR
Comparator feature.


cache

protected static ICache<String,List<URL>> cache
Cache of resources.

Constructor Detail

ResourceFinder

public ResourceFinder()
Method Detail

getComparator

public Comparator<URL> getComparator()
Get the resources comparator.

Returns:
The comparator.

setComparator

public void setComparator(Comparator<URL> comparator)
Set the comparator.

Parameters:
comparator - Comparator.

getDefault

public String getDefault(String resource)
Get default name for resource files.

Parameters:
resource - The resource name.
Returns:
The corresponding default resource name.

getSpecific

public URL getSpecific(String resource)
                throws IOException
Get the most specific file. The one which is closer in classpath lookup.

Parameters:
resource - The resource.
Returns:
The resource URL.
Throws:
IOException - On lookup errors.

getAllResources

public List<URL> getAllResources(String resource)
                          throws IOException
List of all resource URLs associated to a given file, including its suffix '_default' corresponding version.

Parameters:
resource - The resource file.
Returns:
The resource URL list.
Throws:
IOException - On lookup error.

log

protected void log(String msg,
                   List<URL> files)
Print load information.

Parameters:
msg - A message.
files - The resource list.

getResources

public List<URL> getResources(String resource)
                       throws IOException
Find a given file in classloader.

Parameters:
resource - The resource name.
Returns:
The list of files satisfying the name restriction in classpath.
Throws:
IOException - On loading list errors.

filter

public List<URL> filter(List<URL> resources)
Filter resources.

Parameters:
resources - The resources.
Returns:
The list filtered resources. Default implementation filters nothing.

sort

public List<URL> sort(List<URL> resources)
Sort the resources using reverse order.

Parameters:
resources - The resources.
Returns:
The sorted list. Default implementation sources is in reverse order.


Copyright © 2014. All rights reserved.