You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2026/09/21 13:07:40 UTC
(juneau) branch master updated: Fill-missing-stamp console FTL macros onto a consumer-owned FreeMarker Configuration so Spring apps keep their bean (WORK-J0551), and carry Page Tab shape in always-on chrome.css so toolkit-less pages still get tabs.
This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new d7b52ca6ec Fill-missing-stamp console FTL macros onto a consumer-owned FreeMarker Configuration so Spring apps keep their bean (WORK-J0551), and carry Page Tab shape in always-on chrome.css so toolkit-less pages still get tabs.
d7b52ca6ec is described below
commit d7b52ca6ec267ef0166cdf4c50f57339deed8822
Author: James Bognar <ja...@apache.org>
AuthorDate: Mon Sep 21 09:07:33 2026 -0400
Fill-missing-stamp console FTL macros onto a consumer-owned FreeMarker Configuration so Spring apps keep their bean (WORK-J0551), and carry Page Tab shape in always-on chrome.css so toolkit-less pages still get tabs.
---
.../ConsoleDataTablesFreemarkerMixin.java | 34 +++---
.../ConsoleDataTablesFreemarkerMixin_Test.java | 136 +++++++++++++++++++++
.../freemarker/console/ConsoleFreemarkerMixin.java | 124 +++++++++++++------
.../console/ConsoleFreemarkerMixin_Test.java | 94 +++++++++++---
.../resources/org/apache/juneau/console/chrome.css | 47 ++++++-
.../server/console/ConsoleChromeMixin_Test.java | 41 +++++++
.../org/apache/juneau/views/juneau-views.css | 12 +-
7 files changed, 406 insertions(+), 82 deletions(-)
diff --git a/juneau-rest/juneau-rest-server-console-ui-freemarker-datatables/src/main/java/org/apache/juneau/rest/server/view/freemarker/console/datatables/ConsoleDataTablesFreemarkerMixin.java b/juneau-rest/juneau-rest-server-console-ui-freemarker-datatables/src/main/java/org/apache/juneau/rest/server/view/freemarker/console/datatables/ConsoleDataTablesFreemarkerMixin.java
index bc5d282ffe..29eb017bf7 100644
--- a/juneau-rest/juneau-rest-server-console-ui-freemarker-datatables/src/main/java/org/apache/juneau/rest/server/view/freemarker/console/datatables/ConsoleDataTablesFreemarkerMixin.java
+++ b/juneau-rest/juneau-rest-server-console-ui-freemarker-datatables/src/main/java/org/apache/juneau/rest/server/view/freemarker/console/datatables/ConsoleDataTablesFreemarkerMixin.java
@@ -46,11 +46,13 @@ import freemarker.template.*;
* {@code datatable.ftlh} included) — so the reserved {@link #DATATABLE_TEMPLATE_PATH} resolves through that
* same loader without any additional wiring here.
*
- * <h5 class='section'>Consumer-supplied {@code Configuration} is honored, not augmented (same S2 guard as the parent):</h5>
+ * <h5 class='section'>Consumer-supplied {@code Configuration} is the same instance, then fill-missing stamped:</h5>
* <p>
- * If the request's {@code BeanStore} already has a {@code Configuration} bean, {@link #resolveConfiguration} returns
- * it completely untouched (the {@code <@datatable>} shared variable is not spliced in either) — same
- * documented v1 caveat as {@link ConsoleFreemarkerMixin}.
+ * Same rule as {@link ConsoleFreemarkerMixin}: {@link #resolveConfiguration} returns the consumer bean
+ * {@code ==}-identical so settings win, then fill-missing-stamps {@code jcDataTableHtml} (and the parent
+ * reserved names) and splices the console loader only when {@link ConsoleFreemarkerMixin#BASE_TEMPLATE_PATH}
+ * would not already resolve. Opt out by registering {@link org.apache.juneau.rest.server.view.freemarker.FreemarkerMixin}
+ * instead of this class.
*
* @since 10.0.0
*/
@@ -86,10 +88,9 @@ public class ConsoleDataTablesFreemarkerMixin extends ConsoleFreemarkerMixin {
}
// Same wrap-once identity-cache pattern as ConsoleFreemarkerMixin's own field, kept as a SEPARATE field (not
- // shared with the parent's private one) since this class needs to answer "have I already registered the
- // <@datatable> shared variable on THIS config" independently of the parent's "have I already spliced in the
- // console loader" question -- the two guards happen to gate on the same underlying object in practice, but
- // are conceptually distinct augmentations and each class owns only its own idempotency.
+ // shared with the parent's private one) since this class needs to answer "have I already fill-missing-stamped
+ // jcDataTableHtml on THIS config" independently of the parent's loader / reserved-name stamp. Presence
+ // checks still run on a cache miss so two mixin instances sharing one Spring singleton do not re-set.
@SuppressWarnings({
"java:S3077" // volatile required for correct double-checked-locking safe-publication; see ConsoleFreemarkerMixin's identical field.
})
@@ -97,26 +98,25 @@ public class ConsoleDataTablesFreemarkerMixin extends ConsoleFreemarkerMixin {
/**
* Resolves the active {@link Configuration}: delegates to {@link ConsoleFreemarkerMixin#resolveConfiguration}
- * for the console-loader augmentation, then additionally registers the {@code <@datatable>} shared variable
- * — unless the request's {@code BeanStore} already has a consumer-supplied {@code Configuration} bean, in
- * which case (mirroring the parent's own guard) it is returned untouched.
+ * for console-loader / reserved-name stamping, then fill-missing-registers {@code jcDataTableHtml}.
+ *
+ * <p>
+ * A consumer {@code Configuration} bean is the same {@code ==} instance (settings win). {@code jcDataTableHtml}
+ * is set only when unset. Identity wrap-once plus the parent's loader presence check keep a shared Spring
+ * singleton from nesting {@code MultiTemplateLoader}.
*
* @param req The current REST request.
* @return The active FreeMarker configuration. Never {@code null}.
*/
- @SuppressWarnings({
- "resource" // False positive: req.getContext().getBeanStore() returns a borrowed, container-owned AutoCloseable, not a resource created/owned here.
- })
@Override
public Configuration resolveConfiguration(RestRequest req) {
var cfg = super.resolveConfiguration(req);
- if (req.getContext().getBeanStore().getBean(Configuration.class).isPresent())
- return cfg;
if (cfg == wrappedConfiguration)
return cfg;
synchronized (this) {
if (cfg != wrappedConfiguration) {
- cfg.setSharedVariable(DataTableMethodModel.NAME, new DataTableMethodModel());
+ if (cfg.getSharedVariable(DataTableMethodModel.NAME) == null)
+ cfg.setSharedVariable(DataTableMethodModel.NAME, new DataTableMethodModel());
wrappedConfiguration = cfg;
}
}
diff --git a/juneau-rest/juneau-rest-server-console-ui-freemarker-datatables/src/test/java/org/apache/juneau/rest/server/view/freemarker/console/datatables/ConsoleDataTablesFreemarkerMixin_Test.java b/juneau-rest/juneau-rest-server-console-ui-freemarker-datatables/src/test/java/org/apache/juneau/rest/server/view/freemarker/console/datatables/ConsoleDataTablesFreemarkerMixin_Test.java
index 2d42cb7964..a89f7c1442 100644
--- a/juneau-rest/juneau-rest-server-console-ui-freemarker-datatables/src/test/java/org/apache/juneau/rest/server/view/freemarker/console/datatables/ConsoleDataTablesFreemarkerMixin_Test.java
+++ b/juneau-rest/juneau-rest-server-console-ui-freemarker-datatables/src/test/java/org/apache/juneau/rest/server/view/freemarker/console/datatables/ConsoleDataTablesFreemarkerMixin_Test.java
@@ -33,6 +33,11 @@ import org.apache.juneau.rest.server.view.freemarker.*;
import org.apache.juneau.rest.server.view.freemarker.console.*;
import org.junit.jupiter.api.*;
+import freemarker.cache.*;
+import freemarker.template.Configuration;
+import freemarker.template.SimpleScalar;
+import freemarker.template.TemplateModel;
+
/**
* Ticket 361 Phase 7 gate: the {@code <@datatable>} macro (this module's only deliverable) — a golden-HTML
* integration proof that a row bean's {@code @Html(render=TagHtmlRender.class)} enum property (Phase 4) renders as
@@ -131,6 +136,137 @@ class ConsoleDataTablesFreemarkerMixin_Test extends TestBase {
"console-ui-freemarker main source must NOT import org.apache.juneau.rest.server.datatables.*");
}
+ //-----------------------------------------------------------------------------------------------------------------
+ // f) Consumer Configuration is the same instance, then fill-missing stamped
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @Rest(mixins=FreemarkerMixin.class)
+ public static class ConsumerConfigHost extends BasicRestServlet {
+ private static final long serialVersionUID = 1L;
+ static final Configuration USER_CFG = new Configuration(Configuration.VERSION_2_3_34);
+ static {
+ USER_CFG.setTemplateLoader(new StringTemplateLoader());
+ }
+ static final Object ORIGINAL_WRAPPER = USER_CFG.getObjectWrapper();
+ static final String ORIGINAL_ENCODING = USER_CFG.getDefaultEncoding();
+ static final Object ORIGINAL_OUTPUT_FORMAT = USER_CFG.getOutputFormat();
+ static final long ORIGINAL_UPDATE_DELAY = USER_CFG.getTemplateUpdateDelayMilliseconds();
+ @Bean public Configuration configuration() { return USER_CFG; }
+ @Bean public FreemarkerMixin freemarker() { return ConsoleDataTablesFreemarkerMixin.create().build(); }
+ @RestGet(path="/probe")
+ public String probe(RestRequest req) {
+ var mixin = (ConsoleDataTablesFreemarkerMixin) req.getContext().getBeanStore().getBean(FreemarkerMixin.class).orElseThrow();
+ var cfg1 = mixin.resolveConfiguration(req);
+ var cfg2 = mixin.resolveConfiguration(req);
+ var sameInstance = cfg1 == USER_CFG && cfg2 == USER_CFG;
+ var settingsUnchanged = cfg1.getObjectWrapper() == ORIGINAL_WRAPPER
+ && Objects.equals(cfg1.getDefaultEncoding(), ORIGINAL_ENCODING)
+ && cfg1.getOutputFormat() == ORIGINAL_OUTPUT_FORMAT
+ && cfg1.getTemplateUpdateDelayMilliseconds() == ORIGINAL_UPDATE_DELAY;
+ var varsFilled = cfg1.getSharedVariable(PageDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(CardDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(NavigationDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(NodeDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(ThemeDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable("jcTagHtml") != null
+ && cfg1.getSharedVariable(DataTableMethodModel.NAME) != null;
+ var reservedResolves = true;
+ try {
+ cfg1.getTemplate(ConsoleFreemarkerMixin.BASE_TEMPLATE_PATH);
+ } catch (@SuppressWarnings("unused") Exception ex) {
+ reservedResolves = false;
+ }
+ return sameInstance + ":" + settingsUnchanged + ":" + varsFilled + ":" + reservedResolves
+ + ":" + loaderCount(cfg1) + ":" + loaderCount(cfg2);
+ }
+ }
+
+ /**
+ * Same assertions as {@code ConsoleFreemarkerMixin_Test.f01}, plus {@code jcDataTableHtml} is set.
+ */
+ @Test void f01_consumerSuppliedConfiguration_isAugmentedInPlace() throws Exception {
+ var c = MockRestClient.buildLax(ConsumerConfigHost.class);
+ var body = c.get("/probe").accept("text/plain").run().getContent().asString();
+ assertEquals("true:true:true:true:2:2", body,
+ () -> "expected same-instance, settings-unchanged, vars-filled (incl jcDataTableHtml), reserved-resolves, loader-count 2 then 2; got " + body);
+ }
+
+ @Rest(mixins=FreemarkerMixin.class)
+ public static class CollisionConfigHost extends BasicRestServlet {
+ private static final long serialVersionUID = 1L;
+ static final Configuration COLLISION_CFG = new Configuration(Configuration.VERSION_2_3_34);
+ static final TemplateModel PAGE_SENTINEL = new SimpleScalar("consumer-page");
+ static {
+ COLLISION_CFG.setSharedVariable(PageDirectiveModel.NAME, PAGE_SENTINEL);
+ }
+ @Bean public Configuration configuration() { return COLLISION_CFG; }
+ @Bean public FreemarkerMixin freemarker() { return ConsoleDataTablesFreemarkerMixin.create().build(); }
+ @RestGet(path="/probe")
+ public String probe(RestRequest req) {
+ var mixin = (ConsoleDataTablesFreemarkerMixin) req.getContext().getBeanStore().getBean(FreemarkerMixin.class).orElseThrow();
+ var cfg = mixin.resolveConfiguration(req);
+ var pageKept = cfg.getSharedVariable(PageDirectiveModel.NAME) == PAGE_SENTINEL;
+ var othersFilled = cfg.getSharedVariable(CardDirectiveModel.NAME) != null
+ && cfg.getSharedVariable(NavigationDirectiveModel.NAME) != null
+ && cfg.getSharedVariable(NodeDirectiveModel.NAME) != null
+ && cfg.getSharedVariable(ThemeDirectiveModel.NAME) != null
+ && cfg.getSharedVariable("jcTagHtml") != null
+ && cfg.getSharedVariable(DataTableMethodModel.NAME) != null;
+ return pageKept + ":" + othersFilled;
+ }
+ }
+
+ /**
+ * Consumer bean already has {@code page} set: that sentinel is kept; the other Juneau reserved names
+ * (including {@code jcDataTableHtml}) are still fill-missing stamped.
+ */
+ @Test void f02_consumerPageSentinel_isKeptAndOtherNamesFilled() throws Exception {
+ var c = MockRestClient.buildLax(CollisionConfigHost.class);
+ var body = c.get("/probe").accept("text/plain").run().getContent().asString();
+ assertEquals("true:true", body,
+ () -> "expected page-sentinel-kept=true, other-names-filled=true; got " + body);
+ }
+
+ @Rest
+ public static class SharedConfigDummyHost extends BasicRestServlet {
+ private static final long serialVersionUID = 1L;
+ static final Configuration SHARED_CFG = new Configuration(Configuration.VERSION_2_3_34);
+ static {
+ SHARED_CFG.setTemplateLoader(new StringTemplateLoader());
+ }
+ static final ThreadLocal<RestRequest> CAPTURED = new ThreadLocal<>();
+ @Bean public Configuration configuration() { return SHARED_CFG; }
+ @RestGet(path="/x")
+ public String x(RestRequest req) {
+ CAPTURED.set(req);
+ return "x";
+ }
+ }
+
+ /**
+ * Two {@link ConsoleDataTablesFreemarkerMixin} instances sharing one consumer {@code Configuration} bean
+ * splice the console loader once: {@code MultiTemplateLoader} count stays 2.
+ */
+ @Test void f03_twoMixinInstances_sharedConsumerBean_loaderCountStays2() throws Exception {
+ MockRestClient.buildLax(SharedConfigDummyHost.class).get("/x").run();
+ var req = SharedConfigDummyHost.CAPTURED.get();
+ var m1 = ConsoleDataTablesFreemarkerMixin.create().build();
+ var m2 = ConsoleDataTablesFreemarkerMixin.create().build();
+ var c1 = m1.resolveConfiguration(req);
+ var c2 = m2.resolveConfiguration(req);
+ assertSame(SharedConfigDummyHost.SHARED_CFG, c1);
+ assertSame(SharedConfigDummyHost.SHARED_CFG, c2);
+ assertEquals(2, loaderCount(c1));
+ assertEquals(2, loaderCount(c2));
+ assertNotNull(c1.getSharedVariable(DataTableMethodModel.NAME));
+ assertNotNull(c2.getSharedVariable(DataTableMethodModel.NAME));
+ }
+
+ private static int loaderCount(Configuration cfg) {
+ var loader = cfg.getTemplateLoader();
+ return loader instanceof MultiTemplateLoader multi ? multi.getTemplateLoaderCount() : -1;
+ }
+
private static boolean importsDatatablesPackage(java.io.File srcMain) throws Exception {
assertTrue(srcMain.isDirectory(), () -> "Expected sibling src/main/java not found: " + srcMain.getAbsolutePath());
try (var files = java.nio.file.Files.walk(srcMain.toPath())) {
diff --git a/juneau-rest/juneau-rest-server-console-ui-freemarker/src/main/java/org/apache/juneau/rest/server/view/freemarker/console/ConsoleFreemarkerMixin.java b/juneau-rest/juneau-rest-server-console-ui-freemarker/src/main/java/org/apache/juneau/rest/server/view/freemarker/console/ConsoleFreemarkerMixin.java
index 0254d9e0cf..d891bdd4ba 100644
--- a/juneau-rest/juneau-rest-server-console-ui-freemarker/src/main/java/org/apache/juneau/rest/server/view/freemarker/console/ConsoleFreemarkerMixin.java
+++ b/juneau-rest/juneau-rest-server-console-ui-freemarker/src/main/java/org/apache/juneau/rest/server/view/freemarker/console/ConsoleFreemarkerMixin.java
@@ -58,14 +58,16 @@ import freemarker.template.*;
* <#include "/org/apache/juneau/console/base.ftlh">
* </p>
*
- * <h5 class='section'>Consumer-supplied {@code Configuration} is honored, not augmented:</h5>
+ * <h5 class='section'>Consumer-supplied {@code Configuration} is the same instance, then fill-missing stamped:</h5>
* <p>
* When the request's {@code BeanStore} already has a {@code Configuration} bean (Spring/Spring-Boot autoconfig, or
- * a microservice {@code BasicBeanStore.put}), {@link #resolveConfiguration} returns that <b>same instance</b>
- * ({@code ==}), completely untouched — the console loader is not spliced in, and
- * {@code org/apache/juneau/console/base.ftlh} does not resolve unless the consumer adds it themselves. This is a
- * documented v1 caveat, not an oversight: augmenting an externally-owned singleton {@code Configuration} silently
- * would be a surprising side effect for a consumer.
+ * a microservice {@code BasicBeanStore.put}), {@link #resolveConfiguration} still returns that <b>same instance</b>
+ * ({@code ==}) so consumer settings win (encoding, {@code ObjectWrapper}, {@code exposeFields}, template-update
+ * delay, output format). It then fill-missing-stamps the reserved console shared variables
+ * ({@code page}, {@code card}, {@code navigation}, {@code node}, {@code theme}, {@code jcTagHtml}) and splices the
+ * reserved-path console loader only when {@link #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
+ * {@link FreemarkerMixin} instead of {@code ConsoleFreemarkerMixin}.
*
* @since 10.0.0
*/
@@ -118,66 +120,110 @@ public class ConsoleFreemarkerMixin extends FreemarkerMixin {
return new Builder();
}
- // Double-checked-locking identity cache (Phase 5 should-fix S2 gate 1): resolveConfiguration is called once
- // per request, but super.resolveConfiguration(req) returns the SAME cached Configuration object on every
- // call for a given mixin instance when no consumer Configuration bean is registered (FreemarkerDispatcher's
- // own lazy default-Configuration cache). Tracking that object's identity here means "have I already wrapped
- // THIS exact object" is answered in O(1) without re-wrapping (which would otherwise nest
- // Multi(Multi(base, console), console) on every subsequent call).
+ // Double-checked-locking identity cache: resolveConfiguration is called once per request, and
+ // super.resolveConfiguration(req) returns the SAME Configuration object on every call for a given mixin
+ // instance (consumer bean or FreemarkerDispatcher's lazy default cache). Tracking that object's identity
+ // here means "have I already stamped THIS exact object" is answered in O(1). Presence checks on the loader
+ // and shared-variable names still run on a cache miss so N Rest resources sharing one Spring singleton
+ // do not nest Multi(Multi(base, console), console).
@SuppressWarnings({
"java:S3077" // volatile is required here for correct double-checked-locking safe-publication; the reference is publish-once (fully constructed/wrapped before assignment) and never compound-mutated.
})
private volatile Configuration wrappedConfiguration;
/**
- * Resolves the active {@link Configuration}, augmented with the reserved-path console loader when no
- * consumer-supplied {@code Configuration} bean is present.
+ * Resolves the active {@link Configuration} and fill-missing-stamps console shared variables onto it.
*
* <p>
- * Two independent guards, both should-fix S2 gates:
+ * Always delegates to {@code super.resolveConfiguration(req)} first so a consumer {@code Configuration} bean
+ * wins for settings. Then:
* <ol class='spaced-list'>
- * <li><b>Consumer identity honored:</b> if the request's {@code BeanStore} already has a {@code Configuration}
- * bean, it is returned {@code ==}-identical and completely untouched — no console loader is spliced
- * in, and {@link #BASE_TEMPLATE_PATH} will not resolve through it unless the consumer adds it themselves.
- * <li><b>Wrap-once:</b> otherwise, the mixin-instance-owned bridge-default {@code Configuration} is augmented
- * exactly once (identity-gated double-checked locking below); every subsequent call on the same instance
- * returns the same already-augmented object without re-wrapping its {@code TemplateLoader}.
+ * <li><b>Fill-missing names:</b> {@code page}, {@code card}, {@code navigation}, {@code node},
+ * {@code theme}, {@code jcTagHtml} are set only when {@code getSharedVariable(name)} is unset. A
+ * consumer value is kept.
+ * <li><b>Loader splice:</b> the classpath-root console {@link ClassTemplateLoader} is wrapped in only when
+ * {@link #BASE_TEMPLATE_PATH} would not already resolve through the current loader.
+ * <li><b>Wrap-once + presence:</b> identity-cached per mixin instance so a second call does not
+ * re-wrap; presence checks so N Rest resources sharing one Spring singleton {@code Configuration} do
+ * not nest {@link MultiTemplateLoader}.
* </ol>
*
* @param req The current REST request.
* @return The active FreeMarker configuration. Never {@code null}.
*/
- @SuppressWarnings({
- "resource" // False positive: req.getContext().getBeanStore() returns a borrowed, container-owned AutoCloseable, not a resource created/owned here.
- })
@Override
public Configuration resolveConfiguration(RestRequest req) {
- if (req.getContext().getBeanStore().getBean(Configuration.class).isPresent())
- return super.resolveConfiguration(req);
var base = super.resolveConfiguration(req);
if (base == wrappedConfiguration)
return base;
synchronized (this) {
if (base != wrappedConfiguration) {
- base.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[]{
- base.getTemplateLoader(),
- new ClassTemplateLoader(getClass().getClassLoader(), "")
- }));
- base.setSharedVariable(TagMethodModel.NAME, new TagMethodModel());
- var packs = new ToolkitPackRegistry();
- for (var extra : extraPacks)
- packs.register(extra.name(), extra.cssPaths(), extra.jsPaths());
- base.setSharedVariable(PageDirectiveModel.NAME, new PageDirectiveModel(chromeTemplate, packs));
- base.setSharedVariable(CardDirectiveModel.NAME, new CardDirectiveModel());
- base.setSharedVariable(NavigationDirectiveModel.NAME, new NavigationDirectiveModel());
- base.setSharedVariable(NodeDirectiveModel.NAME, new NodeDirectiveModel());
- base.setSharedVariable(ThemeDirectiveModel.NAME, new ThemeDirectiveModel());
+ spliceConsoleLoaderIfNeeded(base);
+ fillMissingConsoleSharedVariables(base);
wrappedConfiguration = base;
}
}
return base;
}
+ /**
+ * Wraps the current {@link TemplateLoader} with a classpath-root console loader only when
+ * {@link #BASE_TEMPLATE_PATH} would not resolve. Presence-checked so a second mixin instance sharing the
+ * same {@code Configuration} does not nest {@link MultiTemplateLoader}.
+ */
+ private void spliceConsoleLoaderIfNeeded(Configuration cfg) {
+ if (reservedTemplateResolves(cfg))
+ return;
+ var console = new ClassTemplateLoader(getClass().getClassLoader(), "");
+ var existing = cfg.getTemplateLoader();
+ if (existing == null)
+ cfg.setTemplateLoader(console);
+ else
+ cfg.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[]{ existing, console }));
+ }
+
+ /**
+ * Whether the reserved console chrome template is already visible on {@code cfg}'s loader. Uses
+ * {@link TemplateLoader#findTemplateSource(String)} so a miss is not cached as a failed
+ * {@link Configuration#getTemplate(String)}.
+ */
+ private static boolean reservedTemplateResolves(Configuration cfg) {
+ var loader = cfg.getTemplateLoader();
+ if (loader == null)
+ return false;
+ try {
+ var source = loader.findTemplateSource(BASE_TEMPLATE_PATH);
+ if (source == null)
+ return false;
+ loader.closeTemplateSource(source);
+ return true;
+ } catch (@SuppressWarnings("unused") Exception e) {
+ return false; // Loader probe failed; treat as unresolved and splice.
+ }
+ }
+
+ /**
+ * Sets each reserved console shared variable only when that name is unset on {@code cfg}.
+ */
+ private void fillMissingConsoleSharedVariables(Configuration cfg) {
+ if (cfg.getSharedVariable(TagMethodModel.NAME) == null)
+ cfg.setSharedVariable(TagMethodModel.NAME, new TagMethodModel());
+ if (cfg.getSharedVariable(PageDirectiveModel.NAME) == null) {
+ var packs = new ToolkitPackRegistry();
+ for (var extra : extraPacks)
+ packs.register(extra.name(), extra.cssPaths(), extra.jsPaths());
+ cfg.setSharedVariable(PageDirectiveModel.NAME, new PageDirectiveModel(chromeTemplate, packs));
+ }
+ if (cfg.getSharedVariable(CardDirectiveModel.NAME) == null)
+ cfg.setSharedVariable(CardDirectiveModel.NAME, new CardDirectiveModel());
+ if (cfg.getSharedVariable(NavigationDirectiveModel.NAME) == null)
+ cfg.setSharedVariable(NavigationDirectiveModel.NAME, new NavigationDirectiveModel());
+ if (cfg.getSharedVariable(NodeDirectiveModel.NAME) == null)
+ cfg.setSharedVariable(NodeDirectiveModel.NAME, new NodeDirectiveModel());
+ if (cfg.getSharedVariable(ThemeDirectiveModel.NAME) == null)
+ cfg.setSharedVariable(ThemeDirectiveModel.NAME, new ThemeDirectiveModel());
+ }
+
/**
* Builder for {@link ConsoleFreemarkerMixin}.
*/
diff --git a/juneau-rest/juneau-rest-server-console-ui-freemarker/src/test/java/org/apache/juneau/rest/server/view/freemarker/console/ConsoleFreemarkerMixin_Test.java b/juneau-rest/juneau-rest-server-console-ui-freemarker/src/test/java/org/apache/juneau/rest/server/view/freemarker/console/ConsoleFreemarkerMixin_Test.java
index ca7f3e49ca..35f95a9866 100644
--- a/juneau-rest/juneau-rest-server-console-ui-freemarker/src/test/java/org/apache/juneau/rest/server/view/freemarker/console/ConsoleFreemarkerMixin_Test.java
+++ b/juneau-rest/juneau-rest-server-console-ui-freemarker/src/test/java/org/apache/juneau/rest/server/view/freemarker/console/ConsoleFreemarkerMixin_Test.java
@@ -18,6 +18,7 @@ package org.apache.juneau.rest.server.view.freemarker.console;
import static org.junit.jupiter.api.Assertions.*;
+import java.util.*;
import java.util.regex.*;
import org.apache.juneau.*;
@@ -31,12 +32,14 @@ import org.junit.jupiter.api.*;
import freemarker.cache.*;
import freemarker.template.Configuration;
+import freemarker.template.SimpleScalar;
+import freemarker.template.TemplateModel;
import freemarker.template.TemplateNotFoundException;
/**
* Phase 5 gate: {@link ConsoleFreemarkerMixin} (reserved-path template loader, {@code base.ftlh}, the
- * {@code <@tag>} macro) and the two should-fix S2 gates the r2 review added (double-wrap prevention;
- * consumer-supplied {@code Configuration} identity honored).
+ * {@code <@tag>} macro), wrap-once loader splicing, and fill-missing stamping onto a consumer
+ * {@code Configuration} bean.
*/
@SuppressWarnings({
"resource" // Closeable test fixtures held in static fields; lifecycle managed by the test/framework, not a real leak.
@@ -237,49 +240,106 @@ class ConsoleFreemarkerMixin_Test extends TestBase {
}
//-----------------------------------------------------------------------------------------------------------------
- // f) Should-fix S2 gate 2: consumer Configuration identity honored
+ // f) Consumer Configuration is the same instance, then fill-missing stamped
//-----------------------------------------------------------------------------------------------------------------
@Rest(mixins=FreemarkerMixin.class)
public static class ConsumerConfigHost extends BasicRestServlet {
private static final long serialVersionUID = 1L;
static final Configuration USER_CFG = new Configuration(Configuration.VERSION_2_3_34);
- static final TemplateLoader ORIGINAL_LOADER = USER_CFG.getTemplateLoader();
+ static {
+ USER_CFG.setTemplateLoader(new StringTemplateLoader());
+ }
+ static final Object ORIGINAL_WRAPPER = USER_CFG.getObjectWrapper();
+ static final String ORIGINAL_ENCODING = USER_CFG.getDefaultEncoding();
+ static final Object ORIGINAL_OUTPUT_FORMAT = USER_CFG.getOutputFormat();
+ static final long ORIGINAL_UPDATE_DELAY = USER_CFG.getTemplateUpdateDelayMilliseconds();
@Bean public Configuration configuration() { return USER_CFG; }
@Bean public FreemarkerMixin freemarker() { return ConsoleFreemarkerMixin.create().build(); }
@RestGet(path="/probe")
public String probe(RestRequest req) {
var mixin = (ConsoleFreemarkerMixin) req.getContext().getBeanStore().getBean(FreemarkerMixin.class).orElseThrow();
- var cfg = mixin.resolveConfiguration(req);
- var sameInstance = cfg == USER_CFG;
- var loaderUnchanged = cfg.getTemplateLoader() == ORIGINAL_LOADER;
+ var cfg1 = mixin.resolveConfiguration(req);
+ var cfg2 = mixin.resolveConfiguration(req);
+ var sameInstance = cfg1 == USER_CFG && cfg2 == USER_CFG;
+ var settingsUnchanged = cfg1.getObjectWrapper() == ORIGINAL_WRAPPER
+ && Objects.equals(cfg1.getDefaultEncoding(), ORIGINAL_ENCODING)
+ && cfg1.getOutputFormat() == ORIGINAL_OUTPUT_FORMAT
+ && cfg1.getTemplateUpdateDelayMilliseconds() == ORIGINAL_UPDATE_DELAY;
+ var varsFilled = cfg1.getSharedVariable(PageDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(CardDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(NavigationDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(NodeDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(ThemeDirectiveModel.NAME) != null
+ && cfg1.getSharedVariable(TagMethodModel.NAME) != null;
var reservedResolves = true;
try {
- cfg.getTemplate(ConsoleFreemarkerMixin.BASE_TEMPLATE_PATH);
- } catch (Exception ex) {
+ cfg1.getTemplate(ConsoleFreemarkerMixin.BASE_TEMPLATE_PATH);
+ } catch (@SuppressWarnings("unused") Exception ex) {
reservedResolves = false;
}
- return sameInstance + ":" + loaderUnchanged + ":" + reservedResolves;
+ return sameInstance + ":" + settingsUnchanged + ":" + varsFilled + ":" + reservedResolves
+ + ":" + loaderCount(cfg1) + ":" + loaderCount(cfg2);
}
}
/**
- * A host that registers its own {@code @Bean Configuration} (no console loader) plus
- * {@code ConsoleFreemarkerMixin}: {@code resolveConfiguration(req)} must return that SAME instance
- * ({@code ==}), its {@code getTemplateLoader()} must be unchanged, and the reserved console template must NOT
- * resolve (the consumer never added the console loader themselves).
+ * A host that registers its own {@code @Bean Configuration} plus {@code ConsoleFreemarkerMixin}:
+ * {@code resolveConfiguration} returns that SAME instance ({@code ==}), leaves wrapper/encoding/output-format/
+ * update-delay alone, fill-missing-stamps the reserved console names, makes the reserved template resolve,
+ * and a second call on the same mixin does not nest {@code MultiTemplateLoader}.
*/
- @Test void f01_consumerSuppliedConfiguration_isReturnedUntouched() throws Exception {
+ @Test void f01_consumerSuppliedConfiguration_isAugmentedInPlace() throws Exception {
var c = MockRestClient.buildLax(ConsumerConfigHost.class);
var body = c.get("/probe").accept("text/plain").run().getContent().asString();
- assertEquals("true:true:false", body,
- () -> "expected same-instance=true, loader-unchanged=true, reserved-template-resolves=false; got " + body);
+ assertEquals("true:true:true:true:2:2", body,
+ () -> "expected same-instance, settings-unchanged, vars-filled, reserved-resolves, loader-count 2 then 2; got " + body);
+ }
+
+ @Rest(mixins=FreemarkerMixin.class)
+ public static class CollisionConfigHost extends BasicRestServlet {
+ private static final long serialVersionUID = 1L;
+ static final Configuration COLLISION_CFG = new Configuration(Configuration.VERSION_2_3_34);
+ static final TemplateModel PAGE_SENTINEL = new SimpleScalar("consumer-page");
+ static {
+ COLLISION_CFG.setSharedVariable(PageDirectiveModel.NAME, PAGE_SENTINEL);
+ }
+ @Bean public Configuration configuration() { return COLLISION_CFG; }
+ @Bean public FreemarkerMixin freemarker() { return ConsoleFreemarkerMixin.create().build(); }
+ @RestGet(path="/probe")
+ public String probe(RestRequest req) {
+ var mixin = (ConsoleFreemarkerMixin) req.getContext().getBeanStore().getBean(FreemarkerMixin.class).orElseThrow();
+ var cfg = mixin.resolveConfiguration(req);
+ var pageKept = cfg.getSharedVariable(PageDirectiveModel.NAME) == PAGE_SENTINEL;
+ var othersFilled = cfg.getSharedVariable(CardDirectiveModel.NAME) != null
+ && cfg.getSharedVariable(NavigationDirectiveModel.NAME) != null
+ && cfg.getSharedVariable(NodeDirectiveModel.NAME) != null
+ && cfg.getSharedVariable(ThemeDirectiveModel.NAME) != null
+ && cfg.getSharedVariable(TagMethodModel.NAME) != null;
+ return pageKept + ":" + othersFilled;
+ }
+ }
+
+ /**
+ * Consumer bean already has {@code page} set: that sentinel is kept; the other Juneau reserved names are
+ * still fill-missing stamped.
+ */
+ @Test void f02_consumerPageSentinel_isKeptAndOtherNamesFilled() throws Exception {
+ var c = MockRestClient.buildLax(CollisionConfigHost.class);
+ var body = c.get("/probe").accept("text/plain").run().getContent().asString();
+ assertEquals("true:true", body,
+ () -> "expected page-sentinel-kept=true, other-names-filled=true; got " + body);
}
//-----------------------------------------------------------------------------------------------------------------
// helpers
//-----------------------------------------------------------------------------------------------------------------
+ private static int loaderCount(Configuration cfg) {
+ var loader = cfg.getTemplateLoader();
+ return loader instanceof MultiTemplateLoader multi ? multi.getTemplateLoaderCount() : -1;
+ }
+
/**
* A minimal live {@link RestRequest} for in-process {@code resolveConfiguration(req)} calls (empty
* {@code BeanStore} -- no {@code Configuration} bean registered). {@code MockRestClient}'s classic client
diff --git a/juneau-rest/juneau-rest-server-console-ui/src/main/resources/org/apache/juneau/console/chrome.css b/juneau-rest/juneau-rest-server-console-ui/src/main/resources/org/apache/juneau/console/chrome.css
index 5e9ce66b73..2148c6bab8 100644
--- a/juneau-rest/juneau-rest-server-console-ui/src/main/resources/org/apache/juneau/console/chrome.css
+++ b/juneau-rest/juneau-rest-server-console-ui/src/main/resources/org/apache/juneau/console/chrome.css
@@ -401,25 +401,63 @@ a:hover { text-decoration: underline; }
/* ==========================================================================
HTML-slot page nav (two text rows; not Page Tabs / Page Subtabs pills)
- Shape lives in juneau-views.css. Selected section = light wash + indicator
- accent on the TOP edge, no pill fill. Hairline under the sections row is
- --jc-page-nav-hairline (2px) and --jc-page-nav-accent. The pair's floor uses
- the same accent. Selected child = accent wash behind the label, not accent type.
+ Shape AND colour live here so toolkit-less pages still get Page Tabs.
+ juneau-views.css keeps a parallel colourless shape for views-only consumers.
+ Selected section = light wash + indicator accent on the TOP edge, no pill
+ fill. Hairline under the sections row is --jc-page-nav-hairline (2px) and
+ --jc-page-nav-accent. The pair's floor uses the same accent. Selected child
+ = accent wash behind the label, not accent type.
========================================================================== */
.juneau-page-nav {
+ display: flex;
+ flex-direction: column;
background-color: var(--jc-nav-bg);
+ border-bottom-width: var(--jc-nav-indicator-width);
+ border-bottom-style: solid;
border-bottom-color: var(--jc-page-nav-accent);
}
+.juneau-page-nav-sections, .juneau-page-nav-children {
+ display: flex;
+ flex-wrap: nowrap;
+ overflow-x: auto;
+ white-space: nowrap;
+ align-items: stretch;
+ gap: 0;
+ margin: 0;
+ padding-left: var(--jc-space-3);
+ padding-right: var(--jc-space-3);
+}
+
.juneau-page-nav-sections {
border-bottom-width: var(--jc-page-nav-hairline);
+ border-bottom-style: solid;
border-bottom-color: var(--jc-page-nav-accent);
}
+.juneau-page-nav-section, .juneau-page-nav-child {
+ flex: 0 0 auto;
+ display: inline-flex;
+ align-items: center;
+ padding-top: 0.45em;
+ padding-bottom: 0.45em;
+ padding-left: var(--jc-space-3);
+ padding-right: var(--jc-space-3);
+ font-weight: 400;
+ text-decoration: none;
+ border: none;
+ border-radius: 0;
+ background-color: transparent;
+ cursor: pointer;
+}
+
.juneau-page-nav-section {
color: var(--jc-text-soft);
font-size: var(--jc-page-nav-section-font-size);
+ border-top-width: var(--jc-nav-indicator-width);
+ border-top-style: solid;
+ border-top-color: transparent;
}
.juneau-page-nav-section:hover {
@@ -432,6 +470,7 @@ a:hover { text-decoration: underline; }
background-color: var(--jc-accent-wash);
border-top-color: var(--jc-page-nav-accent);
color: var(--jc-text);
+ font-weight: 600;
}
.juneau-page-nav-child {
diff --git a/juneau-rest/juneau-rest-server-console-ui/src/test/java/org/apache/juneau/rest/server/console/ConsoleChromeMixin_Test.java b/juneau-rest/juneau-rest-server-console-ui/src/test/java/org/apache/juneau/rest/server/console/ConsoleChromeMixin_Test.java
index 642e8ad337..759880c592 100644
--- a/juneau-rest/juneau-rest-server-console-ui/src/test/java/org/apache/juneau/rest/server/console/ConsoleChromeMixin_Test.java
+++ b/juneau-rest/juneau-rest-server-console-ui/src/test/java/org/apache/juneau/rest/server/console/ConsoleChromeMixin_Test.java
@@ -760,6 +760,47 @@ class ConsoleChromeMixin_Test extends TestBase {
assertFalse(navRules.toLowerCase().contains("salesforce sans"), navRules);
}
+ @Test void j07b_htmlSlotPageNav_chromeCarriesShapeSoToolkitLessPagesDoNotConcatenateLabels() throws Exception {
+ // <@node> emits adjacent <a> tags with no whitespace. Without flex + padding in always-on
+ // chrome.css, toolkit-less pages (Setup, New Release) render as "SetupReleasesNew Release".
+ var css = readChromeCss();
+ var navMarker = "HTML-slot page nav (two text rows";
+ var navStart = css.indexOf(navMarker);
+ assertNotEquals(-1, navStart, () -> "missing HTML-slot page nav comment, css:\n" + css);
+ var navEnd = css.indexOf("Page scaffolding", navStart);
+ assertNotEquals(-1, navEnd, () -> "missing Page scaffolding marker after page-nav, css:\n" + css);
+ var navRules = css.substring(navStart, navEnd);
+ var floorStart = navRules.indexOf("\n.juneau-page-nav {");
+ assertTrue(floorStart >= 0, navRules);
+ var floorBlock = navRules.substring(floorStart, navRules.indexOf("}", floorStart));
+ assertTrue(floorBlock.contains("display: flex"),
+ () -> "chrome must own page-nav column flex, not just hue, block:\n" + floorBlock);
+ assertTrue(floorBlock.contains("border-bottom-width: var(--jc-nav-indicator-width)"),
+ () -> "floor width must paint without views.css, block:\n" + floorBlock);
+ assertTrue(floorBlock.contains("border-bottom-style: solid"),
+ () -> "floor style must paint without views.css, block:\n" + floorBlock);
+ assertTrue(navRules.contains(".juneau-page-nav-sections, .juneau-page-nav-children {"),
+ () -> "sections and children rows must share a flex row rule:\n" + navRules);
+ var rowsStart = navRules.indexOf(".juneau-page-nav-sections, .juneau-page-nav-children {");
+ var rowsBlock = navRules.substring(rowsStart, navRules.indexOf("}", rowsStart));
+ assertTrue(rowsBlock.contains("display: flex"),
+ () -> "sections/children must be a flex row so labels do not concatenate, block:\n" + rowsBlock);
+ var sharedStart = navRules.indexOf(".juneau-page-nav-section, .juneau-page-nav-child {");
+ assertTrue(sharedStart >= 0, () -> "missing shared section/child shape rule:\n" + navRules);
+ var sharedBlock = navRules.substring(sharedStart, navRules.indexOf("}", sharedStart));
+ assertTrue(sharedBlock.contains("display: inline-flex"),
+ () -> "tab links must be inline-flex, block:\n" + sharedBlock);
+ assertTrue(sharedBlock.contains("padding-left: var(--jc-space-3)"),
+ () -> "tab links must have horizontal padding so labels do not run together, block:\n" + sharedBlock);
+ var sectionTypeStart = navRules.indexOf("\n.juneau-page-nav-section {");
+ assertTrue(sectionTypeStart >= 0, navRules);
+ var sectionTypeBlock = navRules.substring(sectionTypeStart, navRules.indexOf("}", sectionTypeStart));
+ assertTrue(sectionTypeBlock.contains("border-top-width: var(--jc-nav-indicator-width)"),
+ () -> "selected-section top accent needs a width without views.css, block:\n" + sectionTypeBlock);
+ assertTrue(sectionTypeBlock.contains("border-top-style: solid"),
+ () -> "selected-section top accent needs a style without views.css, block:\n" + sectionTypeBlock);
+ }
+
@Test void j08_jcCard_keepsShadowAndRadius_dropsGreyStroke() throws Exception {
var css = readChromeCss();
var start = css.indexOf(".jc-card {");
diff --git a/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-views.css b/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-views.css
index 2337435ce9..55c73ba393 100644
--- a/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-views.css
+++ b/juneau-rest/juneau-rest-server-views/src/main/resources/org/apache/juneau/views/juneau-views.css
@@ -2826,11 +2826,13 @@ input[type="checkbox"].jc-editable-field-input {
/*
* HTML-slot page nav: one construct, two text rows, accent floor below the pair.
- * Shape only in this file (no hue palette). Selected section = indicator-width accent
- * on the TOP edge plus light wash (themed in console chrome). A 2px hairline sits under
- * the sections row (between tabs and children). Selected child = light wash behind the
- * label, not blue type and not a connected pill ribbon. Not .jc-tab / .jc-subtab
- * ribbon-format; leftover .jc-tab / .jc-subtab rules are historical (hash-swap shell deleted).
+ * Colourless shape for views-only consumers. Console chrome.css carries the same
+ * shape plus hue so toolkit-less pages still get Page Tabs. Selected section =
+ * indicator-width accent on the TOP edge plus light wash (themed in console chrome).
+ * A 2px hairline sits under the sections row (between tabs and children). Selected
+ * child = light wash behind the label, not blue type and not a connected pill ribbon.
+ * Not .jc-tab / .jc-subtab ribbon-format; leftover .jc-tab / .jc-subtab rules are
+ * historical (hash-swap shell deleted).
*/
.juneau-page-nav {
display: flex;