001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.console.views; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021import java.nio.charset.*; 022import java.util.regex.*; 023 024import org.apache.juneau.http.*; 025import org.apache.juneau.http.response.NotFound; 026import org.apache.juneau.rest.server.*; 027import org.apache.juneau.commons.beanquery.*; 028import org.apache.juneau.console.*; 029import org.apache.juneau.console.datatables.*; 030import org.apache.juneau.rest.server.util.*; 031import org.apache.juneau.console.widgets.*; 032 033/** 034 * Mixin that serves the first-party rich-view runtime assets — {@code juneau-views.js}, 035 * {@code juneau-ribbon.js}, {@code juneau-renders.js}, {@code juneau-views.css}, the opt-in 036 * {@code juneau-regions.js} region-populate runtime, the opt-in {@code juneau-config.js}/{@code juneau-config.css} 037 * column-chooser runtime — each at its stable path, plus deprecated compatibility mounts 038 * for the two assets that have since moved to the widget module. 039 * 040 * <p> 041 * Compose into a host resource via {@link Rest#mixins() @Rest(mixins=ViewsMixin.class)}; the asset URLs then become 042 * available alongside the host's own endpoints, so browser pages can load the runtime without the application hosting 043 * it itself. This mirrors the sibling {@code DataTablesMixin}/{@code ConsoleChromeMixin} serving pattern (those 044 * modules are not dependencies of this one, so they are not linked here). 045 * 046 * <h2 class='section'>What this ships (and what it deliberately does not):</h2> 047 * <p> 048 * Juneau's jars don't copy the <a class="doclink" href="https://datatables.net">DataTables</a> library or jQuery. Only 049 * the thin, first-party runtime is served here; the DataTables, jQuery and Buttons files come from the WebJars that 050 * {@code juneau-console-datatables} declares, served by {@code WebJarsMixin}. The 051 * base {@code juneau-views.css} {@code .tag} chip is dependency-free (neutral, no colors); {@code console-ui}'s 052 * {@code chrome.css} themes the same {@code .tag.<domain>.<value>} classes when present, but this module takes 053 * <b>no</b> dependency on it. 054 * 055 * <h2 class='section'>Relocated: two assets now ship in the widget module</h2> 056 * <p> 057 * {@code juneau-calendar.js} and {@code juneau-calendar.css} are widget runtimes, not 058 * table runtimes, and their bytes now live in {@code juneau-console-widgets} beside the bean contracts that 059 * drive them. {@link WidgetsMixin} is where a new application gets them. 060 * 061 * <p> 062 * This mixin keeps a <b>deprecated</b> mount and path constant for each of the two so that an existing 063 * {@code @Rest(mixins=ViewsMixin.class)} application keeps working with no change: the mount reads the widget 064 * module's bytes off the classpath (that module is a compile-scope dependency of this one) rather than holding a 065 * second copy, so the body and the cache-buster are identical to what {@link WidgetsMixin} serves. Composing both 066 * mixins is therefore harmless. 067 * 068 * <p> 069 * The relocation does <b>not</b> make that script standalone: it still resolves glyphs through this module's 070 * {@code juneau-icons.js} and pushes its popovers onto the ONE shared layer stack {@code juneau-views.js} publishes. 071 * A page loading the widget calendar runtime must still load this module's {@code juneau-icons.js} and 072 * {@code juneau-views.js} first. 073 * 074 * <h2 class='section'>Cache-busting + versioned URLs:</h2> 075 * <p> 076 * Each asset is served with a one-day {@code Cache-Control} and referenced from a page's {@code head=} block with a 077 * {@code ?v=<buildVersion>-<hash8>} cache-buster (see {@link #viewAssetUrl(String)}, or 078 * {@link #viewAssetUrl(RestRequest, String)} for a template-rendered consumer that needs the URL already resolved 079 * to an absolute, browser-fetchable form), where {@code hash8} is an 080 * 8-hex-char CRC32 of that asset's own served bytes, computed once and cached (classpath resources never change 081 * within a running JVM). Keying the buster off content rather than {@code buildVersion} alone matters for 082 * {@code -SNAPSHOT} builds: that version string is stable across dev rebuilds, so a version-only buster would keep 083 * serving a browser's stale cached copy after every rebuild - the content hash changes the instant the bytes do, 084 * with no SNAPSHOT special-casing needed. {@code buildVersion} is the framework's 085 * {@link Package#getImplementationVersion() implementation version}, falling back to {@code "dev"} when running from an 086 * unpackaged (IDE/test) classpath. The served endpoint ignores the query string, so any (or no) {@code ?v=} still 087 * resolves to the same asset. 088 * 089 * <h2 class='section'>Contract-version handshake:</h2> 090 * <p> 091 * {@link #CONTRACT_VERSION} is the single wire-contract discriminator for a {@code VIEW_META} sidecar. 092 * {@code juneau-views.js} bakes in the same value so the client can fail loud when a served sidecar's 093 * {@code contractVersion} differs from the runtime's. 094 * 095 * <h2 class='section'>Mixin-only deployment:</h2> 096 * <p> 097 * The mount paths are pinned at the op level by {@code @RestGet(path=...)} on the serving methods; a class-level 098 * {@code @Rest(paths=...)} would be silently ignored under the mixin pattern. 099 * 100 * <h2 class='section'>See Also:</h2> 101 * <ul> 102 * <li class='jc'>{@link ViewTable} 103 * </ul> 104 * 105 * @since 10.0.0 106 */ 107// @formatter:off 108@Rest 109@SuppressWarnings({ 110 "java:S1133" // Still referenced externally (compatibility mount, forRemoval=false); removal is a separate deprecation-cycle decision. 111}) 112public class ViewsMixin { 113 114 /** 115 * The URL path at which the client initializer is served (relative to the host mount). A page with any 116 * datatables card must load {@code juneau-datatables.js} ({@link #DATATABLES_JS_PATH}) <b>before</b> this script, 117 * so {@code window.JuneauDataTables} is already present when {@code buildOptions} wires up that card's ajax. 118 * This mixin does not serve {@code juneau-datatables.js} itself — the resource 119 * mixes in {@code DataTablesMixin} for that, the same way it already mixes in {@code ViewsMixin} for this 120 * script; a duplicate {@code @RestGet} for the same path on two mixed-in classes would fail route 121 * registration. A missing {@code window.JuneauDataTables} when a server-side table initializes fails loudly (console warning, 122 * no silent GET fallback) rather than silently misbehaving. A page with any ribbon options should likewise load 123 * {@code juneau-ribbon.js} before this script, so {@code window.JuneauViews.ribbon} is present when 124 * {@code buildOptions} merges that view's active ribbon state into the request; unlike the 125 * {@code JuneauDataTables} case this one degrades rather than fails — a missing 126 * {@code window.JuneauViews.ribbon} warns and simply contributes no ribbon filters, since a view with no ribbon 127 * configured never needed {@code juneau-ribbon.js} loaded at all. 128 */ 129 public static final String VIEWS_JS_PATH = "/juneau-views.js"; 130 131 /** 132 * The URL path of the DataTables glue script, {@code juneau-datatables.js} (the same path as 133 * {@link DataTablesMixin#GLUE_PATH}). 134 * 135 * <p> 136 * Named here so {@link #viewAssetUrl(RestRequest, String)} can build its cache-busted URL, and so the console's 137 * {@code "datatables-glue"} toolkit pack can name the path without importing the datatables package 138 * ({@code juneau-console-freemarker} forbids that import; see its {@code ModuleGraph_ImportScan_Test}). This mixin does 139 * <b>not</b> serve it (see {@link #VIEWS_JS_PATH} for why); {@link DataTablesMixin} does. On a console page the 140 * {@code "datatables-glue"} toolkit pack emits it for every {@code type="datatables"} card, client or server mode, 141 * after jQuery and DataTables and before {@code juneau-views.js}. A host with datatables cards composes 142 * {@link DataTablesMixin} and {@code WebJarsMixin}. 143 * 144 * <h4 class='section'>Example:</h4> 145 * <p class='bjava'> 146 * <ja>@Rest</ja>(mixins={ViewsMixin.<jk>class</jk>, DataTablesMixin.<jk>class</jk>, WebJarsMixin.<jk>class</jk>}) 147 * <jk>public class</jk> MyResource <jk>extends</jk> BasicRestServlet { 148 * <jc>// Emitted by the "datatables-glue" pack before juneau-views.js:</jc> 149 * <jc>// ViewsMixin.viewAssetUrl(req, ViewsMixin.DATATABLES_JS_PATH)</jc> 150 * } 151 * </p> 152 */ 153 public static final String DATATABLES_JS_PATH = DataTablesMixin.GLUE_PATH; 154 155 /** The URL path at which the ribbon runtime is served (relative to the host mount). */ 156 public static final String RIBBON_JS_PATH = "/juneau-ribbon.js"; 157 158 /** The URL path at which the renderer registry is served (relative to the host mount). */ 159 public static final String RENDERS_JS_PATH = "/juneau-renders.js"; 160 161 /** The URL path at which the base view stylesheet is served (relative to the host mount). */ 162 public static final String VIEWS_CSS_PATH = "/juneau-views.css"; 163 164 /** 165 * The URL path at which the icon registry is served (relative to the host mount). 166 * 167 * <h4 class='section'>Example:</h4> 168 * <p class='bjava'> 169 * <jc>// Page-level sprite layers, read once before the chrome draws:</jc> 170 * <jc>// <script src="/views/juneau-icons.js"</jc> 171 * <jc>// data-juneau-icon-replacement="/my/set.svg"</jc> 172 * <jc>// data-juneau-icon-override="/my/overrides.svg"></script></jc> 173 * </p> 174 */ 175 public static final String ICONS_JS_PATH = "/juneau-icons.js"; 176 177 /** 178 * The URL path at which the column-search engine is served (relative to the host mount). This 179 * dependency-free {@code <script>} loads before {@code juneau-views.js} (like the icon registry): it publishes 180 * {@code JuneauViews.search} — the client mirror of the server-side {@link SearchExpressionParser}/ 181 * {@link SearchOperatorSet}/{@link InMemoryBeanQueryContext} context that the header search popup and a client-mode 182 * grid use to parse and evaluate each column's raw search expression. 183 */ 184 public static final String SEARCH_JS_PATH = "/juneau-search.js"; 185 186 /** 187 * The URL path at which the general page-state store is served (relative to the host mount). This 188 * dependency-free {@code <script>} loads before {@code juneau-views.js} and {@code juneau-config.js} (like the 189 * icon registry and column-search engine): it publishes {@code JuneauViews.pageState} — a per-table / 190 * per-page key/value store, backed by {@code localStorage} by default and degrading to a silent no-op when 191 * browser storage is blocked. The datatable View Settings dialog and any other page preference share it. 192 */ 193 public static final String PAGESTATE_JS_PATH = "/juneau-pagestate.js"; 194 195 /** 196 * The URL path at which the shareable "Copy link" URL-state codec is served (relative to the host mount). This 197 * dependency-free {@code <script>} loads before {@code juneau-views.js} and {@code juneau-config.js} (like the 198 * icon registry, column-search engine, and page-state store): it publishes {@code JuneauViews.urlState} — 199 * the single codec for the one {@code ?state=} query parameter that carries a shareable link's live tab, primary- 200 * table filters, and primary-table sort (never the browser-local View Settings, and never nested tables). 201 */ 202 public static final String URLSTATE_JS_PATH = "/juneau-urlstate.js"; 203 204 /** 205 * The URL path at which the in-page message bus is served (relative to the host mount). This dependency-free 206 * {@code <script>} publishes {@code JuneauViews.bus} — topic declare/claim, publish/subscribe with optional 207 * retention, and the frame and source bridges — and it <b>must</b> load before {@code juneau-views.js}, 208 * {@code juneau-regions.js} and {@code juneau-console.js}, all of which read it. The {@code "views"} toolkit pack 209 * lists it first. A page that wires topics without it fails loud with {@code E-JS-46}. 210 * 211 * <h4 class='section'>Example:</h4> 212 * <p class='bjava'> 213 * <jc>// A hand-written page head that does not use the "views" toolkit pack: the bus goes first.</jc> 214 * <jk>var</jk> <jv>bus</jv> = ViewsMixin.<jsm>viewAssetUrl</jsm>(<jv>req</jv>, ViewsMixin.<jsf>BUS_JS_PATH</jsf>); 215 * <jk>var</jk> <jv>views</jv> = ViewsMixin.<jsm>viewAssetUrl</jsm>(<jv>req</jv>, ViewsMixin.<jsf>VIEWS_JS_PATH</jsf>); 216 * <jc>// <script src="${bus}"></script><script src="${views}"></script></jc> 217 * </p> 218 */ 219 public static final String BUS_JS_PATH = "/juneau-bus.js"; 220 221 /** 222 * The URL path at which the client object model ({@code JuneauViews.model}) is served (relative to the host mount). 223 * Loaded right after {@link #BUS_JS_PATH}; the {@code "views"} toolkit pack lists it second. 224 */ 225 public static final String MODEL_JS_PATH = "/juneau-model.js"; 226 227 /** 228 * The URL path at which the opt-in inline-handler compiler is served (relative to the host mount). It is the only 229 * shipped script that compiles code from strings, so it belongs to no toolkit pack: a page that opts in with 230 * {@code allowInlineHandlers(true)} gets it as a separate script tag after the runtime pack, and the response CSP 231 * must then allow {@code 'unsafe-eval'}. 232 */ 233 public static final String MODEL_INLINE_JS_PATH = "/juneau-model-inline.js"; 234 235 /** 236 * The URL path at which the shared SVG symbol sprite is served (relative to the host mount). 237 * {@code juneau-icons.js} fetches this next to itself by default (pack {@code original}); the key/legend 238 * file is not served to browsers. An app replaces part or all of this shipped set per page with a replacement 239 * and/or override sprite that uses the same {@code juneau-sym-{stem}} symbol ids. 240 * 241 * <h4 class='section'>Example:</h4> 242 * <p class='bjava'> 243 * <jc>// Page-level sprite layers, read once before the chrome draws:</jc> 244 * <jc>// <script src="/views/juneau-icons.js"</jc> 245 * <jc>// data-juneau-icon-replacement="/my/set.svg"</jc> 246 * <jc>// data-juneau-icon-override="/my/overrides.svg"></script></jc> 247 * </p> 248 */ 249 public static final String SYMBOLS_SVG_PATH = "/juneau-symbols.svg"; 250 251 /** 252 * The URL path at which the opt-in Material Symbols Outlined sprite is served (relative to the host mount). 253 * Selected as the legacy replacement layer by {@code JuneauViews.icons.pack("material")} / 254 * {@code data-juneau-icon-pack="material"}; new apps point {@code data-juneau-icon-replacement} / 255 * {@code JuneauViews.icons.sprites({replacementUrl})} at the set they want instead. 256 * Default remains {@link #SYMBOLS_SVG_PATH} (Juneau's own shipped set). The Material pack loads as the replacement 257 * layer on top of that shipped sprite, so stems the Material file does not carry fall back to the shipped glyph. 258 * 259 * <h4 class='section'>Example:</h4> 260 * <p class='bjava'> 261 * <jc>// Opt in to the Material Symbols sprite as the replacement layer over the shipped set, before the chrome draws:</jc> 262 * <jc>// <script src="/views/juneau-icons.js" data-juneau-icon-pack="material"></script></jc> 263 * <jc>// or, from script before first paint:</jc> 264 * <jc>// JuneauViews.icons.pack("material");</jc> 265 * </p> 266 */ 267 public static final String SYMBOLS_MATERIAL_SVG_PATH = "/juneau-symbols-material.svg"; 268 269 /** 270 * The URL path at which the Lucide base sprite is served (relative to the host mount). It is the lowest icon 271 * layer: any stem the shipped sprite, a replacement or an override also carries wins over it, and a failed 272 * fetch leaves the shipped glyphs in place. 273 */ 274 public static final String SYMBOLS_LUCIDE_SVG_PATH = "/juneau-symbols-lucide.svg"; 275 276 /** 277 * The URL path at which the opt-in region-populate runtime is served (relative to the host mount). A page with 278 * no {@code data-juneau-region} element never needs to load it. 279 * 280 * <h4 class='section'>Load order is a contract, not a preference:</h4> 281 * <p> 282 * This {@code <script>} MUST come after {@code juneau-views.js}. The region runtime publishes onto the same 283 * {@code window.JuneauViews} namespace that {@code juneau-views.js} creates, and reuses that runtime's 284 * {@code renderAsyncStatus} status renderer rather than defining one of its own. 285 */ 286 public static final String REGIONS_JS_PATH = "/juneau-regions.js"; 287 288 /** 289 * The URL path at which the opt-in region-populate paint library is served (relative to the host mount). A 290 * page of purely custom regions (every populate hand-writes its own DOM) never needs to load it. 291 * 292 * <h4 class='section'>Load order is a contract, not a preference:</h4> 293 * <p> 294 * This {@code <script>} MUST come after {@code juneau-regions.js} (itself after {@code juneau-views.js}). 295 * {@code fieldGrid}'s renderer dispatch reads the renderer registry {@code juneau-views.js} publishes and its 296 * markdown/sanitized-HTML paths reuse that runtime's allowlist copiers, and {@code ctx.helpers} 297 * (a bare pass-through of this asset's exports) is a field of the {@code ctx} {@code juneau-regions.js} freezes. 298 */ 299 public static final String HELPERS_JS_PATH = "/juneau-helpers.js"; 300 301 /** 302 * [GET] path of the DataRegistry runtime ({@code JuneauViews.data}): the frames behind {@code data:} bus topics. 303 * Loaded after {@link #BUS_JS_PATH}; the {@code "data"} toolkit pack serves it. 304 */ 305 public static final String DATA_JS_PATH = "/juneau-data.js"; 306 307 /** 308 * The URL path at which the opt-in terminal-view module is served (relative to the host mount). 309 * 310 * <h4 class='section'>Load order is a contract, not a preference:</h4> 311 * <p> 312 * This {@code <script>} MUST come after {@code juneau-regions.js} (itself after {@code juneau-views.js}) and 313 * before {@code juneau-helpers.js}. It registers its populator with {@code juneau-regions.js} at load time; 314 * icons are built through {@code JuneauViews.helpers.icon}, which is resolved at call time, so loading before 315 * {@code juneau-helpers.js} is safe. 316 * 317 * @since 10.0.0 318 */ 319 public static final String RUN_VIEW_JS_PATH = "/juneau-terminal-view.js"; 320 321 /** 322 * The URL path at which the opt-in column-chooser runtime is served (relative to the host mount). A 323 * consumer adds this {@code <script>} after {@code juneau-views.js}; a non-configurable table never loads it. 324 */ 325 public static final String CONFIG_JS_PATH = "/juneau-config.js"; 326 327 /** 328 * The URL path at which the opt-in column-chooser stylesheet is served (relative to the host mount). 329 */ 330 public static final String CONFIG_CSS_PATH = "/juneau-config.css"; 331 332 /** 333 * The URL path at which the opt-in reusable-calendar runtime is served (relative to the host mount). A page 334 * with no calendar never loads it. 335 * 336 * <h4 class='section'>Load order is a contract, not a preference:</h4> 337 * <p> 338 * This {@code <script>} MUST come after {@code juneau-views.js}. The calendar's {@code "+N more"} popover is 339 * pushed onto the ONE shared layer stack that {@code juneau-views.js} publishes, so that Escape, focus return 340 * and z-order are the same as every other layer in the page. The calendar deliberately defines no second 341 * stack of its own: if the shared one is absent it fails loud (console error plus a visible in-cell refusal) 342 * rather than quietly opening a popover nothing can dismiss. 343 * 344 * @deprecated The calendar runtime now ships in the widget module; compose 345 * {@link WidgetsMixin} and use its constant of the same name. This one 346 * remains only so that an application composing this mixin alone keeps serving the asset at the same URL. 347 */ 348 @Deprecated(since = "10.0.0", forRemoval = false) 349 public static final String CALENDAR_JS_PATH = "/juneau-calendar.js"; 350 351 /** 352 * The URL path at which the opt-in reusable-calendar stylesheet is served (relative to the host mount). 353 * 354 * @deprecated The calendar stylesheet now ships in the widget module; compose 355 * {@link WidgetsMixin} and use its constant of the same name. This one 356 * remains only so that an application composing this mixin alone keeps serving the asset at the same URL. 357 */ 358 @Deprecated(since = "10.0.0", forRemoval = false) 359 public static final String CALENDAR_CSS_PATH = "/juneau-calendar.css"; 360 361 /** 362 * The URL path at which the console shell runtime is served (relative to the host mount). 363 * 364 * <p> 365 * {@code juneau-console.js} mounts the C1 page contract (header, nav, cards, footer) from a page's 366 * {@code #juneau-page} script island. This module takes a compile-scope dependency on 367 * {@code juneau-console} so that a {@code views}-only application can serve the console shell 368 * from the same mixin it already composes, without separately adding {@link ConsoleChromeMixin}. The toolkit 369 * pack ({@code juneau-views.js} and siblings) deliberately does <b>not</b> bundle this script: a console page's 370 * shell loads it once via {@code PageCapture.writeBody}, and a second copy from the toolkit pack would 371 * double-load the runtime. 372 * 373 * <h4 class='section'>Example:</h4> 374 * <p class='bjava'> 375 * <jc>// A views-only application serves the console shell at the same stable (unprefixed) path ConsoleChromeMixin serves it at.</jc> 376 * <ja>@Rest</ja>(mixins=ViewsMixin.<jk>class</jk>) 377 * <jk>public class</jk> MyResource {} 378 * 379 * <jc>// GET /juneau-console.js now returns the shell runtime.</jc> 380 * </p> 381 */ 382 public static final String CONSOLE_JS_PATH = ConsoleChromeMixin.CONSOLE_JS_PATH_UNPREFIXED; 383 384 /** 385 * The frozen {@code VIEW_META} contract-version handshake constant. FTL {@code <@card type="datatables">} 386 * catalogs emit this on the lifted {@code view} object. 387 * 388 * <p> 389 * Templates never author {@code view.contractVersion}: the framework stamps this value when it lifts the catalog, 390 * so a contract bump never touches adopter templates. A pre-built envelope body is rejected at render time, and 391 * {@code ConsoleTemplateValidator}'s {@code view-contract-version} rule flags a literal pin statically. 392 */ 393 public static final String CONTRACT_VERSION = "5"; 394 395 /** 396 * The app-header refresh-envelope contract-version handshake constant that the console shell bakes in. 397 * Deliberately distinct from {@link #CONTRACT_VERSION} and {@link #BAR_CONTRACT_VERSION}: a header-envelope 398 * revision must never force a view-sidecar or bar-sidecar bump, or vice-versa. 399 */ 400 public static final String HEADER_CONTRACT_VERSION = "1"; 401 402 /** 403 * The bar-slot refresh-envelope contract-version handshake constant that the console shell bakes in. 404 * Deliberately a distinct constant from {@link #HEADER_CONTRACT_VERSION} (see that constant). 405 */ 406 public static final String BAR_CONTRACT_VERSION = "1"; 407 408 /** 409 * The slot-envelope ({@code SLOT_META}) contract-version handshake constant that {@code juneau-views.js} 410 * bakes in. Deliberately a distinct constant from {@link #CONTRACT_VERSION} (the 411 * inner {@code VIEW_META} object): a slot-envelope revision must never force a view-sidecar bump, or vice-versa. 412 */ 413 public static final String SLOT_CONTRACT_VERSION = "1"; 414 415 /** Classpath location of the shipped initializer. */ 416 static final String VIEWS_JS_RESOURCE = "/org/apache/juneau/views/juneau-views.js"; 417 418 /** Classpath location of the DataTables glue script, shipped by {@code juneau-console-datatables}. */ 419 static final String DATATABLES_JS_RESOURCE = "/org/apache/juneau/console/datatables/juneau-datatables.js"; 420 421 /** Classpath location of the shipped ribbon runtime. */ 422 static final String RIBBON_JS_RESOURCE = "/org/apache/juneau/views/juneau-ribbon.js"; 423 424 /** Classpath location of the shipped renderer registry. */ 425 static final String RENDERS_JS_RESOURCE = "/org/apache/juneau/views/juneau-renders.js"; 426 427 /** Classpath location of the shipped base stylesheet. */ 428 static final String VIEWS_CSS_RESOURCE = "/org/apache/juneau/views/juneau-views.css"; 429 430 /** Classpath location of the shipped icon registry. */ 431 static final String ICONS_JS_RESOURCE = "/org/apache/juneau/views/juneau-icons.js"; 432 433 /** Classpath location of the shipped column-search engine (client mirror of the Java column-search engine). */ 434 static final String SEARCH_JS_RESOURCE = "/org/apache/juneau/views/juneau-search.js"; 435 436 /** Classpath location of the shipped in-page message bus ({@code JuneauViews.bus}). */ 437 static final String BUS_JS_RESOURCE = "/org/apache/juneau/views/juneau-bus.js"; 438 439 /** Classpath location of the shipped client object model ({@code JuneauViews.model}). */ 440 static final String MODEL_JS_RESOURCE = "/org/apache/juneau/views/juneau-model.js"; 441 442 /** Classpath location of the shipped opt-in inline-handler compiler. */ 443 static final String MODEL_INLINE_JS_RESOURCE = "/org/apache/juneau/views/juneau-model-inline.js"; 444 445 /** Classpath location of the shipped general page-state store. */ 446 static final String PAGESTATE_JS_RESOURCE = "/org/apache/juneau/views/juneau-pagestate.js"; 447 448 /** Classpath location of the shipped shareable-link URL-state codec. */ 449 static final String URLSTATE_JS_RESOURCE = "/org/apache/juneau/views/juneau-urlstate.js"; 450 451 /** Classpath location of the shipped SVG symbol sprite (Juneau's own set, default pack). */ 452 static final String SYMBOLS_SVG_RESOURCE = "/org/apache/juneau/views/juneau-symbols.svg"; 453 454 /** Classpath location of the opt-in Material Symbols Outlined sprite. */ 455 static final String SYMBOLS_MATERIAL_SVG_RESOURCE = "/org/apache/juneau/views/juneau-symbols-material.svg"; 456 457 /** Classpath location of the Lucide base sprite. */ 458 static final String SYMBOLS_LUCIDE_SVG_RESOURCE = "/org/apache/juneau/views/juneau-symbols-lucide.svg"; 459 460 /** Classpath location of the shipped region-populate runtime. */ 461 static final String REGIONS_JS_RESOURCE = "/org/apache/juneau/views/juneau-regions.js"; 462 463 /** Classpath location of the shipped region-populate paint library. */ 464 static final String HELPERS_JS_RESOURCE = "/org/apache/juneau/views/juneau-helpers.js"; 465 466 /** Classpath location of the shipped DataRegistry runtime. */ 467 static final String DATA_JS_RESOURCE = "/org/apache/juneau/views/juneau-data.js"; 468 469 /** Classpath location of the shipped terminal-view module. */ 470 static final String RUN_VIEW_JS_RESOURCE = "/org/apache/juneau/views/juneau-terminal-view.js"; 471 472 /** Classpath location of the shipped column-chooser runtime. */ 473 static final String CONFIG_JS_RESOURCE = "/org/apache/juneau/views/juneau-config.js"; 474 475 /** Classpath location of the shipped column-chooser stylesheet. */ 476 static final String CONFIG_CSS_RESOURCE = "/org/apache/juneau/views/juneau-config.css"; 477 478 /** 479 * Classpath location of the reusable-calendar runtime, which the <b>widget</b> module now ships. 480 * 481 * <p> 482 * The two widget-owned assets below are read out of the widget module's classpath (a compile-scope dependency of 483 * this one), never copied into this module's resources. Reading rather than copying is what makes this mixin's 484 * deprecated accessor serve the same bytes the widget mixin serves, and it is why the absent-from-this-module 485 * guard in the serving test can assert a move rather than a duplication. 486 */ 487 static final String CALENDAR_JS_RESOURCE = "/org/apache/juneau/widgets/juneau-calendar.js"; 488 489 /** Classpath location of the reusable-calendar stylesheet, which the widget module now ships (see {@link #CALENDAR_JS_RESOURCE}). */ 490 static final String CALENDAR_CSS_RESOURCE = "/org/apache/juneau/widgets/juneau-calendar.css"; 491 492 /** Content type emitted for the JavaScript assets. */ 493 static final String JS_CONTENT_TYPE = "text/javascript;charset=utf-8"; 494 495 /** Content type emitted for the stylesheet asset. */ 496 static final String CSS_CONTENT_TYPE = "text/css;charset=utf-8"; 497 498 /** Content type emitted for the SVG symbol sprite. */ 499 static final String SVG_CONTENT_TYPE = "image/svg+xml"; 500 501 /** {@code Cache-Control} header emitted for every asset (1 day). */ 502 static final String CACHE_CONTROL = "max-age=86400, public"; 503 504 /** 505 * Read+cache+hash+serve helper for this mixin's shipped assets, anchored on this class so 506 * {@link ClasspathAssetCache#buildVersion()} resolves this module's own implementation version (see that 507 * class's javadoc's version-anchor section). 508 */ 509 private static final ClasspathAssetCache ASSET_CACHE = new ClasspathAssetCache(ViewsMixin.class); 510 511 /** 512 * The same helper, but anchored on the <b>widget</b> mixin, for the two assets that module now ships and this 513 * one only keeps deprecated mounts for. 514 * 515 * <p> 516 * The anchor governs two things: which classpath the bytes are read from (irrelevant here — the widget 517 * module is a compile-scope dependency, so either anchor finds the same bytes) and which module's 518 * implementation version the {@code ?v=<buildVersion>-<hash8>} cache-buster carries. Anchoring the relocated 519 * two on the widget mixin makes this mixin's deprecated URL for an asset <b>byte-identical</b> to the widget 520 * mixin's URL for it, buster included, rather than merely serving the same body behind two differently-versioned 521 * URLs. A page that mixes both mixins therefore cannot end up caching the same script twice. 522 */ 523 private static final ClasspathAssetCache WIDGET_ASSET_CACHE = new ClasspathAssetCache(WidgetsMixin.class); 524 525 /** 526 * The same helper, but anchored on the <b>console-ui</b> mixin, for the console shell script that module ships 527 * and this one serves at {@link #CONSOLE_JS_PATH}. Anchoring on {@link ConsoleChromeMixin} (rather than this 528 * class) makes this mount's {@code ?v=<buildVersion>-<hash8>} cache-buster identical to 529 * {@code ConsoleChromeMixin}'s own mount of the same bytes, so a page that composes both mixins cannot end up 530 * caching the same script twice under two different busters. 531 */ 532 private static final ClasspathAssetCache CONSOLE_ASSET_CACHE = new ClasspathAssetCache(ConsoleChromeMixin.class); 533 534 /** 535 * The same helper, but anchored on {@link DataTablesMixin}, for {@link #DATATABLES_JS_PATH}: the cache-buster 536 * carries the datatables module's implementation version, since that module ships (and serves) the bytes. 537 */ 538 private static final ClasspathAssetCache DATATABLES_ASSET_CACHE = new ClasspathAssetCache(DataTablesMixin.class); 539 540 /** 541 * [GET /juneau-views.js] — serve the client initializer. 542 * 543 * @return The initializer as a JavaScript {@link HttpResource}. 544 */ 545 @RestGet( 546 path=VIEWS_JS_PATH, 547 summary="Juneau rich-view client initializer", 548 description="First-party JavaScript that auto-initializes <table data-juneau-view> elements from their VIEW_META sidecar.", 549 swagger=@OpSwagger(ignore=true) 550 ) 551 public HttpResource getViewsScript() { 552 return serve(VIEWS_JS_RESOURCE, JS_CONTENT_TYPE); 553 } 554 555 /** 556 * [GET /juneau-ribbon.js] — serve the ribbon/toolbar runtime. 557 * 558 * @return The ribbon runtime as a JavaScript {@link HttpResource}. 559 */ 560 @RestGet( 561 path=RIBBON_JS_PATH, 562 summary="Juneau rich-view ribbon runtime", 563 description="First-party JavaScript that builds the ribbon/toolbar from a view's VIEW_META ribbon actions.", 564 swagger=@OpSwagger(ignore=true) 565 ) 566 public HttpResource getRibbonScript() { 567 return serve(RIBBON_JS_RESOURCE, JS_CONTENT_TYPE); 568 } 569 570 /** 571 * [GET /juneau-renders.js] — serve the renderer registry. 572 * 573 * @return The renderer registry as a JavaScript {@link HttpResource}. 574 */ 575 @RestGet( 576 path=RENDERS_JS_PATH, 577 summary="Juneau rich-view renderer registry", 578 description="First-party, dependency-free JavaScript cell-renderer registry consumed by the view initializer.", 579 swagger=@OpSwagger(ignore=true) 580 ) 581 public HttpResource getRendersScript() { 582 return serve(RENDERS_JS_RESOURCE, JS_CONTENT_TYPE); 583 } 584 585 /** 586 * [GET /juneau-views.css] — serve the base view stylesheet. 587 * 588 * @return The base stylesheet as a CSS {@link HttpResource}. 589 */ 590 @RestGet( 591 path=VIEWS_CSS_PATH, 592 summary="Juneau rich-view base stylesheet", 593 description="First-party base '.tag' chip stylesheet (neutral, no colors); console-ui themes the same classes when present.", 594 swagger=@OpSwagger(ignore=true) 595 ) 596 public HttpResource getViewsStylesheet() { 597 return serve(VIEWS_CSS_RESOURCE, CSS_CONTENT_TYPE); 598 } 599 600 /** 601 * [GET /juneau-icons.js] — serve the icon registry. 602 * 603 * @return The icon registry as a JavaScript {@link HttpResource}. 604 */ 605 @RestGet( 606 path=ICONS_JS_PATH, 607 summary="Juneau rich-view icon registry", 608 description="First-party, dependency-free JavaScript icon registry (name -> inline-SVG markup) consumed by the ribbon/paging-pill runtime.", 609 swagger=@OpSwagger(ignore=true) 610 ) 611 public HttpResource getIconsScript() { 612 return serve(ICONS_JS_RESOURCE, JS_CONTENT_TYPE); 613 } 614 615 /** 616 * [GET /juneau-search.js] — serve the column-search engine. 617 * 618 * @return The column-search engine as a JavaScript {@link HttpResource}. 619 */ 620 @RestGet( 621 path=SEARCH_JS_PATH, 622 summary="Juneau rich-view column-search engine", 623 description="First-party, dependency-free JavaScript mirror of the server-side column-search engine (parser, operator metadata, and per-type leaf semantics) published as JuneauViews.search.", 624 swagger=@OpSwagger(ignore=true) 625 ) 626 public HttpResource getSearchScript() { 627 return serve(SEARCH_JS_RESOURCE, JS_CONTENT_TYPE); 628 } 629 630 /** 631 * [GET /juneau-pagestate.js] — serve the general page-state store. 632 * 633 * @return The page-state store as a JavaScript {@link HttpResource}. 634 */ 635 @RestGet( 636 path=PAGESTATE_JS_PATH, 637 summary="Juneau rich-view page-state store", 638 description="First-party, dependency-free JavaScript key/value store (per-table and per-page namespaces, localStorage-backed with a blocked-storage no-op fallback) published as JuneauViews.pageState.", 639 swagger=@OpSwagger(ignore=true) 640 ) 641 public HttpResource getPageStateScript() { 642 return serve(PAGESTATE_JS_RESOURCE, JS_CONTENT_TYPE); 643 } 644 645 /** 646 * [GET /juneau-urlstate.js] — serve the shareable-link URL-state codec. 647 * 648 * @return The URL-state codec as a JavaScript {@link HttpResource}. 649 */ 650 @RestGet( 651 path=URLSTATE_JS_PATH, 652 summary="Juneau rich-view shareable-link URL-state codec", 653 description="First-party, dependency-free JavaScript codec for the one ?state= query parameter (tab/filter/sort of the primary table only, never View Settings or nested tables) published as JuneauViews.urlState.", 654 swagger=@OpSwagger(ignore=true) 655 ) 656 public HttpResource getUrlStateScript() { 657 return serve(URLSTATE_JS_RESOURCE, JS_CONTENT_TYPE); 658 } 659 660 /** 661 * [GET /juneau-bus.js] — serve the in-page message bus. 662 * 663 * @return The message bus as a JavaScript {@link HttpResource}. 664 */ 665 @RestGet( 666 path=BUS_JS_PATH, 667 summary="Juneau in-page message bus", 668 description="Dependency-free topic bus (JuneauViews.bus): declare/claim, publish/subscribe with retention, frame and source bridges.", 669 swagger=@OpSwagger(ignore=true) 670 ) 671 public HttpResource getBusScript() { 672 return serve(BUS_JS_RESOURCE, JS_CONTENT_TYPE); 673 } 674 675 /** 676 * [GET /juneau-model.js] — serve the client object model. 677 * 678 * @return The object model as a JavaScript {@link HttpResource}. 679 */ 680 @RestGet( 681 path=MODEL_JS_PATH, 682 summary="Juneau client object model", 683 description="Twin client object model (JuneauViews.model): handles, class cards, named handlers and the JSON builder.", 684 swagger=@OpSwagger(ignore=true) 685 ) 686 public HttpResource getModelScript() { 687 return serve(MODEL_JS_RESOURCE, JS_CONTENT_TYPE); 688 } 689 690 /** 691 * [GET /juneau-model-inline.js] — serve the opt-in inline-handler compiler. 692 * 693 * @return The inline-handler compiler as a JavaScript {@link HttpResource}. 694 */ 695 @RestGet( 696 path=MODEL_INLINE_JS_PATH, 697 summary="Juneau inline-handler compiler", 698 description="Opt-in compiler for inline handler strings; needs 'unsafe-eval' in the page CSP.", 699 swagger=@OpSwagger(ignore=true) 700 ) 701 public HttpResource getModelInlineScript() { 702 return serve(MODEL_INLINE_JS_RESOURCE, JS_CONTENT_TYPE); 703 } 704 705 /** 706 * [GET /juneau-symbols.svg] — serve the shared SVG symbol sprite. 707 * 708 * @return The sprite as an SVG {@link HttpResource}. 709 */ 710 @RestGet( 711 path=SYMBOLS_SVG_PATH, 712 summary="Juneau rich-view SVG symbol sprite", 713 description="Shared SVG <symbol> sprite referenced by juneau-icons.js <use href> hosts. The key/legend file is not served.", 714 swagger=@OpSwagger(ignore=true) 715 ) 716 public HttpResource getSymbolsSvg() { 717 return serve(SYMBOLS_SVG_RESOURCE, SVG_CONTENT_TYPE); 718 } 719 720 /** 721 * [GET /juneau-symbols-material.svg] — serve the opt-in Material Symbols Outlined sprite. 722 * 723 * @return The Material sprite as an SVG {@link HttpResource}. 724 */ 725 @RestGet( 726 path=SYMBOLS_MATERIAL_SVG_PATH, 727 summary="Juneau rich-view Material Symbols SVG sprite (opt-in)", 728 description="NOTICE-attributed Material Symbols Outlined sprite. Apps normally supply their own set via the icon replacementUrl (data-juneau-icon-replacement); JuneauViews.icons.pack(\"material\") remains the legacy base selector. Default remains juneau-symbols.svg.", 729 swagger=@OpSwagger(ignore=true) 730 ) 731 public HttpResource getSymbolsMaterialSvg() { 732 return serve(SYMBOLS_MATERIAL_SVG_RESOURCE, SVG_CONTENT_TYPE); 733 } 734 735 /** 736 * [GET /juneau-symbols-lucide.svg] — serve the Lucide base sprite (the lowest icon layer). 737 * 738 * @return The Lucide sprite as an SVG {@link HttpResource}. 739 */ 740 @RestGet( 741 path=SYMBOLS_LUCIDE_SVG_PATH, 742 summary="Juneau rich-view Lucide SVG sprite (base layer)", 743 description="ISC-licensed Lucide glyphs that sit beneath the shipped sprite; any stem the shipped, replacement or override layer carries wins.", 744 swagger=@OpSwagger(ignore=true) 745 ) 746 public HttpResource getSymbolsLucideSvg() { 747 return serve(SYMBOLS_LUCIDE_SVG_RESOURCE, SVG_CONTENT_TYPE); 748 } 749 750 /** 751 * [GET /juneau-regions.js] — serve the opt-in region-populate runtime. 752 * 753 * @return The region-populate runtime as a JavaScript {@link HttpResource}. 754 */ 755 @RestGet( 756 path=REGIONS_JS_PATH, 757 summary="Juneau rich-view region-populate runtime", 758 description="First-party, opt-in JavaScript that resolves a name-keyed populator against a data-juneau-region container.", 759 swagger=@OpSwagger(ignore=true) 760 ) 761 public HttpResource getRegionsScript() { 762 return serve(REGIONS_JS_RESOURCE, JS_CONTENT_TYPE); 763 } 764 765 /** 766 * [GET /juneau-helpers.js] — serve the opt-in region-populate paint library. 767 * 768 * @return The paint library as a JavaScript {@link HttpResource}. 769 */ 770 @RestGet( 771 path=HELPERS_JS_PATH, 772 summary="Juneau rich-view region-populate paint library", 773 description="First-party, opt-in JavaScript helper library (fieldGrid, kvTable, tabStrip, dataPane, recordTable, and the rest of JuneauViews.helpers) for a data-juneau-region populator.", 774 swagger=@OpSwagger(ignore=true) 775 ) 776 public HttpResource getHelpersScript() { 777 return serve(HELPERS_JS_RESOURCE, JS_CONTENT_TYPE); 778 } 779 780 /** 781 * [GET /juneau-data.js] — serve the DataRegistry runtime. 782 * 783 * @return The runtime as a JavaScript {@link HttpResource}. 784 */ 785 @RestGet( 786 path=DATA_JS_PATH, 787 summary="Juneau DataRegistry runtime", 788 description="First-party JavaScript holding the columnar frames behind data: bus topics (JuneauViews.data).", 789 swagger=@OpSwagger(ignore=true) 790 ) 791 public HttpResource getDataScript() { 792 return serve(DATA_JS_RESOURCE, JS_CONTENT_TYPE); 793 } 794 795 /** 796 * [GET /juneau-terminal-view.js] — serve the opt-in terminal-view module. 797 * 798 * @return The terminal-view module as a JavaScript {@link HttpResource}. 799 * @since 10.0.0 800 */ 801 @RestGet( 802 path=RUN_VIEW_JS_PATH, 803 summary="Juneau rich-view terminal-view module", 804 description="First-party, opt-in JavaScript for the terminal-view region: a live test and build run summary with suites, failures and notes.", 805 swagger=@OpSwagger(ignore=true) 806 ) 807 public HttpResource getTerminalViewScript() { 808 return serve(RUN_VIEW_JS_RESOURCE, JS_CONTENT_TYPE); 809 } 810 811 /** 812 * [GET /juneau-config.js] — serve the opt-in column-chooser runtime (column configuration is localStorage-persisted). 813 * 814 * @return The column-chooser runtime as a JavaScript {@link HttpResource}. 815 */ 816 @RestGet( 817 path=CONFIG_JS_PATH, 818 summary="Juneau rich-view column-chooser runtime", 819 description="First-party, opt-in JavaScript that renders the View-tab column chooser and column configuration (localStorage-persisted) for a columnConfig view.", 820 swagger=@OpSwagger(ignore=true) 821 ) 822 public HttpResource getConfigScript() { 823 return serve(CONFIG_JS_RESOURCE, JS_CONTENT_TYPE); 824 } 825 826 /** 827 * [GET /juneau-config.css] — serve the opt-in column-chooser stylesheet. 828 * 829 * @return The column-chooser stylesheet as a CSS {@link HttpResource}. 830 */ 831 @RestGet( 832 path=CONFIG_CSS_PATH, 833 summary="Juneau rich-view column-chooser stylesheet", 834 description="First-party, opt-in CSS for the View-tab column chooser dialog.", 835 swagger=@OpSwagger(ignore=true) 836 ) 837 public HttpResource getConfigStylesheet() { 838 return serve(CONFIG_CSS_RESOURCE, CSS_CONTENT_TYPE); 839 } 840 841 /** 842 * Returns the servlet-relative URL for a served asset, carrying a {@code ?v=<buildVersion>-<hash8>} content- 843 * sensitive cache-buster suitable for a page's {@code head=} block (see the class Javadoc's cache-busting 844 * section for why the buster is content- rather than purely version-keyed). 845 * 846 * @param path One of the asset path constants ({@link #VIEWS_JS_PATH}, {@link #RIBBON_JS_PATH}, 847 * {@link #BUS_JS_PATH}, {@link #RENDERS_JS_PATH}, {@link #VIEWS_CSS_PATH}, {@link #ICONS_JS_PATH}, {@link #SYMBOLS_SVG_PATH}, 848 * {@link #SYMBOLS_MATERIAL_SVG_PATH}, {@link #SYMBOLS_LUCIDE_SVG_PATH}, {@link #REGIONS_JS_PATH}, {@link #HELPERS_JS_PATH}, {@link #DATA_JS_PATH}, {@link #RUN_VIEW_JS_PATH}, {@link #CONFIG_JS_PATH}, {@link #CONFIG_CSS_PATH}, 849 * {@link #CALENDAR_JS_PATH}, {@link #CALENDAR_CSS_PATH}, {@link #DATATABLES_JS_PATH}, {@link #MODEL_JS_PATH}, {@link #MODEL_INLINE_JS_PATH}). 850 * @return The servlet-relative asset URL with the version+content-hash cache-buster appended. 851 */ 852 public static String viewAssetUrl(String path) { 853 return "servlet:" + path + cacheFor(path).cacheBuster(resourceFor(path)); 854 } 855 856 /** 857 * Returns a real, browser-fetchable <b>absolute</b> URL for a served asset, resolved against the given 858 * request's context path and mount — carrying the same {@code ?v=<buildVersion>-<hash8>} content- 859 * sensitive cache-buster as {@link #viewAssetUrl(String)} (see the class Javadoc's cache-busting section). 860 * 861 * <p> 862 * {@link #viewAssetUrl(String)} returns a {@code servlet:}-prefixed URL that only Juneau's own HTML serializer 863 * resolves (it rewrites {@code servlet:} against the request at render time). A template-rendering consumer 864 * (e.g. {@code juneau-rest-server-view-freemarker}) sits downstream of that serializer, so it never sees the 865 * rewrite and would otherwise receive the literal, unfetchable string. This overload resolves the URL itself, 866 * per-request, the same way {@code ConsoleChromeMixin.assetUrl(RestRequest, ...)} does — via 867 * {@link RestRequest#getUriResolver()} — so it is usable from any consumer, template-rendered or not. 868 * 869 * @param req The current request, supplying the context path/mount to resolve against. 870 * @param path One of the asset path constants ({@link #VIEWS_JS_PATH}, {@link #RIBBON_JS_PATH}, 871 * {@link #BUS_JS_PATH}, {@link #RENDERS_JS_PATH}, {@link #VIEWS_CSS_PATH}, {@link #ICONS_JS_PATH}, {@link #SYMBOLS_SVG_PATH}, 872 * {@link #SYMBOLS_MATERIAL_SVG_PATH}, {@link #SYMBOLS_LUCIDE_SVG_PATH}, {@link #REGIONS_JS_PATH}, {@link #HELPERS_JS_PATH}, {@link #DATA_JS_PATH}, {@link #RUN_VIEW_JS_PATH}, {@link #CONFIG_JS_PATH}, {@link #CONFIG_CSS_PATH}, 873 * {@link #CALENDAR_JS_PATH}, {@link #CALENDAR_CSS_PATH}, {@link #DATATABLES_JS_PATH}, {@link #MODEL_JS_PATH}, {@link #MODEL_INLINE_JS_PATH}). 874 * @return The absolute asset URL with the version+content-hash cache-buster appended. 875 */ 876 public static String viewAssetUrl(RestRequest req, String path) { 877 return req.getUriResolver().resolve("servlet:" + path) + cacheFor(path).cacheBuster(resourceFor(path)); 878 } 879 880 /** 881 * [GET /juneau-calendar.js] — serve the opt-in reusable-calendar runtime from the widget module's classpath. 882 * 883 * @return The calendar runtime as a JavaScript {@link HttpResource}. 884 * @deprecated Compose {@link WidgetsMixin} instead, which ships these bytes. This mount stays so that an 885 * application composing only this mixin keeps serving the asset at the same URL with the same body. 886 */ 887 @Deprecated(since = "10.0.0", forRemoval = false) 888 @RestGet( 889 path=CALENDAR_JS_PATH, 890 summary="Juneau reusable-calendar runtime (relocated)", 891 description="Deprecated compatibility mount. The calendar runtime now ships in juneau-console-widgets; these bytes are read from that module and are identical to the ones WidgetsMixin serves.", 892 swagger=@OpSwagger(ignore=true) 893 ) 894 public HttpResource getCalendarScript() { 895 return WIDGET_ASSET_CACHE.serve(CALENDAR_JS_RESOURCE, JS_CONTENT_TYPE, CACHE_CONTROL); 896 } 897 898 /** 899 * [GET /juneau-calendar.css] — serve the opt-in reusable-calendar stylesheet from the widget module's classpath. 900 * 901 * @return The calendar stylesheet as a CSS {@link HttpResource}. 902 * @deprecated Compose {@link WidgetsMixin} instead, which ships these bytes. This mount stays so that an 903 * application composing only this mixin keeps serving the asset at the same URL with the same body. 904 */ 905 @Deprecated(since = "10.0.0", forRemoval = false) 906 @RestGet( 907 path=CALENDAR_CSS_PATH, 908 summary="Juneau reusable-calendar stylesheet (relocated)", 909 description="Deprecated compatibility mount. The calendar stylesheet now ships in juneau-console-widgets; these bytes are read from that module and are identical to the ones WidgetsMixin serves.", 910 swagger=@OpSwagger(ignore=true) 911 ) 912 public HttpResource getCalendarStylesheet() { 913 return WIDGET_ASSET_CACHE.serve(CALENDAR_CSS_RESOURCE, CSS_CONTENT_TYPE, CACHE_CONTROL); 914 } 915 916 /** 917 * [GET /juneau-console.js] — serve the console shell runtime from the console-ui module's classpath. 918 * 919 * @return The console shell runtime as a JavaScript {@link HttpResource}. 920 */ 921 @RestGet( 922 path=CONSOLE_JS_PATH, 923 summary="Juneau console shell runtime", 924 description="Renders the #juneau-page contract into header, nav, cards and footer; served from the console-ui module's classpath.", 925 swagger=@OpSwagger(ignore=true) 926 ) 927 public HttpResource getConsoleJs() { 928 return CONSOLE_ASSET_CACHE.serve(ConsoleChromeMixin.CONSOLE_JS_RESOURCE, JS_CONTENT_TYPE, CACHE_CONTROL); 929 } 930 931 /** The path of the single-symbol SVG route. */ 932 public static final String SYMBOL_SVG_PATH = "/juneau-symbol/{file}"; 933 934 private static final Pattern SYMBOL_NAME = Pattern.compile("[a-z0-9_]{1,64}"); 935 936 /** 937 * [GET /juneau-symbol/{name}.svg] — serve one built-in symbol as a standalone SVG, for use as a favicon. 938 * 939 * @param file The symbol file name, <c>{name}.svg</c> with the name matching <c>[a-z0-9_]{1,64}</c>. 940 * @return The symbol as an {@link HttpResource}. 941 * @throws NotFound If the name is malformed or no sprite defines it. 942 */ 943 @RestGet( 944 path=SYMBOL_SVG_PATH, 945 summary="Single built-in symbol as a standalone SVG", 946 description="A symbol from the Lucide or shipped sprite, with colours that follow prefers-color-scheme; for favicons.", 947 swagger=@OpSwagger(ignore=true) 948 ) 949 @SuppressWarnings({ 950 "java:S135" // Sprite search skips missing symbols and stops at an unsafe one; each exit is distinct. 951 }) 952 public HttpResource getSymbol(@Path("file") String file) { 953 var name = file.endsWith(".svg") ? file.substring(0, file.length() - 4) : ""; 954 if (! SYMBOL_NAME.matcher(name).matches()) 955 throw new NotFound("Unknown symbol: " + name); 956 var open = "<symbol id=\"juneau-sym-" + name + "\""; 957 for (var resource : new String[]{SYMBOLS_LUCIDE_SVG_RESOURCE, SYMBOLS_SVG_RESOURCE}) { 958 var sprite = new String(ASSET_CACHE.bytes(resource), StandardCharsets.UTF_8); 959 var start = sprite.indexOf(open); 960 if (start < 0) 961 continue; 962 var innerStart = sprite.indexOf('>', start) + 1; 963 var inner = sprite.substring(innerStart, sprite.indexOf("</symbol>", innerStart)); 964 // A symbol that fills with currentColor on its own tag passes that fill to its children through a wrapper group. 965 if (sprite.substring(start, innerStart).contains("fill=\"currentColor\"")) 966 inner = "<g class=\"f\">" + inner + "</g>"; 967 if (inner.contains("<script")) 968 break; 969 // A presentation attribute cannot hold a CSS variable, so currentColor becomes a class the embedded stylesheet colours. 970 var svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\">" 971 + "<style>.s{stroke:#4a4a4a}.f{fill:#4a4a4a}@media (prefers-color-scheme:dark){.s{stroke:#c8c8c8}.f{fill:#c8c8c8}}</style>" 972 + inner.replace("stroke=\"currentColor\"", "class=\"s\"").replace("fill=\"currentColor\"", "class=\"f\"") + "</svg>"; 973 return ASSET_CACHE.wrap(svg.getBytes(StandardCharsets.UTF_8), SVG_CONTENT_TYPE, CACHE_CONTROL); 974 } 975 throw new NotFound("Unknown symbol: " + name); 976 } 977 978 /** Reads (and caches) the classpath asset and wraps it as a cacheable {@link HttpResource}. */ 979 private static HttpResource serve(String resource, String contentType) { 980 return ASSET_CACHE.serve(resource, contentType, CACHE_CONTROL); 981 } 982 983 /** 984 * Selects the cache that owns the given asset path: the two relocated widget assets hash and version through 985 * the widget module's cache (see {@link #WIDGET_ASSET_CACHE}), the DataTables glue through the datatables 986 * module's (see {@link #DATATABLES_ASSET_CACHE}), everything else through this module's own. 987 */ 988 private static ClasspathAssetCache cacheFor(String path) { 989 if (eqa(path, CALENDAR_JS_PATH, CALENDAR_CSS_PATH)) 990 return WIDGET_ASSET_CACHE; 991 if (eq(path, DATATABLES_JS_PATH)) 992 return DATATABLES_ASSET_CACHE; 993 return ASSET_CACHE; 994 } 995 996 /** Maps a public asset path constant to its classpath resource constant (content-hashing only; routing itself is by {@code @RestGet(path=...)}). */ 997 @SuppressWarnings({ 998 "java:S3776" // Flat path-to-resource lookup table; one branch per asset, no nesting. 999 }) 1000 private static String resourceFor(String path) { 1001 if (eq(path, VIEWS_JS_PATH)) return VIEWS_JS_RESOURCE; 1002 if (eq(path, RIBBON_JS_PATH)) return RIBBON_JS_RESOURCE; 1003 if (eq(path, RENDERS_JS_PATH)) return RENDERS_JS_RESOURCE; 1004 if (eq(path, VIEWS_CSS_PATH)) return VIEWS_CSS_RESOURCE; 1005 if (eq(path, ICONS_JS_PATH)) return ICONS_JS_RESOURCE; 1006 if (eq(path, SEARCH_JS_PATH)) return SEARCH_JS_RESOURCE; 1007 if (eq(path, PAGESTATE_JS_PATH)) return PAGESTATE_JS_RESOURCE; 1008 if (eq(path, URLSTATE_JS_PATH)) return URLSTATE_JS_RESOURCE; 1009 if (eq(path, BUS_JS_PATH)) return BUS_JS_RESOURCE; 1010 if (eq(path, MODEL_JS_PATH)) return MODEL_JS_RESOURCE; 1011 if (eq(path, MODEL_INLINE_JS_PATH)) return MODEL_INLINE_JS_RESOURCE; 1012 if (eq(path, SYMBOLS_SVG_PATH)) return SYMBOLS_SVG_RESOURCE; 1013 if (eq(path, SYMBOLS_MATERIAL_SVG_PATH)) return SYMBOLS_MATERIAL_SVG_RESOURCE; 1014 if (eq(path, SYMBOLS_LUCIDE_SVG_PATH)) return SYMBOLS_LUCIDE_SVG_RESOURCE; 1015 if (eq(path, REGIONS_JS_PATH)) return REGIONS_JS_RESOURCE; 1016 if (eq(path, HELPERS_JS_PATH)) return HELPERS_JS_RESOURCE; 1017 if (eq(path, DATA_JS_PATH)) return DATA_JS_RESOURCE; 1018 if (eq(path, RUN_VIEW_JS_PATH)) return RUN_VIEW_JS_RESOURCE; 1019 if (eq(path, CONFIG_JS_PATH)) return CONFIG_JS_RESOURCE; 1020 if (eq(path, CONFIG_CSS_PATH)) return CONFIG_CSS_RESOURCE; 1021 if (eq(path, CALENDAR_JS_PATH)) return CALENDAR_JS_RESOURCE; 1022 if (eq(path, CALENDAR_CSS_PATH)) return CALENDAR_CSS_RESOURCE; 1023 if (eq(path, DATATABLES_JS_PATH)) return DATATABLES_JS_RESOURCE; 1024 throw new IllegalArgumentException("Unknown asset path: " + path); 1025 } 1026}