com.google.clearsilver.jsilver.resourceloader
Class ClassResourceLoader
java.lang.Object
com.google.clearsilver.jsilver.resourceloader.BaseResourceLoader
com.google.clearsilver.jsilver.resourceloader.BufferedResourceLoader
com.google.clearsilver.jsilver.resourceloader.ClassResourceLoader
- All Implemented Interfaces:
- ResourceLoader
public class ClassResourceLoader
- extends BufferedResourceLoader
Loads resources from classpath, alongside a given class.
For example, suppose the classpath contains:
com/foo/SomeThing.class
com/foo/my-template.cs
com/foo/subdir/another-template.cs
You can access the resources in the class's package like this:
ResourceLoader loader = new ClassResourceLoader(SomeThing.class);
loader.open("my-template.cs");
loader.open("subdir/my-template.cs");
Or by using a relative path:
ResourceLoader loader = new ClassResourceLoader(Something.class, "subdir");
loader.open("my-template.cs");
- See Also:
ResourceLoader
,
ClassLoaderResourceLoader
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ClassResourceLoader
public ClassResourceLoader(Class<?> cls)
ClassResourceLoader
public ClassResourceLoader(Class<?> cls,
String basePath)
- Load resources from the given subdirectory
basePath
,
relative to the .class file of cls
.
open
public Reader open(String name)
throws IOException
- Description copied from interface:
ResourceLoader
- Open a resource. If this resource is not found, null should be returned.
The caller of this method is guaranteed to call
ResourceLoader.close(Reader)
when done with the
reader.
- Parameters:
name
- the name of the resource
- Returns:
- Reader, or null if not found.
- Throws:
IOException
- if resource fails to open
openOrFail
public Reader openOrFail(String name)
throws JSilverTemplateNotFoundException,
IOException
- Description copied from interface:
ResourceLoader
- Open a resource or throw an exception if no such resource is found.
The caller of this method is guaranteed to call
ResourceLoader.close(Reader)
when done with the
reader.
- Parameters:
name
- the name of the resource
- Returns:
- Reader, or null if not found.
- Throws:
JSilverTemplateNotFoundException
- if resource is not found
IOException
- if resource fails to open
Copyright © 2010-2012 Google. All Rights Reserved.