Class HandlebarsHstTemplateServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.onehippo.forge.templating.support.core.servlet.AbstractHstTemplateServlet
org.onehippo.forge.templating.support.handlebars.servlet.HandlebarsHstTemplateServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

public class HandlebarsHstTemplateServlet extends AbstractHstTemplateServlet
Handlebars specific Templating Support Servlet for Hippo CMS Delivery tier web application.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default HST related helpers prefix.
    static final String
    Servlet context init param name for whether or not the template cache should be enabled.
    static final String
    Servlet context init param name for the prefix of HST related helpers.
    static final long
     

    Fields inherited from class org.onehippo.forge.templating.support.core.servlet.AbstractHstTemplateServlet

    CLASSPATH_TEMPLATE_PROTOCOL, WEB_FILE_TEMPLATE_PROTOCOL

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Clear the template cache if available in the subclass.
    protected com.github.jknack.handlebars.cache.TemplateCache
    createTemplateCache(jakarta.servlet.ServletConfig config)
    Create a Handlebars' TemplateCache instance.
    protected Object
    createTemplateContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Create a templating engine specific Context object which can be evaluated by the template.
    protected com.github.jknack.handlebars.io.TemplateLoader
    createTemplateLoader(jakarta.servlet.ServletConfig config)
    Create a template loader.
    protected void
    initializeTemplateEngine(jakarta.servlet.ServletConfig config)
    Initialize the specific templating engine in a subclass.
    protected void
    processTemplate(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String templatePath, Object context)
    Resolve the template by the templatePath and process the template for the request with the templating engine specific context object.
    protected void
    registerHelpers(jakarta.servlet.ServletConfig config, com.github.jknack.handlebars.Handlebars handlebars)
    Register default helpers.

    Methods inherited from class org.onehippo.forge.templating.support.core.servlet.AbstractHstTemplateServlet

    doGet, doPost, getTemplatePath, init

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service

    Methods inherited from class jakarta.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • serialVersionUID

      public static final long serialVersionUID
      See Also:
    • PARAM_CACHE_ENABLED

      public static final String PARAM_CACHE_ENABLED
      Servlet context init param name for whether or not the template cache should be enabled.
      See Also:
    • PARAM_HST_HELPERS_PREFIX

      public static final String PARAM_HST_HELPERS_PREFIX
      Servlet context init param name for the prefix of HST related helpers.
      See Also:
    • DEFAULT_HST_HELPERS_PREFIX

      public static final String DEFAULT_HST_HELPERS_PREFIX
      Default HST related helpers prefix.
      See Also:
  • Constructor Details

    • HandlebarsHstTemplateServlet

      public HandlebarsHstTemplateServlet()
  • Method Details

    • initializeTemplateEngine

      protected void initializeTemplateEngine(jakarta.servlet.ServletConfig config) throws jakarta.servlet.ServletException
      Description copied from class: AbstractHstTemplateServlet
      Initialize the specific templating engine in a subclass. This method is invoked by AbstractHstTemplateServlet.init(ServletConfig) method during the initialization phase.
      Specified by:
      initializeTemplateEngine in class AbstractHstTemplateServlet
      Parameters:
      config - ServletConfig object
      Throws:
      jakarta.servlet.ServletException - if servlet exception occurs
    • createTemplateContext

      protected Object createTemplateContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException
      Description copied from class: AbstractHstTemplateServlet
      Create a templating engine specific Context object which can be evaluated by the template.

      This method is invoked by AbstractHstTemplateServlet.process(HttpServletRequest, HttpServletResponse) method before invoking AbstractHstTemplateServlet.processTemplate(HttpServletRequest, HttpServletResponse, String, Object) to pass a Context object to the AbstractHstTemplateServlet.processTemplate(HttpServletRequest, HttpServletResponse, String, Object).

      Specified by:
      createTemplateContext in class AbstractHstTemplateServlet
      Parameters:
      request - HttpServletRequest instance
      response - HttpServletResponse instance
      Returns:
      a Context object which can be evaluated by the template
      Throws:
      jakarta.servlet.ServletException - if servlet exception occurs
      IOException - if IO exception occurs
    • processTemplate

      protected void processTemplate(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String templatePath, Object context) throws jakarta.servlet.ServletException, IOException
      Description copied from class: AbstractHstTemplateServlet
      Resolve the template by the templatePath and process the template for the request with the templating engine specific context object.
      Specified by:
      processTemplate in class AbstractHstTemplateServlet
      Parameters:
      request - HttpServletRequest instance
      response - HttpServletResponse instance
      templatePath - template path
      context - Templating engine specific Context object which is evaluated by the template
      Throws:
      jakarta.servlet.ServletException - if servlet exception occurs
      IOException - if IO exception occurs
    • clearTemplateCache

      protected void clearTemplateCache()
      Description copied from class: AbstractHstTemplateServlet
      Clear the template cache if available in the subclass. It does nothing by default unless overridden.
      Overrides:
      clearTemplateCache in class AbstractHstTemplateServlet
    • createTemplateLoader

      protected com.github.jknack.handlebars.io.TemplateLoader createTemplateLoader(jakarta.servlet.ServletConfig config) throws jakarta.servlet.ServletException
      Create a template loader. This method is invoked by initializeTemplateEngine(ServletConfig) during the initialization phase.

      By default, this method instantiates an ProtocolBasedDelegatingTemplateLoader which should be able to handle webfiles or classpath or servlet path based templates by delegating based on the protocol used in the template path.

      Parameters:
      config - ServletConfig instance
      Returns:
      Handlebars' TemplateLoader instance.
      Throws:
      jakarta.servlet.ServletException - if servlet exception occurs.
    • createTemplateCache

      protected com.github.jknack.handlebars.cache.TemplateCache createTemplateCache(jakarta.servlet.ServletConfig config) throws jakarta.servlet.ServletException
      Create a Handlebars' TemplateCache instance. This method is invoked by initializeTemplateEngine(ServletConfig) during the initialization phase.

      By default, this method simply instantiates a ConcurrentMapTemplateCache if PARAM_CACHE_ENABLED servlet init parameter is set to "true".

      Parameters:
      config - ServletConfig instance
      Returns:
      Handlebars' TemplateCache instance.
      Throws:
      jakarta.servlet.ServletException - if servlet exception occurs.
    • registerHelpers

      protected void registerHelpers(jakarta.servlet.ServletConfig config, com.github.jknack.handlebars.Handlebars handlebars)
      Register default helpers.
      Parameters:
      config - ServletConfig instance
      handlebars - Handlebars instance