org.apache.velocity.runtime.resource.loader
Class StringResourceLoader

java.lang.Object
  extended by org.apache.velocity.runtime.resource.loader.ResourceLoader
      extended by org.apache.velocity.runtime.resource.loader.StringResourceLoader

public class StringResourceLoader
extends ResourceLoader

Resource loader that works with Strings. Users should manually add resources to the repository that is know by the factory of this package. Below is an example configuration for this loader. Note that 'repositoryimpl' is not mandatory; if not provided, the factory will fall back on using the default implementation of this package. string.resource.loader.description = Velocity StringResource loader string.resource.loader.class = org.apache.velocity.runtime.resource.loader..StringResourceLoader string.resource.loader.repository.class = org.apache.velocity.runtime.resource.loader.StringResourceRepositoryImpl Resources can be added to the repository like this: StringResourceRepository = StringResourceLoader.getRepository(); String myTemplateName = "/somewhere/intherepo/name"; String myTemplateBody = "Hi, ${username}... this is a some template!"; vsRepository.putStringResource(myTemplateName, myTemplateBody); After this, the templates can be retrieved as usual.

Version:
$Id: StringResourceLoader.java 479058 2006-11-25 00:26:32Z henning $
Author:
Eelco Hillenius, Henning P. Schmiedehausen

Field Summary
static String REPOSITORY_CLASS
          Key to look up the repository implementation class.
static String REPOSITORY_CLASS_DEFAULT
          The default implementation class.
static String REPOSITORY_ENCODING
          Key to look up the repository char encoding.
static String REPOSITORY_ENCODING_DEFAULT
          The default repository encoding.
 
Fields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
className, isCachingOn, log, modificationCheckInterval, rsvc
 
Constructor Summary
StringResourceLoader()
           
 
Method Summary
 long getLastModified(Resource resource)
          Get the last modified time of the InputStream source that was used to create the template.
static StringResourceRepository getRepository()
          Returns a reference to the Repository.
 InputStream getResourceStream(String name)
          Get an InputStream so that the Runtime can build a template with it.
 void init(ExtendedProperties configuration)
          Initialize the template loader with a a resources class.
 boolean isSourceModified(Resource resource)
          Given a template, check to see if the source of InputStream has been modified.
 
Methods inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
commonInit, getClassName, getModificationCheckInterval, isCachingOn, setCachingOn, setModificationCheckInterval
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPOSITORY_CLASS

public static final String REPOSITORY_CLASS
Key to look up the repository implementation class.

See Also:
Constant Field Values

REPOSITORY_CLASS_DEFAULT

public static final String REPOSITORY_CLASS_DEFAULT
The default implementation class.


REPOSITORY_ENCODING

public static final String REPOSITORY_ENCODING
Key to look up the repository char encoding.

See Also:
Constant Field Values

REPOSITORY_ENCODING_DEFAULT

public static final String REPOSITORY_ENCODING_DEFAULT
The default repository encoding.

See Also:
Constant Field Values
Constructor Detail

StringResourceLoader

public StringResourceLoader()
Method Detail

getRepository

public static StringResourceRepository getRepository()
Returns a reference to the Repository.

Returns:
A StringResourceRepository Reference.

init

public void init(ExtendedProperties configuration)
Description copied from class: ResourceLoader
Initialize the template loader with a a resources class.

Specified by:
init in class ResourceLoader
See Also:
ResourceLoader.init(org.apache.commons.collections.ExtendedProperties)

getResourceStream

public InputStream getResourceStream(String name)
                              throws ResourceNotFoundException
Get an InputStream so that the Runtime can build a template with it.

Specified by:
getResourceStream in class ResourceLoader
Parameters:
name - name of template to get.
Returns:
InputStream containing the template.
Throws:
ResourceNotFoundException - Ff template not found in the RepositoryFactory.

isSourceModified

public boolean isSourceModified(Resource resource)
Description copied from class: ResourceLoader
Given a template, check to see if the source of InputStream has been modified.

Specified by:
isSourceModified in class ResourceLoader
Returns:
True if the resource has been modified.
See Also:
ResourceLoader.isSourceModified(org.apache.velocity.runtime.resource.Resource)

getLastModified

public long getLastModified(Resource resource)
Description copied from class: ResourceLoader
Get the last modified time of the InputStream source that was used to create the template. We need the template here because we have to extract the name of the template in order to locate the InputStream source.

Specified by:
getLastModified in class ResourceLoader
Returns:
Time in millis when the resource has been modified.
See Also:
ResourceLoader.getLastModified(org.apache.velocity.runtime.resource.Resource)


Copyright © 2000-2007 The Apache Software Foundation. All Rights Reserved.