com.google.clearsilver.jsilver.resourceloader
Class ClassLoaderResourceLoader

java.lang.Object
  extended by com.google.clearsilver.jsilver.resourceloader.BaseResourceLoader
      extended by com.google.clearsilver.jsilver.resourceloader.BufferedResourceLoader
          extended by com.google.clearsilver.jsilver.resourceloader.ClassLoaderResourceLoader
All Implemented Interfaces:
ResourceLoader

public class ClassLoaderResourceLoader
extends BufferedResourceLoader

Loads resources from classpath.

For example, suppose the classpath contains:

 com/foo/my-template.cs
 com/foo/subdir/another-template.cs
 

You can access the resources like this:

 ResourceLoader loader =
     new ClassPathResourceLoader(getClassLoader(), "com/foo");
 loader.open("my-template.cs");
 loader.open("subdir/my-template.cs");
 

See Also:
ResourceLoader, ClassResourceLoader

Field Summary
 
Fields inherited from class com.google.clearsilver.jsilver.resourceloader.BufferedResourceLoader
DEFAULT_BUFFER_SIZE, DEFAULT_CHARACTER_SET
 
Constructor Summary
ClassLoaderResourceLoader(ClassLoader classLoader)
           
ClassLoaderResourceLoader(ClassLoader classLoader, String basePath)
           
 
Method Summary
 Reader open(String name)
          Open a resource.
 Reader openOrFail(String name)
          Open a resource or throw an exception if no such resource is found.
 
Methods inherited from class com.google.clearsilver.jsilver.resourceloader.BufferedResourceLoader
buffer, getBufferSize, getCharacterSet, setBufferSize, setCharacterSet
 
Methods inherited from class com.google.clearsilver.jsilver.resourceloader.BaseResourceLoader
close, getKey, getResourceVersionId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLoaderResourceLoader

public ClassLoaderResourceLoader(ClassLoader classLoader,
                                 String basePath)

ClassLoaderResourceLoader

public ClassLoaderResourceLoader(ClassLoader classLoader)
Method Detail

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.