Class AttributeContext

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

public class AttributeContext extends Object
Attribute cascade state gathered during head processing. Contains default attributes (from <mj-attributes>), class attributes (from <mj-class>), and HTML attributes (from <mj-html-attributes>).

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

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

  • Constructor Details

    • AttributeContext

      public AttributeContext()
      Creates a new empty AttributeContext with no default, class, or HTML attributes.
  • Method Details

    • setDefaultAttributes

      public void setDefaultAttributes(String tagName, Map<String,String> attrs)
      Sets default attributes for a given MJML tag name. If attributes already exist for the tag, the new values are merged in.
      Parameters:
      tagName - the MJML tag name (e.g. "mj-all", "mj-section")
      attrs - the attribute name-value pairs to set
    • getDefaultAttributes

      public Map<String,String> getDefaultAttributes(String tagName)
      Returns the default attributes for a given MJML tag name.
      Parameters:
      tagName - the MJML tag name to look up
      Returns:
      the attribute map for the tag, or an empty map if none are set
    • getAllDefaults

      public Map<String,String> getAllDefaults()
      Returns the global default attributes defined under the "mj-all" tag.
      Returns:
      the "mj-all" attribute map, or an empty map if none are set
    • setClassAttributes

      public void setClassAttributes(String className, Map<String,String> attrs)
      Sets class-level attributes for a given MJML class name. If attributes already exist for the class, the new values are merged in.
      Parameters:
      className - the MJML class name
      attrs - the attribute name-value pairs to set
    • getClassAttributes

      public Map<String,String> getClassAttributes(String className)
      Returns the class-level attributes for a given MJML class name.
      Parameters:
      className - the MJML class name to look up
      Returns:
      the attribute map for the class, or an empty map if none are set
    • setHtmlAttributes

      public void setHtmlAttributes(String selector, Map<String,String> attrs)
      Sets HTML attributes for a given CSS selector. If attributes already exist for the selector, the new values are merged in.
      Parameters:
      selector - the CSS selector identifying target elements
      attrs - the attribute name-value pairs to set
    • getHtmlAttributes

      public Map<String, Map<String,String>> getHtmlAttributes()
      Returns an unmodifiable view of all HTML attributes keyed by CSS selector.
      Returns:
      unmodifiable map of selector to attribute map