Class HtmlLetterBuilder
java.lang.Object
com.nsdev.lettergenerator.builder.HtmlLetterBuilder
Mutable compiler input for the supported HTML-like letter template language. Prefer
Letter.template(String) or Letter.fromHtml(String) as entry points. A single <letter>
root defines regions and page settings; arbitrary browser HTML is not supported. Placeholder
values replace parsed text and attribute values without creating new markup nodes. Image
references use explicitly registered asset bytes.
Values replace the previous binding map; assets accumulate by name and replace an existing
name. Parsing, substitution, and asset resolution happen at build(). Each build returns
an independent immutable document; full rendering validation happens in LetterPdfGenerator.
-
Method Summary
Modifier and TypeMethodDescriptionRegisters a defensive copy of named image bytes for later HTML asset resolution.Reads a local file immediately and registers its bytes as a named markup image asset.build()Compiles the current source, bindings and assets into an immutable document snapshot.compile()Captures parsed source and owned configuration for concurrent repeated binding.component(String name, LetterComponent value) Registers a fragment referenced by an empty component tag with a ref attribute.locale(LocaleSettings value) Sets deterministic document locale while preserving other explicit settings.static HtmlLetterBuilderresolvedHtml(String source) Creates a builder for already-resolved letter markup with substitution disabled.settings(DocumentSettings value) Sets immutable language, metadata and text configuration.static HtmlLetterBuilderCreates a builder with${name}substitution enabled.theme(LetterTheme value) Supplies per-document role defaults and named styles.validate()Inspects bindings, assets and declared model constraints using built-in fonts, without PDF layout.validate(LetterPdfGenerator generator) Inspects with the selected generator's registered fonts.Replaces all bindings with an owned typed snapshot.
-
Method Details
-
template
Creates a builder with${name}substitution enabled. Missing bindings fail at build time; replacement values are not recursively substituted.- Parameters:
source- non-null source containing one supported<letter>root- Returns:
- a fresh template builder
- Throws:
IllegalArgumentException- ifsourceis null
-
resolvedHtml
Creates a builder for already-resolved letter markup with substitution disabled. Callingvalues(Map)on this builder is an error.- Parameters:
source- non-null source containing one supported<letter>root- Returns:
- a fresh builder for resolved markup
- Throws:
IllegalArgumentException- ifsourceis null
-
values
Replaces all bindings with an owned typed snapshot. Maps with nonblank string keys, lists, finite numbers, booleans, text, characters and supported immutable java.time values are accepted. Null values, cycles and arbitrary objects fail with the input path.- Parameters:
replacements- non-null map of nonblank keys to non-null supported values- Returns:
- this builder
- Throws:
IllegalArgumentException- if substitution is disabled, the map is null, a key is null or blank, or a value is null or unsupported
-
locale
Sets deterministic document locale while preserving other explicit settings.- Parameters:
value- non-null formatting settings- Returns:
- this builder
-
settings
Sets immutable language, metadata and text configuration.- Parameters:
value- non-null document settings- Returns:
- this builder
-
compile
Captures parsed source and owned configuration for concurrent repeated binding.- Returns:
- immutable prepared template
-
asset
Registers a defensive copy of named image bytes for later HTML asset resolution. Reusing a name replaces its previous bytes. Image decoding and format checks occur when markup referencing the asset is built, so registration can follow content calls.- Parameters:
name- nonblank asset identifier used by markup image referencesdata- non-null image bytes; supported image formats are PNG, JPEG and static SVG- Returns:
- this builder
- Throws:
IllegalArgumentException- if the name is null or blank, or the bytes are null
-
asset
Reads a local file immediately and registers its bytes as a named markup image asset. Reusing a name replaces the existing asset; image decoding is deferred until referenced markup is built.- Parameters:
name- nonblank asset identifierpath- non-null image file to read- Returns:
- this builder
- Throws:
IOException- if the file cannot be readNullPointerException- ifpathis nullIllegalArgumentException- ifnameis null or blank
-
theme
Supplies per-document role defaults and named styles.- Parameters:
value- non-null immutable theme- Returns:
- this builder
-
component
Registers a fragment referenced by an empty component tag with a ref attribute.- Parameters:
name- nonblank component namevalue- immutable content- Returns:
- this builder
-
validate
Inspects bindings, assets and declared model constraints using built-in fonts, without PDF layout.- Returns:
- immutable report aggregating missing variable occurrences and invalid assets
-
validate
Inspects with the selected generator's registered fonts. Success does not guarantee content fit.- Parameters:
generator- non-null font-aware validator- Returns:
- immutable authoring report
-
build
Compiles the current source, bindings and assets into an immutable document snapshot. Template parsing, supported-tag and style checks, placeholder binding, image decoding and region arrangement occur here. Rendering validation, including font availability and layout constraints, is performed later byLetterPdfGenerator. The builder remains reusable after a build.- Returns:
- a new immutable letter document
- Throws:
InvalidLetterException- if markup, placeholders, referenced assets or constructed letter regions are invalid, or no body content is produced
-