Class DefaultMustacheFactory

    • Field Detail

      • mustacheCache

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​Mustache> mustacheCache
        Create the default cache for mustache compilations. This is basically required by the specification to handle recursive templates.
      • oh

        protected ObjectHandler oh
        This is the default object handler.
      • mc

        protected final MustacheParser mc
        This parser should work with any MustacheFactory
      • templateCache

        protected final java.util.concurrent.ConcurrentHashMap<FragmentKey,​Mustache> templateCache
        New templates that are generated at runtime are cached here. The template key includes the text of the template and the context so we get proper error messages and debugging information.
      • recursionLimit

        protected int recursionLimit
      • es

        protected java.util.concurrent.ExecutorService es
      • partialCache

        private final java.lang.ThreadLocal<java.util.Map<java.lang.String,​Mustache>> partialCache
    • Constructor Detail

      • DefaultMustacheFactory

        public DefaultMustacheFactory()
      • DefaultMustacheFactory

        public DefaultMustacheFactory​(MustacheResolver mustacheResolver)
      • DefaultMustacheFactory

        public DefaultMustacheFactory​(java.lang.String classpathResourceRoot)
        Use the classpath to resolve mustache templates.
        Parameters:
        classpathResourceRoot - the location in the resources where templates are stored
      • DefaultMustacheFactory

        public DefaultMustacheFactory​(java.io.File fileRoot)
        Use the file system to resolve mustache templates.
        Parameters:
        fileRoot - the root of the file system where templates are stored
    • Method Detail

      • resolvePartialPath

        public 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.
        Parameters:
        dir -
        name -
        extension -
        Returns:
      • ensureForwardSlash

        private static java.lang.String ensureForwardSlash​(java.lang.String path)
      • getReader

        public java.io.Reader getReader​(java.lang.String resourceName)
        Description copied from interface: MustacheFactory
        Given a resource name, construct a reader.
        Specified by:
        getReader in interface MustacheFactory
        Parameters:
        resourceName - used to find the resource
        Returns:
        a reader
      • encode

        public void encode​(java.lang.String value,
                           java.io.Writer writer)
        Description copied from interface: MustacheFactory
        This defines how "encoded" values are encoded. It defaults to something appropriate for HTML output.
        Specified by:
        encode in interface MustacheFactory
        Parameters:
        value - the unencoded value
        writer - where to encode the value
      • setObjectHandler

        public void setObjectHandler​(ObjectHandler oh)
        You can override the default object handler post construction.
        Parameters:
        oh - The object handler to use.
      • getExecutorService

        public 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.
        Returns:
        the executor service
      • setExecutorService

        public void setExecutorService​(java.util.concurrent.ExecutorService es)
        If you need to specify your own executor service you can.
        Parameters:
        es - The executor service to use for Future evaluation
      • getFragmentCacheFunction

        protected java.util.function.Function<FragmentKey,​Mustache> getFragmentCacheFunction()
      • compile

        public Mustache compile​(java.lang.String name)
        Description copied from interface: MustacheFactory
        Create a mustache given a resource name.
        Specified by:
        compile in interface MustacheFactory
        Parameters:
        name - the name of the resource
        Returns:
        the compiled mustache
      • compile

        public Mustache compile​(java.io.Reader reader,
                                java.lang.String name)
        Description copied from interface: MustacheFactory
        Create a mustache given a reader and a name.
        Specified by:
        compile in interface MustacheFactory
        Parameters:
        reader - the reader
        name - the name of the resource
        Returns:
        the compiled mustache
      • compile

        public Mustache compile​(java.io.Reader reader,
                                java.lang.String file,
                                java.lang.String sm,
                                java.lang.String em)
      • translate

        public java.lang.String translate​(java.lang.String from)
        Description copied from interface: MustacheFactory
        Converts your arbitrary name to another name.
        Specified by:
        translate in interface MustacheFactory
        Parameters:
        from - the tag to replace
        Returns:
        the new tag
      • filterText

        public 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.
        Parameters:
        appended - The text to be appended to the output
        startOfLine - Are we at the start of the line?
        Returns:
        the filtered string
      • setRecursionLimit

        public void setRecursionLimit​(int recursionLimit)
        Maximum recursion limit for partials.
        Parameters:
        recursionLimit - the number of recursions we will attempt before failing
      • getRecursionLimit

        public int getRecursionLimit()
      • compilePartial

        public 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.
        Parameters:
        s - the name of the partial to compile
        Returns:
        the compiled partial
      • getMustacheCacheFunction

        protected java.util.function.Function<java.lang.String,​Mustache> getMustacheCacheFunction()
      • createMustacheCache

        protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​Mustache> createMustacheCache()
      • createLambdaCache

        protected java.util.concurrent.ConcurrentHashMap<FragmentKey,​Mustache> createLambdaCache()