Class TemplateProcessorRegistry

java.lang.Object
org.springframework.extensions.webscripts.TemplateProcessorRegistry

public class TemplateProcessorRegistry extends Object
Registry of Template Processors.

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

Author:
muzquiano, Kevin Roast
  • Constructor Details

    • TemplateProcessorRegistry

      public TemplateProcessorRegistry()
  • Method Details

    • setDefaultTemplateProcessor

      public void setDefaultTemplateProcessor(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, String extension, 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(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(String extension)
      Gets the template processor registered for the given extension
      Parameters:
      extension - the extension
      Returns:
      the template processor by extension
    • findValidTemplatePath

      public String findValidTemplatePath(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 String[] getRegisteredExtensions()
      Returns the extensions with registered processors
      Returns:
      the registered extensions
    • getExtensionForProcessor

      public 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