org.sakaiproject.entitybroker.util.spring
Class ResourceFinder

java.lang.Object
  extended by org.sakaiproject.entitybroker.util.spring.ResourceFinder

public class ResourceFinder
extends Object

Takes a path or list of paths to resources and turns them into different things (file/IS/resource), this also allows us to look on a relative or absolute path and will automatically check the typical places one might expect to put sakai config files
Checks the environmental and file paths first and then defaults to checking the classloaders
Allows us to find resources in our pack since the Sakai context classloader is wrong, too bad it is not correct, that would be cool, but it is wrong and it is not cool

Sample usage:

<property name="configLocation"> <bean class="org.sakaiproject.entitybroker.impl.util.ResourceFinder" factory-method="getResource"> <constructor-arg value="ehcache.xml" /> </bean> </property> Just call whichever get* method you want to depending on the needed output
You can also get arrays of resources at once like so: <property name="mappingLocations"> <bean class="org.sakaiproject.entitybroker.impl.util.ResourceFinder" factory-method="getResources"> <constructor-arg> <list> <value>org/sakaiproject/hierarchy/dao/hbm/HierarchyPersistentNode.hbm.xml</value> <value>org/sakaiproject/hierarchy/dao/hbm/HierarchyNodeMetaData.hbm.xml</value> </list> </constructor-arg> </bean> </property>

Author:
Aaron Zeckoski (aaron@caret.cam.ac.uk)

Field Summary
static String environmentPathVariable
           
static String relativePath
           
 
Constructor Summary
ResourceFinder()
           
 
Method Summary
protected static String getContainerHome()
           
protected static String getEnvironmentPath()
           
static File getFile(String path)
           
static File[] getFiles(List<String> paths)
           
static InputStream getInputStream(String path)
           
static InputStream[] getInputStreams(List<String> paths)
           
protected static String getRelativePath()
           
static org.springframework.core.io.Resource getResource(String path)
          Resolve a path into a resource relative to environmental defaults or relative paths or the classloader
static org.springframework.core.io.Resource[] getResources(List<String> paths)
          Resolves a list of paths into resources relative to environmental defaults or relative paths or the classloader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

relativePath

public static String relativePath

environmentPathVariable

public static String environmentPathVariable
Constructor Detail

ResourceFinder

public ResourceFinder()
Method Detail

getResources

public static org.springframework.core.io.Resource[] getResources(List<String> paths)
Resolves a list of paths into resources relative to environmental defaults or relative paths or the classloader

Parameters:
paths - a list of paths to resources (org/sakaiproject/mystuff/Thing.xml)
Returns:
an array of Spring Resource objects

getFiles

public static File[] getFiles(List<String> paths)

getInputStreams

public static InputStream[] getInputStreams(List<String> paths)

getResource

public static org.springframework.core.io.Resource getResource(String path)
Resolve a path into a resource relative to environmental defaults or relative paths or the classloader

Parameters:
path - a path to a resource (org/sakaiproject/mystuff/Thing.xml)
Returns:
the Spring Resource object

getFile

public static File getFile(String path)

getInputStream

public static InputStream getInputStream(String path)

getRelativePath

protected static String getRelativePath()

getEnvironmentPath

protected static String getEnvironmentPath()

getContainerHome

protected static String getContainerHome()


Copyright © 2007-2012 CARET, University of Cambridge. All Rights Reserved.