public class DefaultMustacheFactory extends java.lang.Object implements MustacheFactory
| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.ExecutorService |
es |
protected MustacheParser |
mc
This parser should work with any MustacheFactory
|
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,Mustache> |
mustacheCache
Create the default cache for mustache compilations.
|
private MustacheResolver |
mustacheResolver |
protected ObjectHandler |
oh
This is the default object handler.
|
private java.lang.ThreadLocal<java.util.Map<java.lang.String,Mustache>> |
partialCache |
protected int |
recursionLimit |
protected java.util.concurrent.ConcurrentHashMap<FragmentKey,Mustache> |
templateCache
New templates that are generated at runtime are cached here.
|
| Constructor and Description |
|---|
DefaultMustacheFactory() |
DefaultMustacheFactory(java.io.File fileRoot)
Use the file system to resolve mustache templates.
|
DefaultMustacheFactory(MustacheResolver mustacheResolver) |
DefaultMustacheFactory(java.lang.String classpathResourceRoot)
Use the classpath to resolve mustache templates.
|
| Modifier and Type | Method and Description |
|---|---|
Mustache |
compile(java.io.Reader reader,
java.lang.String name)
Create a mustache given a reader and a name.
|
Mustache |
compile(java.io.Reader reader,
java.lang.String file,
java.lang.String sm,
java.lang.String em) |
Mustache |
compile(java.lang.String name)
Create a mustache given a resource name.
|
Mustache |
compilePartial(java.lang.String s)
In order to handle recursion, we need a temporary thread local cache during compilation
that is ultimately thrown away after the top level partial is complete.
|
protected java.util.concurrent.ConcurrentHashMap<FragmentKey,Mustache> |
createLambdaCache() |
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,Mustache> |
createMustacheCache() |
MustacheVisitor |
createMustacheVisitor()
Creates the visitor for compilation.
|
void |
encode(java.lang.String value,
java.io.Writer writer)
This defines how "encoded" values are encoded.
|
private static java.lang.String |
ensureForwardSlash(java.lang.String path) |
java.lang.String |
filterText(java.lang.String appended,
boolean startOfLine)
Override this method to apply any filtering to text that will appear
verbatim in the output template.
|
java.util.concurrent.ExecutorService |
getExecutorService()
There is an ExecutorService that is used when executing parallel
operations when a Callable is returned from a mustache value or iterable.
|
Mustache |
getFragment(FragmentKey templateKey) |
protected java.util.function.Function<FragmentKey,Mustache> |
getFragmentCacheFunction() |
protected java.util.function.Function<java.lang.String,Mustache> |
getMustacheCacheFunction() |
ObjectHandler |
getObjectHandler()
The object handler knows how to transform names into fields and methods.
|
java.io.Reader |
getReader(java.lang.String resourceName)
Given a resource name, construct a reader.
|
int |
getRecursionLimit() |
java.lang.String |
resolvePartialPath(java.lang.String dir,
java.lang.String name,
java.lang.String extension)
Using the directory, namd and extension, resolve a partial to a name.
|
void |
setExecutorService(java.util.concurrent.ExecutorService es)
If you need to specify your own executor service you can.
|
void |
setObjectHandler(ObjectHandler oh)
You can override the default object handler post construction.
|
void |
setRecursionLimit(int recursionLimit)
Maximum recursion limit for partials.
|
java.lang.String |
translate(java.lang.String from)
Converts your arbitrary name to another name.
|
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,Mustache> mustacheCache
protected ObjectHandler oh
protected final MustacheParser mc
protected final java.util.concurrent.ConcurrentHashMap<FragmentKey,Mustache> templateCache
protected int recursionLimit
private final MustacheResolver mustacheResolver
protected java.util.concurrent.ExecutorService es
private final java.lang.ThreadLocal<java.util.Map<java.lang.String,Mustache>> partialCache
public DefaultMustacheFactory()
public DefaultMustacheFactory(MustacheResolver mustacheResolver)
public DefaultMustacheFactory(java.lang.String classpathResourceRoot)
classpathResourceRoot - the location in the resources where templates are storedpublic DefaultMustacheFactory(java.io.File fileRoot)
fileRoot - the root of the file system where templates are storedpublic java.lang.String resolvePartialPath(java.lang.String dir,
java.lang.String name,
java.lang.String extension)
dir - name - extension - private static java.lang.String ensureForwardSlash(java.lang.String path)
public MustacheVisitor createMustacheVisitor()
MustacheFactorycreateMustacheVisitor in interface MustacheFactorypublic java.io.Reader getReader(java.lang.String resourceName)
MustacheFactorygetReader in interface MustacheFactoryresourceName - used to find the resourcepublic void encode(java.lang.String value,
java.io.Writer writer)
MustacheFactoryencode in interface MustacheFactoryvalue - the unencoded valuewriter - where to encode the valuepublic ObjectHandler getObjectHandler()
MustacheFactorygetObjectHandler in interface MustacheFactorypublic void setObjectHandler(ObjectHandler oh)
oh - The object handler to use.public java.util.concurrent.ExecutorService getExecutorService()
public void setExecutorService(java.util.concurrent.ExecutorService es)
es - The executor service to use for Future evaluationpublic Mustache getFragment(FragmentKey templateKey)
protected java.util.function.Function<FragmentKey,Mustache> getFragmentCacheFunction()
public Mustache compile(java.lang.String name)
MustacheFactorycompile in interface MustacheFactoryname - the name of the resourcepublic Mustache compile(java.io.Reader reader, java.lang.String name)
MustacheFactorycompile in interface MustacheFactoryreader - the readername - the name of the resourcepublic Mustache compile(java.io.Reader reader, java.lang.String file, java.lang.String sm, java.lang.String em)
public java.lang.String translate(java.lang.String from)
MustacheFactorytranslate in interface MustacheFactoryfrom - the tag to replacepublic java.lang.String filterText(java.lang.String appended,
boolean startOfLine)
appended - The text to be appended to the outputstartOfLine - Are we at the start of the line?public void setRecursionLimit(int recursionLimit)
recursionLimit - the number of recursions we will attempt before failingpublic int getRecursionLimit()
public Mustache compilePartial(java.lang.String s)
s - the name of the partial to compileprotected java.util.function.Function<java.lang.String,Mustache> getMustacheCacheFunction()
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,Mustache> createMustacheCache()
protected java.util.concurrent.ConcurrentHashMap<FragmentKey,Mustache> createLambdaCache()