Class BaseComponent

java.lang.Object
dev.jcputney.mjml.component.BaseComponent
Direct Known Subclasses:
BodyComponent, HeadComponent

public abstract sealed class BaseComponent extends Object permits BodyComponent, HeadComponent
Abstract base class for all MJML components. Sealed to permit only BodyComponent and HeadComponent subtypes.
  • Field Details

    • node

      protected final MjmlNode node
      The parsed MJML node backing this component.
    • globalContext

      protected final GlobalContext globalContext
      The global rendering context shared across all components.
    • renderContext

      protected final RenderContext renderContext
      The render-phase context for the current rendering pass.
  • Constructor Details

    • BaseComponent

      protected BaseComponent(MjmlNode node, GlobalContext globalContext, RenderContext renderContext)
      Creates a new component bound to the given node and contexts.
      Parameters:
      node - the parsed MJML node
      globalContext - the global rendering context
      renderContext - the render-phase context
  • Method Details

    • getTagName

      public abstract String getTagName()
      Returns the MJML tag name this component handles.
      Returns:
      the MJML tag name
    • getDefaultAttributes

      public abstract Map<String,String> getDefaultAttributes()
      Returns the default attribute values for this component.
      Returns:
      a map of attribute names to their default values
    • getAttribute

      public String getAttribute(String name)
      Resolves an attribute value using the 5-level cascade.
      Parameters:
      name - the attribute name to resolve
      Returns:
      the resolved attribute value, or null if not found
    • getAttribute

      public String getAttribute(String name, String defaultValue)
      Resolves an attribute value, returning the provided default if not found.
      Parameters:
      name - the attribute name to resolve
      defaultValue - the value to return if the attribute is not found
      Returns:
      the resolved attribute value, or defaultValue if not found
    • getNode

      public MjmlNode getNode()
      Returns the parsed MJML node backing this component.
      Returns:
      the MJML node