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
Handlebars specific Templating Support Servlet for Hippo CMS Delivery tier web application.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic 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
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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 thetemplatePath
and process the template for the request with the templating engine specificcontext
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
-
Field Details
-
serialVersionUID
public static final long serialVersionUID- See Also:
-
PARAM_CACHE_ENABLED
Servlet context init param name for whether or not the template cache should be enabled.- See Also:
-
PARAM_HST_HELPERS_PREFIX
Servlet context init param name for the prefix of HST related helpers.- See Also:
-
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 byAbstractHstTemplateServlet.init(ServletConfig)
method during the initialization phase.- Specified by:
initializeTemplateEngine
in classAbstractHstTemplateServlet
- 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 invokingAbstractHstTemplateServlet.processTemplate(HttpServletRequest, HttpServletResponse, String, Object)
to pass a Context object to theAbstractHstTemplateServlet.processTemplate(HttpServletRequest, HttpServletResponse, String, Object)
.- Specified by:
createTemplateContext
in classAbstractHstTemplateServlet
- Parameters:
request
- HttpServletRequest instanceresponse
- HttpServletResponse instance- Returns:
- a Context object which can be evaluated by the template
- Throws:
jakarta.servlet.ServletException
- if servlet exception occursIOException
- 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 thetemplatePath
and process the template for the request with the templating engine specificcontext
object.- Specified by:
processTemplate
in classAbstractHstTemplateServlet
- Parameters:
request
- HttpServletRequest instanceresponse
- HttpServletResponse instancetemplatePath
- template pathcontext
- Templating engine specific Context object which is evaluated by the template- Throws:
jakarta.servlet.ServletException
- if servlet exception occursIOException
- 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 classAbstractHstTemplateServlet
-
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 byinitializeTemplateEngine(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 byinitializeTemplateEngine(ServletConfig)
during the initialization phase.By default, this method simply instantiates a
ConcurrentMapTemplateCache
ifPARAM_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 instancehandlebars
- Handlebars instance
-