Class ConsoleFreemarkerMixin

java.lang.Object
org.apache.juneau.rest.server.view.freemarker.FreemarkerMixin
org.apache.juneau.console.freemarker.ConsoleFreemarkerMixin

A FreemarkerMixin that additionally makes the reserved-classpath admin-console chrome template (org/apache/juneau/console/base.ftlh) — and the <@tag> macro it defines — resolvable from any consumer template, without shadowing the consumer's own basePath-rooted template tree.
Used INSTEAD OF FreemarkerMixin, not beside it:

Register it typed as either FreemarkerMixin or ConsoleFreemarkerMixin — both declared return types work. FreemarkerViewRenderer finds the exact-type FreemarkerMixin bean when one is registered, and otherwise also looks for a bean declared under any registered subtype, which this class registers via a static initializer:

@Bean public FreemarkerMixin freemarker() { return ConsoleFreemarkerMixin.create().basePath("/templates/").build(); }

or equivalently:

@Bean public ConsoleFreemarkerMixin freemarker() { return ConsoleFreemarkerMixin.create().basePath("/templates/").build(); }

Consumer /templates is never shadowed:

The augmented Configuration's TemplateLoader tries the consumer's own basePath-derived loader first; the reserved template is addressed by its full classpath-root-relative path (BASE_TEMPLATE_PATH) on a second, classpath-root-rooted ClassTemplateLoader, so it cannot collide with a consumer path such as /templates/base.ftlh. Consumer templates include it with a loader-root-absolute path:

<#include "/org/apache/juneau/console/base.ftlh">

Consumer-supplied Configuration is the same instance, then fill-missing stamped:

When the request's BeanStore already has a Configuration bean (Spring/Spring-Boot autoconfig, or a microservice BasicBeanStore.put), resolveConfiguration(org.apache.juneau.rest.server.RestRequest) still returns that same instance (==) so consumer settings win (encoding, ObjectWrapper, exposeFields, template-update delay, output format). It then fill-missing-stamps the reserved console shared variables (page, card, navigation, node, theme, token, console, main, the <@console> slot names head/scripts/brand/actions/ title/footer/body, and jcTagHtml) and splices the reserved-path console loader only when BASE_TEMPLATE_PATH would not already resolve. A name the consumer already set is left alone. There is no opt-out flag on this class — opt out by registering FreemarkerMixin instead of ConsoleFreemarkerMixin.

Since:
10.0.0
  • Field Details

    • BASE_TEMPLATE_PATH

      public static final String BASE_TEMPLATE_PATH
      The reserved classpath-root-relative location of the shipped console chrome template (defines the <@tag> macro). Load-bearing for the collision-free-namespacing argument in the class javadoc — do not shorten.
      See Also:
    • DEFAULT_CHROME_TEMPLATE

      public static final String DEFAULT_CHROME_TEMPLATE
      Default consumer chrome template included by <@page> when none is configured.
      See Also:
  • Constructor Details

  • Method Details

    • create

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

      public freemarker.template.Configuration resolveConfiguration(RestRequest req)
      Resolves the active Configuration and fill-missing-stamps console shared variables onto it.

      Always delegates to super.resolveConfiguration(req) first so a consumer Configuration bean wins for settings. Then:

      1. Fill-missing names: page, card, navigation, node, theme, token, console, main, the <@console> slot names (head, scripts, brand, actions, title, footer, body), and jcTagHtml are set only when getSharedVariable(name) is unset. A consumer value is kept.
      2. Loader splice: the classpath-root console ClassTemplateLoader is wrapped in only when BASE_TEMPLATE_PATH would not already resolve through the current loader.
      3. Wrap-once + presence: identity-cached per mixin instance so a second call does not re-wrap; presence checks so N Rest resources sharing one Spring singleton Configuration do not nest MultiTemplateLoader.
      Overrides:
      resolveConfiguration in class FreemarkerMixin
      Parameters:
      req - The current REST request.
      Returns:
      The active FreeMarker configuration. Never null.