Record Class LetterDocument

java.lang.Object
java.lang.Record
com.nsdev.lettergenerator.model.LetterDocument
Record Components:
schemaVersion - input schema version; generation currently requires SUPPORTED_SCHEMA_VERSION
page - physical layout, or null for PageSpec.defaults()
defaultStyle - nullable overrides applied before section, block, cell, and run styles
sections - body sections in reading order; generation requires at least one body block
fixedElements - positioned top/bottom content; null means no fixed elements
signature - optional visual signature; null means no signature
watermark - optional decoration behind page content; null means no watermark
theme - optional document-local role and named style defaults
components - optional document-local reusable content; null becomes an empty map
settings - optional formatting and output metadata; null selects stable defaults
attachments - optional PDFs appended unchanged after the generated letter

public record LetterDocument(int schemaVersion, PageSpec page, Style defaultStyle, List<Section> sections, List<FixedElement> fixedElements, Signature signature, Watermark watermark, LetterTheme theme, Map<String,LetterComponent> components, DocumentSettings settings, List<PdfAttachment> attachments) extends Record
Complete immutable input to PDF generation, shared by the Java builders and JSON input. A document contains body sections, optional positioned content, a visual signature, and a watermark. The schema version is checked during generation; constructing this record does not validate content, fonts, geometry, or image formats.

Supplied lists and the component map are copied into unmodifiable collections, preserving null entries for later validation. A null sections list remains null; only a null fixed-elements list becomes empty. Themes and reusable components resolve before ordinary validation, without global registrations.

  • Field Details

    • SUPPORTED_SCHEMA_VERSION

      public static final int SUPPORTED_SCHEMA_VERSION
      Schema version accepted by generation and by the JSON document model.
      See Also:
  • Constructor Details

    • LetterDocument

      public LetterDocument(int schemaVersion, PageSpec page, Style defaultStyle, List<Section> sections, List<FixedElement> fixedElements, Signature signature, Watermark watermark, LetterTheme theme, Map<String,LetterComponent> components, DocumentSettings settings, List<PdfAttachment> attachments)
      Substitutes the default page and snapshots both lists without validating their contents.
      Parameters:
      schemaVersion - schema identifier stored unchanged
      page - page specification, or null to use the default
      defaultStyle - optional document-wide style overrides
      sections - ordered body sections, copied if nonnull
      fixedElements - positioned elements, copied or replaced with an empty list
      signature - optional visual signature
      watermark - optional page decoration
      theme - nullable role and named-style definitions
      components - nullable reusable-content registrations, defensively copied
      settings - optional document settings
      attachments - optional appended PDF snapshots
    • LetterDocument

      public LetterDocument(int schemaVersion, PageSpec page, Style defaultStyle, List<Section> sections, List<FixedElement> fixedElements, Signature signature, Watermark watermark, LetterTheme theme, Map<String,LetterComponent> components)
      Preserves composition-aware construction without additional settings or attachments.
      Parameters:
      schemaVersion - input schema
      page - physical layout
      defaultStyle - document style
      sections - body sections
      fixedElements - fixed content
      signature - optional signature
      watermark - optional decoration
      theme - optional theme
      components - optional reusable registrations
    • LetterDocument

      public LetterDocument(int schemaVersion, PageSpec page, Style defaultStyle, List<Section> sections, List<FixedElement> fixedElements, Signature signature, Watermark watermark)
      Preserves the original constructor with no theme or reusable-content registrations.
      Parameters:
      schemaVersion - input schema version
      page - nullable page specification
      defaultStyle - nullable document overrides
      sections - ordered body sections
      fixedElements - nullable positioned content
      signature - nullable visual signature
      watermark - nullable decoration
  • Method Details

    • withTheme

      public LetterDocument withTheme(LetterTheme value)
      Replaces the theme while retaining content and component registrations.
      Parameters:
      value - nullable theme
      Returns:
      immutable document copy
    • withComponents

      public LetterDocument withComponents(Map<String,LetterComponent> value)
      Replaces component registrations with a defensive snapshot.
      Parameters:
      value - nullable document-local component registrations
      Returns:
      immutable document copy
    • withSettings

      public LetterDocument withSettings(DocumentSettings value)
      Replaces document settings while preserving all content and attachments.
      Parameters:
      value - formatting/output metadata
      Returns:
      independent immutable model
    • withAttachments

      public LetterDocument withAttachments(List<PdfAttachment> value)
      Replaces appended PDF registrations while retaining the letter.
      Parameters:
      value - appended PDFs, snapshotted
      Returns:
      immutable model
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • schemaVersion

      public int schemaVersion()
      Returns the value of the schemaVersion record component.
      Returns:
      the value of the schemaVersion record component
    • page

      public PageSpec page()
      Returns the value of the page record component.
      Returns:
      the value of the page record component
    • defaultStyle

      public Style defaultStyle()
      Returns the value of the defaultStyle record component.
      Returns:
      the value of the defaultStyle record component
    • sections

      public List<Section> sections()
      Returns the value of the sections record component.
      Returns:
      the value of the sections record component
    • fixedElements

      public List<FixedElement> fixedElements()
      Returns the value of the fixedElements record component.
      Returns:
      the value of the fixedElements record component
    • signature

      public Signature signature()
      Returns the value of the signature record component.
      Returns:
      the value of the signature record component
    • watermark

      public Watermark watermark()
      Returns the value of the watermark record component.
      Returns:
      the value of the watermark record component
    • theme

      public LetterTheme theme()
      Returns the value of the theme record component.
      Returns:
      the value of the theme record component
    • components

      public Map<String,LetterComponent> components()
      Returns the value of the components record component.
      Returns:
      the value of the components record component
    • settings

      public DocumentSettings settings()
      Returns the value of the settings record component.
      Returns:
      the value of the settings record component
    • attachments

      public List<PdfAttachment> attachments()
      Returns the value of the attachments record component.
      Returns:
      the value of the attachments record component