Package com.github.jknack.handlebars.io
Class CompositeTemplateLoader
- java.lang.Object
-
- com.github.jknack.handlebars.io.CompositeTemplateLoader
-
- All Implemented Interfaces:
TemplateLoader
public class CompositeTemplateLoader extends java.lang.Object implements TemplateLoader
Combine two or more
TemplateLoader
as a singleTemplateLoader
.TemplateLoader
s are executed in the order they are provided.Execution is as follows:
- If a
TemplateLoader
is able to resolve aTemplateSource
, thatTemplateSource
is considered the response. - If a
TemplateLoader
throws aIOException
exception the nextTemplateLoader
in the chain will be used.
- Since:
- 1.0.0
-
-
Field Summary
-
Fields inherited from interface com.github.jknack.handlebars.io.TemplateLoader
DEFAULT_PREFIX, DEFAULT_SUFFIX
-
-
Constructor Summary
Constructors Constructor Description CompositeTemplateLoader(TemplateLoader... loaders)
Creates a newCompositeTemplateLoader
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.charset.Charset
getCharset()
java.lang.Iterable<TemplateLoader>
getDelegates()
Returns the delegates template loaders.java.lang.String
getPrefix()
java.lang.String
getSuffix()
java.lang.String
resolve(java.lang.String location)
Resolve a relative location to an absolute location.void
setCharset(java.nio.charset.Charset charset)
Set the default charset.void
setPrefix(java.lang.String prefix)
Set the prefix that gets prepended to view names when building a URI.void
setSuffix(java.lang.String suffix)
Set the suffix that gets appended to view names when building a URI.TemplateSource
sourceAt(java.lang.String location)
Get a template source from location.
-
-
-
Constructor Detail
-
CompositeTemplateLoader
public CompositeTemplateLoader(TemplateLoader... loaders)
Creates a newCompositeTemplateLoader
.- Parameters:
loaders
- The template loader chain. At least two loaders must be provided.
-
-
Method Detail
-
sourceAt
public TemplateSource sourceAt(java.lang.String location) throws java.io.IOException
Description copied from interface:TemplateLoader
Get a template source from location.- Specified by:
sourceAt
in interfaceTemplateLoader
- Parameters:
location
- The location of the template source. Required.- Returns:
- A new template source.
- Throws:
java.io.IOException
- If the template's source can't be resolved.
-
resolve
public java.lang.String resolve(java.lang.String location)
Description copied from interface:TemplateLoader
Resolve a relative location to an absolute location.- Specified by:
resolve
in interfaceTemplateLoader
- Parameters:
location
- The candidate location.- Returns:
- Resolve the uri to an absolute location.
-
getPrefix
public java.lang.String getPrefix()
- Specified by:
getPrefix
in interfaceTemplateLoader
- Returns:
- The prefix that gets prepended to view names when building a URI.
-
getSuffix
public java.lang.String getSuffix()
- Specified by:
getSuffix
in interfaceTemplateLoader
- Returns:
- The suffix that gets appended to view names when building a URI.
-
setPrefix
public void setPrefix(java.lang.String prefix)
Description copied from interface:TemplateLoader
Set the prefix that gets prepended to view names when building a URI.- Specified by:
setPrefix
in interfaceTemplateLoader
- Parameters:
prefix
- The prefix that gets prepended to view names when building a URI.
-
setSuffix
public void setSuffix(java.lang.String suffix)
Description copied from interface:TemplateLoader
Set the suffix that gets appended to view names when building a URI.- Specified by:
setSuffix
in interfaceTemplateLoader
- Parameters:
suffix
- The suffix that gets appended to view names when building a URI.
-
setCharset
public void setCharset(java.nio.charset.Charset charset)
Description copied from interface:TemplateLoader
Set the default charset.- Specified by:
setCharset
in interfaceTemplateLoader
- Parameters:
charset
- Charset.
-
getCharset
public java.nio.charset.Charset getCharset()
- Specified by:
getCharset
in interfaceTemplateLoader
- Returns:
- Charset.
-
getDelegates
public java.lang.Iterable<TemplateLoader> getDelegates()
Returns the delegates template loaders.- Returns:
- The delegates template loaders.
-
-