Class ThymeleafDispatcher

java.lang.Object
org.apache.juneau.rest.server.view.thymeleaf.ThymeleafDispatcher
All Implemented Interfaces:
RawTemplateDispatcher

public class ThymeleafDispatcher extends Object implements RawTemplateDispatcher
Flavor-neutral worker bean carrying the Thymeleaf raw-template-dispatch logic shared by the ThymeleafMixin mixin, the ThymeleafServlet servlet, and the ThymeleafResource child flavors.

This is the flavor-neutral worker for the Thymeleaf capability: it is not one of the three @Rest flavor classes — it is a plain bean that implements RawTemplateDispatcher and holds the capability state (basePath / cacheTemplates / templateMode / lazy default engine) plus the raw-serve and engine-resolution logic. Each flavor independently holds an instance of this worker and delegates to it, so no flavor is another flavor's worker.

See Also:
Since:
10.0.0
  • Field Details

  • Constructor Details

  • Method Details

    • create

      Creates a new builder.
      Returns:
      A new builder.
    • getBasePath

      public String getBasePath()
      Returns the base path under which template resources are resolved.
      Returns:
      The base path. Never null.
    • isCacheTemplates

      public boolean isCacheTemplates()
      Returns whether the bridge's default engine caches resolved templates.
      Returns:
      The cache flag. Defaults to DEFAULT_CACHE_TEMPLATES.
    • getTemplateMode

      public org.thymeleaf.templatemode.TemplateMode getTemplateMode()
      Returns the template mode used by the bridge's default engine.
      Returns:
      The template mode. Defaults to DEFAULT_TEMPLATE_MODE.
    • resolveTemplateEngine

      public org.thymeleaf.TemplateEngine resolveTemplateEngine(RestRequest req)
      Resolves the active TemplateEngine.

      Lookup order:

      1. req.getContext().getBeanStore().getBean(TemplateEngine.class) — covers Spring Boot autoconfig (`SpringTemplateEngine` is-a `TemplateEngine`) and any user-supplied bean.
      2. Lazy bridge default — constructed on first call when no engine bean is registered. Carries a single ClassLoaderTemplateResolver keyed off (basePath, .html, templateMode, cacheTemplates).
      Parameters:
      req - The current REST request.
      Returns:
      The active template engine. Never null.
    • buildDefaultEngine

      protected org.thymeleaf.TemplateEngine buildDefaultEngine()
      Constructs the bridge-default TemplateEngine.

      Single ClassLoaderTemplateResolver with prefix=basePath, suffix=".html", templateMode=templateMode, and cacheable=cacheTemplates. Subclasses may override to plug in custom resolvers / dialects without registering a separate @Bean TemplateEngine.

      Returns:
      A new TemplateEngine instance.
    • render

      public void render(String path, RestRequest req, RestResponse res) throws IOException, BasicHttpException
      Renders a raw template through the Thymeleaf engine onto the response.
      Specified by:
      render in interface RawTemplateDispatcher
      Parameters:
      path - The trailing path segment after the mount prefix (the template name relative to the configured base path; trailing .html stripped).
      req - The current REST request.
      res - The current REST response.
      Throws:
      IOException - If the underlying response writer fails.
      BasicHttpException - On boundary violation (403), missing engine (500), or render failure (500).