Class MjmlConfiguration

java.lang.Object
dev.jcputney.mjml.MjmlConfiguration

public final class MjmlConfiguration extends Object
Configuration for the MJML renderer. Use the builder() method to create instances.
  • Field Details

    • DEFAULT_MAX_INPUT_SIZE

      public static final int DEFAULT_MAX_INPUT_SIZE
      Default maximum input size in characters (approximately 1 MB for ASCII).
      See Also:
    • DEFAULT_MAX_NESTING_DEPTH

      public static final int DEFAULT_MAX_NESTING_DEPTH
      Default maximum nesting depth.
      See Also:
    • DEFAULT_MAX_INCLUDE_DEPTH

      public static final int DEFAULT_MAX_INCLUDE_DEPTH
      Default maximum include depth.
      See Also:
    • DEFAULT_CONTAINER_WIDTH

      public static final int DEFAULT_CONTAINER_WIDTH
      Default container width in pixels, matching the MJML v4 default of 600px.
      See Also:
  • Method Details

    • builder

      public static MjmlConfiguration.Builder builder()
      Creates a new MjmlConfiguration.Builder for constructing an MjmlConfiguration.
      Returns:
      a new builder instance
    • defaults

      public static MjmlConfiguration defaults()
      Returns a default configuration with all settings at their default values.
      Returns:
      a default MjmlConfiguration instance
    • getLanguage

      public String getLanguage()
      Returns the language code for the HTML document. Defaults to "und" (undetermined).
      Returns:
      the language code
    • getDirection

      public Direction getDirection()
      Returns the text direction for the HTML document. Defaults to Direction.AUTO.
      Returns:
      the text direction
    • getIncludeResolver

      public IncludeResolver getIncludeResolver()
      Returns the include resolver used to resolve mj-include paths, or null if none is configured.
      Returns:
      the include resolver, or null
    • getCustomComponents

      public Map<String, ComponentFactory> getCustomComponents()
      Returns the custom component factories registered via MjmlConfiguration.Builder.registerComponent(String, ComponentFactory).
      Returns:
      an unmodifiable map of tag names to component factories
    • getCustomContainerComponents

      public Map<String, ContainerComponentFactory> getCustomContainerComponents()
      Returns the custom container component factories registered via MjmlConfiguration.Builder.registerContainerComponent(String, ContainerComponentFactory). Container components receive the ComponentRegistry as a fourth argument, allowing them to instantiate and render child components.
      Returns:
      an unmodifiable map of tag names to container component factories
    • isSanitizeOutput

      public boolean isSanitizeOutput()
      Whether to escape HTML special characters in attribute values in rendered output. When true, characters like ", <, >, & are escaped in attribute values to prevent XSS. Default is true.
      Returns:
      true if output sanitization is enabled
    • getMaxInputSize

      public int getMaxInputSize()
      Maximum allowed input size in characters. Inputs exceeding this limit are rejected before processing. Default is 1,048,576 (approximately 1 MB for ASCII).
      Returns:
      the maximum input size in characters
    • getMaxNestingDepth

      public int getMaxNestingDepth()
      Maximum allowed nesting depth for MJML elements. Exceeding this depth during parsing or rendering throws an exception. Default is 100.
      Returns:
      the maximum nesting depth
    • getMaxIncludeDepth

      public int getMaxIncludeDepth()
      Maximum allowed include nesting depth for mj-include. Exceeding this depth during include resolution throws an exception. Default is 50.
      Returns:
      the maximum include depth
    • getContentSanitizer

      public ContentSanitizer getContentSanitizer()
      Returns the optional content sanitizer, or null if none is configured. When set, the sanitizer is applied to the inner HTML content of <mj-text>, <mj-button>, and <mj-raw> elements before rendering.
      Returns:
      the content sanitizer, or null if none is configured
    • toBuilder

      public MjmlConfiguration.Builder toBuilder()
      Returns a builder pre-populated with this configuration's values.
      Returns:
      a new builder initialized with this configuration's values
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object