freemarker.cache
Class ClassTemplateLoader

java.lang.Object
  extended byfreemarker.cache.URLTemplateLoader
      extended byfreemarker.cache.ClassTemplateLoader
All Implemented Interfaces:
TemplateLoader

public class ClassTemplateLoader
extends URLTemplateLoader

A TemplateLoader that uses streams reachable through Class.getResourceAsStream(String) as its source of templates.

Version:
$Id: ClassTemplateLoader.java,v 1.9 2004/03/25 21:18:28 ddekany Exp $
Author:
Attila Szegedi, szegedia at freemail dot hu

Constructor Summary
ClassTemplateLoader()
          Creates a resource template cache that will use its own class to load the resources.
ClassTemplateLoader(java.lang.Class loaderClass)
          Creates a resource template cache that will use the specified class to load the resources.
ClassTemplateLoader(java.lang.Class loaderClass, java.lang.String path)
          Creates a resource template cache that will use the specified class to load the resources.
 
Method Summary
protected  java.net.URL getURL(java.lang.String name)
          Given a template name (plus potential locale decorations) retrieves an URL that points the template source.
 
Methods inherited from class freemarker.cache.URLTemplateLoader
canonicalizePrefix, closeTemplateSource, findTemplateSource, getLastModified, getReader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassTemplateLoader

public ClassTemplateLoader()
Creates a resource template cache that will use its own class to load the resources. It will use the base path of "/". (But you hardly ever should use the default package as the template root, so probably you should do something like this:
new ClassTemplateLoader(SomeClass.class, "/templates"))


ClassTemplateLoader

public ClassTemplateLoader(java.lang.Class loaderClass)
Creates a resource template cache that will use the specified class to load the resources. It will use the base path of "" meaning templates will be resolved relative to the class location, that is, relatively to the directory (package) of the class. (But you hardly ever want to store a Java class in the template root, so probably you should do something like this:
new ClassTemplateLoader(SomeClass.class, "/templates"))

Parameters:
loaderClass - the class whose Class.getResource(String) will be used to load the templates.

ClassTemplateLoader

public ClassTemplateLoader(java.lang.Class loaderClass,
                           java.lang.String path)
Creates a resource template cache that will use the specified class to load the resources. It will use the specified base path. A path that doesn't start with a slash (/) is a path relative to the path (package) of the current class. A path that starts with a slash is an absolute path starting from the classpath root. Path components should be separated by forward slashes independently of the separator character used by the underlying operating system.

Parameters:
loaderClass - the class whose Class.getResource(String) will be used to load the templates.
path - the base path to template resources.
Method Detail

getURL

protected java.net.URL getURL(java.lang.String name)
Description copied from class: URLTemplateLoader
Given a template name (plus potential locale decorations) retrieves an URL that points the template source.

Specified by:
getURL in class URLTemplateLoader
Parameters:
name - the name of the sought template, including the locale decorations.
Returns:
an URL that points to the template source, or null if it can determine that the template source does not exist.