Class MetadataContext

java.lang.Object
dev.jcputney.mjml.context.MetadataContext

public class MetadataContext extends Object
Document-level metadata gathered during head processing. Contains title, preview text, breakpoint, container width, body background color, head comments, and file-start content.

This is one of three focused sub-contexts extracted from GlobalContext. See also StyleContext and AttributeContext.

Thread safety: This class is not thread-safe. Each render pipeline creates its own instance.

  • Constructor Details

    • MetadataContext

      public MetadataContext()
      Creates a new MetadataContext with default values: empty title and preview text, a breakpoint of "480px", the default container width, and no head comments or file-start content.
  • Method Details

    • getTitle

      public String getTitle()
      Returns the document title.
      Returns:
      the title, never null
    • setTitle

      public void setTitle(String title)
      Sets the document title. A null value is normalized to an empty string.
      Parameters:
      title - the title to set
    • getPreviewText

      public String getPreviewText()
      Returns the email preview text (shown in inbox previews).
      Returns:
      the preview text, never null
    • setPreviewText

      public void setPreviewText(String previewText)
      Sets the email preview text. A null value is normalized to an empty string.
      Parameters:
      previewText - the preview text to set
    • getBreakpoint

      public String getBreakpoint()
      Returns the responsive breakpoint as a CSS value string (e.g. "480px").
      Returns:
      the breakpoint string
    • setBreakpoint

      public void setBreakpoint(String breakpoint)
      Sets the responsive breakpoint. null or empty values are ignored, leaving the current breakpoint unchanged.
      Parameters:
      breakpoint - the breakpoint CSS value to set (e.g. "480px")
    • getBreakpointPx

      public int getBreakpointPx()
      Returns the responsive breakpoint parsed as an integer pixel value. If parsing fails, defaults to 480.
      Returns:
      the breakpoint in pixels
    • getContainerWidth

      public int getContainerWidth()
      Returns the container width in pixels.
      Returns:
      the container width
    • setContainerWidth

      public void setContainerWidth(int containerWidth)
      Sets the container width in pixels.
      Parameters:
      containerWidth - the container width to set
    • getBodyBackgroundColor

      public String getBodyBackgroundColor()
      Returns the body background color CSS value.
      Returns:
      the body background color, never null
    • setBodyBackgroundColor

      public void setBodyBackgroundColor(String bodyBackgroundColor)
      Sets the body background color. A null value is normalized to an empty string.
      Parameters:
      bodyBackgroundColor - the body background color CSS value to set
    • addHeadComment

      public void addHeadComment(String comment)
      Adds a comment found in the <mj-head> section to the list of head comments.
      Parameters:
      comment - the comment text to add
    • getHeadComments

      public List<String> getHeadComments()
      Returns an unmodifiable list of comments found in the <mj-head> section.
      Returns:
      an unmodifiable list of head comment strings
    • addFileStartContent

      public void addFileStartContent(String content)
      Adds content that should appear at the start of the rendered file. null or empty values are ignored.
      Parameters:
      content - the file-start content to add
    • getFileStartContent

      public List<String> getFileStartContent()
      Returns an unmodifiable list of content strings that should appear at the start of the rendered file.
      Returns:
      an unmodifiable list of file-start content strings