Class PageCapture
java.lang.Object
org.apache.juneau.console.freemarker.PageCapture
Typed, per-render capture of one console page: theme, header, footer, nav tree, active nav, cards
and slot templates, held as FreeMarker
Environment custom state (see KEY) so every
directive in the render shares one instance. <@console> serializes it as the #juneau-page
contract.
Example:
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classMutable footer fields; mirrors$defs/footer.static final classMutable header fields; mirrors$defs/header.static interfaceA nav-tree mutation deferred until the chrome's nav tree exists. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionAppends a header badge.Appends a card.voidaddPendingNavUnder(String parentIdPath, PageCapture.NavAdder adder) Records a child to add under an existing chrome nav node, resolved later byapplyPendingNavAdds().Adds a header or footer slot template.voidResolves every pending nav addition recorded byaddPendingNavUnder(java.lang.String, org.apache.juneau.console.freemarker.PageCapture.NavAdder), in declaration order.cards()static PageCaptureget(freemarker.core.Environment env) Returns the capture for this render, if one exists.booleaninPage()mergeBodyAttrs(String attrs) Merge-aware setter for the raw<@body>attribute text: union by attribute name, existing (spec) text first and then the new text.Union merge for the page stylesheets: appends any URL not already present, in first-seen order.Union merge for the page init scripts: appends any URL not already present, in first-seen order.Merge-aware twin oftab(String): first writer wins, and any second non-blank writer is rejected, even with the same value.mergeTheme(String name) Merge-aware twin oftheme(String): first writer wins, a repeat of the same value is a no-op, and a differing second writer is rejected.mergeToolkit(List<String> names) Union merge fortoolkit(List): appends any name not already present, in first-seen order.navRoot()static PageCaptureof(freemarker.core.Environment env) Returns the capture for this render, creating it on first use.static Stringrender(freemarker.template.TemplateDirectiveBody body) Renders a directive body to a string.require(Collection<String> packs) Records toolkit packs the page needs, in first-seen order.schemeToggle(boolean value) Explicitly selects a nav path (<@node selected="true">).tab()Serializes the contract.toolkits()voidWrites the contract island, the templates and the shell script tag.
-
Field Details
-
KEY
Environment custom-state key. -
CONTRACT_VERSION
The contract version this server writes.- See Also:
-
-
Method Details
-
of
public static PageCapture of(freemarker.core.Environment env) throws freemarker.template.TemplateModelException Returns the capture for this render, creating it on first use.On create, a
PageSpeccarried in the data model underPageSpec.ATTRis applied to the new capture before any directive writes to it, and marked adopted.- Parameters:
env- The FreeMarker environment.- Returns:
- The capture, never
null . - Throws:
freemarker.template.TemplateModelException- If seeding aPageSpecfrom the data model fails.
-
get
Returns the capture for this render, if one exists.- Parameters:
env- The FreeMarker environment.- Returns:
- The capture, or
null .
-
render
public static String render(freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException Renders a directive body to a string.- Parameters:
body- The body, ornull .- Returns:
- The rendered markup, or
""when the body isnull . - Throws:
freemarker.template.TemplateException- On a template error.IOException- On an I/O error.
-
title
- Parameters:
v- The page title. @return This object.
-
theme
- Parameters:
name- A stock theme name. @return This object.
-
scheme
- Parameters:
name- A colour-scheme pin:auto,lightordark. @return This object.
-
schemeToggle
- Parameters:
value- Whether the visitor's stored scheme choice is honoured. @return This object.
-
tab
- Parameters:
v- The<@page tab>value. @return This object.
-
toolkit
- Parameters:
names- Toolkit names from<@page toolkit>. @return This object.
-
header
- Parameters:
c- Mutates the header. @return This object.
-
select
Explicitly selects a nav path (<@node selected="true">).- Parameters:
idPath- The root-first id path.- Returns:
- This object.
- Throws:
freemarker.template.TemplateModelException- If a path is already selected (E-6).
-
addCard
public PageCapture addCard(CardSpec card, String markupOrNull) throws freemarker.template.TemplateModelException Appends a card.- Parameters:
card- The card.markupOrNull- Markup emitted as<template data-card="{id}">, ornull .- Returns:
- This object.
- Throws:
freemarker.template.TemplateModelException- On a duplicate card id (E-9).
-
addSlot
Adds a header or footer slot template.- Parameters:
scope-headerorfooter.name- The slot name.markup- The slot markup.- Returns:
- This object.
-
addBadge
Appends a header badge.- Parameters:
badge- The badge. Must not benull .- Returns:
- This object.
- Throws:
freemarker.template.TemplateModelException- On a duplicate badge id.
-
mergeTab
Merge-aware twin oftab(String): first writer wins, and any second non-blank writer is rejected, even with the same value.- Parameters:
tab- The<@page tab>value. Blank is a no-op.- Returns:
- This object.
- Throws:
freemarker.template.TemplateModelException- If a non-blank tab was already set.
-
mergeTheme
Merge-aware twin oftheme(String): first writer wins, a repeat of the same value is a no-op, and a differing second writer is rejected.- Parameters:
name- The<@theme name>value. Blank is a no-op.- Returns:
- This object.
- Throws:
freemarker.template.TemplateModelException- If a different, non-blank theme was already set.
-
mergeBodyAttrs
Merge-aware setter for the raw<@body>attribute text: union by attribute name, existing (spec) text first and then the new text. The same attribute name on both sides is always rejected, even when the values agree. Called once, fromcheckConsoleClose(), with the text<@body>captured intoftlBodyAttrs.- Parameters:
attrs- The raw<@body>attribute text. Blank is a no-op.- Returns:
- This object.
- Throws:
freemarker.template.TemplateModelException- If an attribute name already set is set again.
-
mergeToolkit
Union merge fortoolkit(List): appends any name not already present, in first-seen order.- Parameters:
names- The names to union in.- Returns:
- This object.
-
mergeCss
Union merge for the page stylesheets: appends any URL not already present, in first-seen order.- Parameters:
hrefs- The URLs to union in.- Returns:
- This object.
-
mergeInit
Union merge for the page init scripts: appends any URL not already present, in first-seen order.- Parameters:
srcs- The URLs to union in.- Returns:
- This object.
-
require
Records toolkit packs the page needs, in first-seen order. Called by<@card>for each authored card and by other directives that emit markup needing a pack.- Parameters:
packs- The pack names.- Returns:
- This object.
-
requiredPacks
- Returns:
- The recorded pack names, in first-seen order.
-
inPage
- Returns:
true while a<@page>body is rendering.
-
tab
- Returns:
- The
<@page tab>value,""when absent.
-
toolkits
- Returns:
- The toolkit names.
-
cards
- Returns:
- The cards, in page order.
-
templates
- Returns:
- Template id to markup, in emit order.
-
toContractJson
Serializes the contract.- Returns:
- Script-safe contract JSON (every
<written as the JSON unicode escape).
-
writeBody
Writes the contract island, the templates and the shell script tag.- Parameters:
out- The writer.- Throws:
IOException- On an I/O error.
-