Class MetadataContext
java.lang.Object
dev.jcputney.mjml.context.MetadataContext
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 Summary
ConstructorsConstructorDescriptionCreates a newMetadataContextwith default values: empty title and preview text, a breakpoint of"480px", the default container width, and no head comments or file-start content. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFileStartContent(String content) Adds content that should appear at the start of the rendered file.voidaddHeadComment(String comment) Adds a comment found in the<mj-head>section to the list of head comments.Returns the body background color CSS value.Returns the responsive breakpoint as a CSS value string (e.g.intReturns the responsive breakpoint parsed as an integer pixel value.intReturns the container width in pixels.Returns an unmodifiable list of content strings that should appear at the start of the rendered file.Returns an unmodifiable list of comments found in the<mj-head>section.Returns the email preview text (shown in inbox previews).getTitle()Returns the document title.voidsetBodyBackgroundColor(String bodyBackgroundColor) Sets the body background color.voidsetBreakpoint(String breakpoint) Sets the responsive breakpoint.voidsetContainerWidth(int containerWidth) Sets the container width in pixels.voidsetPreviewText(String previewText) Sets the email preview text.voidSets the document title.
-
Constructor Details
-
MetadataContext
public MetadataContext()Creates a newMetadataContextwith 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
-
setTitle
Sets the document title. Anullvalue is normalized to an empty string.- Parameters:
title- the title to set
-
getPreviewText
Returns the email preview text (shown in inbox previews).- Returns:
- the preview text, never
null
-
setPreviewText
Sets the email preview text. Anullvalue is normalized to an empty string.- Parameters:
previewText- the preview text to set
-
getBreakpoint
Returns the responsive breakpoint as a CSS value string (e.g."480px").- Returns:
- the breakpoint string
-
setBreakpoint
Sets the responsive breakpoint.nullor 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 to480.- 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
Returns the body background color CSS value.- Returns:
- the body background color, never
null
-
setBodyBackgroundColor
Sets the body background color. Anullvalue is normalized to an empty string.- Parameters:
bodyBackgroundColor- the body background color CSS value to set
-
addHeadComment
Adds a comment found in the<mj-head>section to the list of head comments.- Parameters:
comment- the comment text to add
-
getHeadComments
-
addFileStartContent
Adds content that should appear at the start of the rendered file.nullor empty values are ignored.- Parameters:
content- the file-start content to add
-
getFileStartContent
-