Class ThymeleafDispatcher
java.lang.Object
org.apache.juneau.rest.server.view.thymeleaf.ThymeleafDispatcher
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault base path applied when noThymeleafDispatcher.Builder.basePath(String)call has been made.static final booleanDefault template-cache flag — production-safe; opt out per-builder for dev.static final org.thymeleaf.templatemode.TemplateModeDefault template mode for the bridge's fallback engine. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBuilder constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.thymeleaf.TemplateEngineConstructs the bridge-defaultTemplateEngine.static ThymeleafDispatcher.Buildercreate()Creates a new builder.Returns the base path under which template resources are resolved.org.thymeleaf.templatemode.TemplateModeReturns the template mode used by the bridge's default engine.booleanReturns whether the bridge's default engine caches resolved templates.voidrender(String path, RestRequest req, RestResponse res) Renders a raw template through the Thymeleaf engine onto the response.org.thymeleaf.TemplateEngineResolves the activeTemplateEngine.
-
Field Details
-
DEFAULT_BASE_PATH
Default base path applied when noThymeleafDispatcher.Builder.basePath(String)call has been made.- See Also:
-
DEFAULT_CACHE_TEMPLATES
Default template-cache flag — production-safe; opt out per-builder for dev.- See Also:
-
DEFAULT_TEMPLATE_MODE
Default template mode for the bridge's fallback engine.
-
-
Constructor Details
-
ThymeleafDispatcher
Builder constructor.- Parameters:
builder- The builder. Must not benull.
-
-
Method Details
-
create
Creates a new builder.- Returns:
- A new builder.
-
getBasePath
Returns the base path under which template resources are resolved.- Returns:
- The base path. Never
null.
-
isCacheTemplates
Returns whether the bridge's default engine caches resolved templates.- Returns:
- The cache flag. Defaults to
DEFAULT_CACHE_TEMPLATES.
-
getTemplateMode
Returns the template mode used by the bridge's default engine.- Returns:
- The template mode. Defaults to
DEFAULT_TEMPLATE_MODE.
-
resolveTemplateEngine
Resolves the activeTemplateEngine.Lookup order:
req.getContext().getBeanStore().getBean(TemplateEngine.class)— covers Spring Boot autoconfig (`SpringTemplateEngine` is-a `TemplateEngine`) and any user-supplied bean.- Lazy bridge default — constructed on first call when no engine bean is
registered. Carries a single
ClassLoaderTemplateResolverkeyed off (basePath,.html,templateMode,cacheTemplates).
- Parameters:
req- The current REST request.- Returns:
- The active template engine. Never
null.
-
buildDefaultEngine
Constructs the bridge-defaultTemplateEngine.Single
ClassLoaderTemplateResolverwithprefix=basePath,suffix=".html",templateMode=templateMode, andcacheable=cacheTemplates. Subclasses may override to plug in custom resolvers / dialects without registering a separate@Bean TemplateEngine.- Returns:
- A new
TemplateEngineinstance.
-
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:
renderin interfaceRawTemplateDispatcher- Parameters:
path- The trailing path segment after the mount prefix (the template name relative to the configuredbase path; trailing.htmlstripped).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).
-