com.github.jknack.handlebars
Class TemplateLoader

java.lang.Object
  extended by com.github.jknack.handlebars.TemplateLoader
Direct Known Subclasses:
ClassTemplateLoader, FileTemplateLoader, ServletContextTemplateLoader

public abstract class TemplateLoader
extends Object

Locate resource in a resource repository like: classpath, filesystem, network, web context.

Since:
0.1.0
Author:
edgar.espina

Field Summary
static String DEFAULT_PREFIX
          The default view prefix.
static String DEFAULT_SUFFIX
          The default view suffix.
 
Constructor Summary
TemplateLoader()
           
 
Method Summary
 String getPrefix()
           
 String getSuffix()
           
 Reader load(URI uri)
          Load the template from a template repository.
 String loadAsString(URI uri)
          Load the template as string from a template repository.
protected abstract  Reader read(String location)
          Read the resource from the given URI.
 String resolve(String uri)
          Resolve the uri to an absolute location.
 void setPrefix(String prefix)
          Set the prefix that gets prepended to view names when building a URI.
 void setSuffix(String suffix)
          Set the suffix that gets appended to view names when building a URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PREFIX

public static final String DEFAULT_PREFIX
The default view prefix.

See Also:
Constant Field Values

DEFAULT_SUFFIX

public static final String DEFAULT_SUFFIX
The default view suffix.

See Also:
Constant Field Values
Constructor Detail

TemplateLoader

public TemplateLoader()
Method Detail

load

public Reader load(URI uri)
            throws IOException
Load the template from a template repository.

Parameters:
uri - The resource's uri. Required.
Returns:
The requested resource.
Throws:
IOException - If the resource cannot be loaded.

loadAsString

public String loadAsString(URI uri)
                    throws IOException
Load the template as string from a template repository.

Parameters:
uri - The resource's uri. Required.
Returns:
The requested resource.
Throws:
IOException - If the resource cannot be loaded.

resolve

public String resolve(String uri)
Resolve the uri to an absolute location.

Parameters:
uri - The candidate uri.
Returns:
Resolve the uri to an absolute location.

read

protected abstract Reader read(String location)
                        throws IOException
Read the resource from the given URI.

Parameters:
location - The resource's location.
Returns:
The requested resource or null if not found.
Throws:
IOException - If the resource cannot be loaded.

setPrefix

public void setPrefix(String prefix)
Set the prefix that gets prepended to view names when building a URI.

Parameters:
prefix - The prefix that gets prepended to view names when building a URI.

setSuffix

public void setSuffix(String suffix)
Set the suffix that gets appended to view names when building a URI.

Parameters:
suffix - The suffix that gets appended to view names when building a URI.

getPrefix

public String getPrefix()
Returns:
The prefix that gets prepended to view names when building a URI.

getSuffix

public String getSuffix()
Returns:
The suffix that gets appended to view names when building a URI.


Copyright © 2012. All Rights Reserved.