Class TemplateProcessorRegistry


  • public class TemplateProcessorRegistry
    extends java.lang.Object
    Registry of Template Processors.

    If no processors are registered, the default script processor is the freemarker processor.

    Author:
    muzquiano, Kevin Roast
    • Constructor Detail

      • TemplateProcessorRegistry

        public TemplateProcessorRegistry()
    • Method Detail

      • setDefaultTemplateProcessor

        public void setDefaultTemplateProcessor​(java.lang.String defaultTemplateProcessorName)
        Sets the name of the default template processor
        Parameters:
        defaultTemplateProcessorName - the name of the default template processor
      • registerTemplateProcessor

        public void registerTemplateProcessor​(TemplateProcessor templateProcessor)
        Registers a template processor
        Parameters:
        templateProcessor - the template processor to register
      • registerTemplateProcessor

        public void registerTemplateProcessor​(TemplateProcessor templateProcessor,
                                              java.lang.String extension,
                                              java.lang.String name)
        Registers a template processor
        Parameters:
        templateProcessor - the template processor to register
        extension - String
        name - String
      • getDefaultTemplateProcessor

        protected TemplateProcessor getDefaultTemplateProcessor()
        Gets the default template processor.
        Returns:
        the default template processor
      • getTemplateProcessor

        public TemplateProcessor getTemplateProcessor​(java.lang.String path)
        Returns the best fit template processor for the given path If a template processor cannot be matched to the path, the default template processor will be returned.
        Parameters:
        path - the path
        Returns:
        the template processor
      • getTemplateProcessorByExtension

        public TemplateProcessor getTemplateProcessorByExtension​(java.lang.String extension)
        Gets the template processor registered for the given extension
        Parameters:
        extension - the extension
        Returns:
        the template processor by extension
      • findValidTemplatePath

        public java.lang.String findValidTemplatePath​(java.lang.String path)
        Returns a variation on the provided path that exists and is processable by one of the processors in this registry.

        First attempts to find a template processor that contains the content located at the given path (using extension information, if available).

        If no match is found, iterates over the file extensions and attempts to find a match.

        Path can therefore be values like:

           testfile.ftl
             - matches to file testfile.ftl using freemarker procesor
         
           testfile
             - matches for all extensions, potentially looking at 
               testfile.ftl, testfile.php, etc.
         
        The extension annotated path is returned which will correctly dispatch to the discovered processor.
        Parameters:
        path - the path
        Returns:
        a valid processor file path or null if no match
      • getRegisteredExtensions

        public java.lang.String[] getRegisteredExtensions()
        Returns the extensions with registered processors
        Returns:
        the registered extensions
      • getExtensionForProcessor

        public java.lang.String getExtensionForProcessor​(TemplateProcessor templateProcessor)
        Gets the extension for given processor.
        Parameters:
        templateProcessor - the template processor
        Returns:
        the extension for processor
      • reset

        public void reset()
        Resets all of the registered template processors