com.google.clearsilver.jsilver.resourceloader
Class InMemoryResourceLoader

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

public class InMemoryResourceLoader
extends BaseResourceLoader

ResourceLoader that pulls all items from memory. This is particularly useful for small templates that can be embedded in code (e.g. in unit tests). Content needs to be stored first using the store(String, String) method.

See Also:
ResourceLoader

Constructor Summary
InMemoryResourceLoader()
           
 
Method Summary
 ConcurrentMap<String,String> getItems()
           
 Reader open(String name)
          Open a resource.
 Reader openOrFail(String name)
          Open a resource or throw an exception if no such resource is found.
 void remove(String name)
           
 void store(String name, String contents)
           
 
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

InMemoryResourceLoader

public InMemoryResourceLoader()
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

store

public void store(String name,
                  String contents)

remove

public void remove(String name)

getItems

public ConcurrentMap<String,String> getItems()


Copyright © 2010-2012 Google. All Rights Reserved.