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
FieldsModifier and TypeFieldDescriptionstatic final StringDefault HST related helpers prefix.static final StringServlet context init param name for whether or not the template cache should be enabled.static final StringServlet context init param name for the prefix of HST related helpers.static final longFields inherited from class org.onehippo.forge.templating.support.core.servlet.AbstractHstTemplateServlet
CLASSPATH_TEMPLATE_PROTOCOL, WEB_FILE_TEMPLATE_PROTOCOLFields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidClear the template cache if available in the subclass.protected com.github.jknack.handlebars.cache.TemplateCachecreateTemplateCache(jakarta.servlet.ServletConfig config) Create a Handlebars'TemplateCacheinstance.protected ObjectcreateTemplateContext(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.TemplateLoadercreateTemplateLoader(jakarta.servlet.ServletConfig config) Create a template loader.protected voidinitializeTemplateEngine(jakarta.servlet.ServletConfig config) Initialize the specific templating engine in a subclass.protected voidprocessTemplate(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String templatePath, Object context) Resolve the template by thetemplatePathand process the template for the request with the templating engine specificcontextobject.protected voidregisterHelpers(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, initMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, serviceMethods 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:AbstractHstTemplateServletInitialize the specific templating engine in a subclass. This method is invoked byAbstractHstTemplateServlet.init(ServletConfig)method during the initialization phase.- Specified by:
initializeTemplateEnginein 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:AbstractHstTemplateServletCreate 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:
createTemplateContextin 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:AbstractHstTemplateServletResolve the template by thetemplatePathand process the template for the request with the templating engine specificcontextobject.- Specified by:
processTemplatein 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:AbstractHstTemplateServletClear the template cache if available in the subclass. It does nothing by default unless overridden.- Overrides:
clearTemplateCachein 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
ProtocolBasedDelegatingTemplateLoaderwhich 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'
TemplateLoaderinstance. - 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'TemplateCacheinstance. This method is invoked byinitializeTemplateEngine(ServletConfig)during the initialization phase.By default, this method simply instantiates a
ConcurrentMapTemplateCacheifPARAM_CACHE_ENABLEDservlet init parameter is set to "true".- Parameters:
config- ServletConfig instance- Returns:
- Handlebars'
TemplateCacheinstance. - 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
-