Class MjmlNode
java.lang.Object
dev.jcputney.mjml.parser.MjmlNode
Lightweight mutable tree node representing an MJML element. Each node has a tag name, attributes,
text content, and children.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a child node to this node and sets the child's parent reference.getAttribute(String name) Returns the value of the attribute with the given name, ornullif not present.getAttribute(String name, String defaultValue) Returns the value of the attribute with the given name, or the default value if not present.Returns an unmodifiable view of all attributes on this node.Returns an unmodifiable view of this node's children.getChildrenByTag(String tag) Returns direct children with the specified tag name.getFirstChildByTag(String tag) Returns the first direct child with the specified tag name, ornullif none match.Returns the inner HTML content - the serialized content of all children.String[]Returns the cached array of mj-class names on this node.Returns the outer HTML of this node including its tag, attributes, and content.Returns the parent node, ornullif this is a root node.Returns the tag name of this node.Returns the text content of this node.voidreplaceWith(List<MjmlNode> replacements) Replaces this node in its parent's children list with the given nodes.voidsetAttribute(String name, String value) Sets the attribute with the given name to the given value.voidsetTextContent(String textContent) Sets the text content of this node.toString()
-
Constructor Details
-
MjmlNode
-
-
Method Details
-
getTagName
-
getAttribute
-
getAttribute
Returns the value of the attribute with the given name, or the default value if not present.- Parameters:
name- the attribute namedefaultValue- the value to return if the attribute is not set- Returns:
- the attribute value, or
defaultValueif the attribute is not set
-
getMjClassNames
Returns the cached array of mj-class names on this node. The result is cached and invalidated when the "mj-class" attribute is changed viasetAttribute(String, String).- Returns:
- the array of class names, or an empty array if no mj-class attribute is set
-
setAttribute
-
getAttributes
-
getChildren
-
addChild
Adds a child node to this node and sets the child's parent reference.- Parameters:
child- the child node to add
-
replaceWith
-
getParent
Returns the parent node, ornullif this is a root node.- Returns:
- the parent node, or
null
-
getTextContent
Returns the text content of this node.- Returns:
- the text content, never
null
-
setTextContent
Sets the text content of this node. Anullvalue is treated as empty string.- Parameters:
textContent- the text content to set
-
getChildrenByTag
-
getFirstChildByTag
-
getInnerHtml
Returns the inner HTML content - the serialized content of all children. For ending tags with CDATA-wrapped content, this returns the raw HTML.- Returns:
- the inner HTML string
-
getOuterHtml
Returns the outer HTML of this node including its tag, attributes, and content.- Returns:
- the outer HTML string
-
toString
-