Package org.grails.io.support
Class DefaultResourceLoader
- java.lang.Object
-
- org.grails.io.support.DefaultResourceLoader
-
- All Implemented Interfaces:
ResourceLoader
- Direct Known Subclasses:
FileSystemResourceLoader
public class DefaultResourceLoader extends java.lang.Object implements ResourceLoader
Default implementation of the ResourceLoader interface.Will return a UrlResource if the location value is a URL, and a ClassPathResource if it is a non-URL path or a "classpath:" pseudo-URL.
- Since:
- 10.03.2004
-
-
Field Summary
-
Fields inherited from interface org.grails.io.support.ResourceLoader
CLASSPATH_URL_PREFIX
-
-
Constructor Summary
Constructors Constructor Description DefaultResourceLoader()Create a new DefaultResourceLoader.DefaultResourceLoader(java.lang.ClassLoader classLoader)Create a new DefaultResourceLoader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ClassLoadergetClassLoader()Return the ClassLoader to load class path resources with.static java.lang.ClassLoadergetDefaultClassLoader()ResourcegetResource(java.lang.String location)Return a Resource handle for the specified resource.protected ResourcegetResourceByPath(java.lang.String path)Return a Resource handle for the resource at the given path.voidsetClassLoader(java.lang.ClassLoader classLoader)Specify the ClassLoader to load class path resources with, ornullfor using the thread context class loader at the time of actual resource access.
-
-
-
Constructor Detail
-
DefaultResourceLoader
public DefaultResourceLoader()
Create a new DefaultResourceLoader.ClassLoader access will happen using the thread context class loader at the time of this ResourceLoader's initialization.
- See Also:
Thread.getContextClassLoader()
-
DefaultResourceLoader
public DefaultResourceLoader(java.lang.ClassLoader classLoader)
Create a new DefaultResourceLoader.- Parameters:
classLoader- the ClassLoader to load class path resources with, ornullfor using the thread context class loader at the time of actual resource access
-
-
Method Detail
-
getDefaultClassLoader
public static java.lang.ClassLoader getDefaultClassLoader()
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
Specify the ClassLoader to load class path resources with, ornullfor using the thread context class loader at the time of actual resource access.The default is that ClassLoader access will happen using the thread context class loader at the time of this ResourceLoader's initialization.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Return the ClassLoader to load class path resources with.- Specified by:
getClassLoaderin interfaceResourceLoader- Returns:
- the ClassLoader (never
null)
-
getResource
public Resource getResource(java.lang.String location)
Description copied from interface:ResourceLoaderReturn a Resource handle for the specified resource. The handle should always be a reusable resource descriptor, allowing for multiple Resource#getInputStream() calls.- Must support fully qualified URLs, e.g. "file:C:/test.dat".
- Must support classpath pseudo-URLs, e.g. "classpath:test.dat".
- Should support relative file paths, e.g. "WEB-INF/test.dat". (This will be implementation-specific, typically provided by an ApplicationContext implementation.)
Note that a Resource handle does not imply an existing resource; you need to invoke Resource#exists to check for existence.
- Specified by:
getResourcein interfaceResourceLoader- Parameters:
location- the resource location- Returns:
- a corresponding Resource handle
- See Also:
ResourceLoader.CLASSPATH_URL_PREFIX
-
getResourceByPath
protected Resource getResourceByPath(java.lang.String path)
Return a Resource handle for the resource at the given path.The default implementation supports class path locations. This should be appropriate for standalone implementations but can be overridden, e.g. for implementations targeted at a Servlet container.
- Parameters:
path- the path to the resource- Returns:
- the corresponding Resource handle
- See Also:
ClassPathResource
-
-