com.google.clearsilver.jsilver.resourceloader
Interface ResourceLoader

All Known Implementing Classes:
BaseResourceLoader, BufferedResourceLoader, ClassLoaderResourceLoader, ClassResourceLoader, CompositeResourceLoader, FileSystemResourceLoader, InMemoryResourceLoader, ResourceLoaderAdaptor

public interface ResourceLoader

Loads resources, from somewhere. This is a service provider interface (SPI) for JSilver. Users of JSilver can easily create their own implementations. However, it is recommended that new implementations don't implement this interface directly, but instead extends BaseResourceLoader. This allows API changes to be made to JSilver that maintain compatibility with existing ResourceLoader implementations.

See Also:
BaseResourceLoader, InMemoryResourceLoader, FileSystemResourceLoader, ClassLoaderResourceLoader, ClassResourceLoader

Method Summary
 void close(Reader reader)
          Close the reader.
 Object getKey(String filename)
          Returns an object that can be used to uniquely identify the file corresponding to the given file name in the context of this ResourceLoader.
 Object getResourceVersionId(String name)
          Returns an object that can be used to identify when a resource has changed.
 Reader open(String name)
          Open a resource.
 Reader openOrFail(String name)
          Open a resource or throw an exception if no such resource is found.
 

Method Detail

open

Reader open(String name)
            throws IOException
Open a resource. If this resource is not found, null should be returned. The caller of this method is guaranteed to call 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

Reader openOrFail(String name)
                  throws JSilverTemplateNotFoundException,
                         IOException
Open a resource or throw an exception if no such resource is found. The caller of this method is guaranteed to call 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

close

void close(Reader reader)
           throws IOException
Close the reader. Allows ResourceLoader to perform any additional clean up.

Parameters:
reader - the reader to close
Throws:
IOException - if reader fasils to close

getKey

Object getKey(String filename)
Returns an object that can be used to uniquely identify the file corresponding to the given file name in the context of this ResourceLoader. (e.g. ordered list of directories + filename, or absolute file path.).

Parameters:
filename - the name we want to identify
Returns:
unique identifier

getResourceVersionId

Object getResourceVersionId(String name)
Returns an object that can be used to identify when a resource has changed. This key should be based on some piece(s) of metadata that strongly indicates the resource has changed, for example a file's last modified time. Since the object is expected to be used as part of a cache key, it should be immutable and implement Object.equals(Object) and Object.hashCode() . If the ResourceLoader does not or cannot compute a version identifier then it is sufficient to always return the same Object, e.g. the resource name. Null, however, should only be returned if a call to open(String) would also return null.

Parameters:
name - the name of the resource to check for resources
Returns:
unique identifier for the current version of the resource or null if the resource cannot be found


Copyright © 2010-2012 Google. All Rights Reserved.