Class HtmlElement
java.lang.Object
dev.jcputney.mjml.css.HtmlElement
Lightweight HTML element representation for CSS selector matching and style inlining. This is NOT
a full DOM - it's a minimal model that supports the operations needed by the CSS inliner: tag
name, attributes, parent/child/sibling navigation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(HtmlElement child) Adds a child element to this element, setting its parent reference and caching its index.Returns all descendant elements in document order (depth-first).getAttribute(String name) Returns the value of the attribute with the given name, ornullif not present.Returns an unmodifiable view of all attributes on this element.Returns the list of child elements.Returns the set of CSS class names on this element, parsed from theclassattribute.getId()Returns the value of theidattribute, ornullif not set.Returns the parent element, ornullif this is the root element.getStyle()Returns the value of thestyleattribute, ornullif not set.intReturns the position immediately after the closing quote of thestyleattribute in the original HTML string, or-1if not set.intReturns the position of thestyle="substring in the original HTML string, or-1if not set.intReturns the position immediately after the closing>character in the original HTML string, or-1if not set.Returns the tag name of this element (always lowercase).intReturns the position of the opening<character in the original HTML string, or-1if not set.booleanWhether this element has position information for in-place style modification.intReturns the index of this element among its parent's children.booleanisDescendantOf(HtmlElement ancestor) Checks if this element is a descendant of the given ancestor.Returns the previous sibling element, or null if this is the first child.voidSets the inlinestyleattribute on this element.voidsetStyleAttrEnd(int styleAttrEnd) Sets the position immediately after the closing quote of thestyleattribute in the original HTML string.voidsetStyleAttrStart(int styleAttrStart) Sets the position of thestyle="substring in the original HTML string.voidsetTagEnd(int tagEnd) Sets the position immediately after the closing>character in the original HTML string.voidsetTagStart(int tagStart) Sets the position of the opening<character in the original HTML string.toString()
-
Constructor Details
-
HtmlElement
-
-
Method Details
-
getTagName
Returns the tag name of this element (always lowercase).- Returns:
- the tag name
-
getAttribute
-
getAttributes
-
getId
Returns the value of theidattribute, ornullif not set.- Returns:
- the element ID, or
null
-
getClassNames
-
getStyle
Returns the value of thestyleattribute, ornullif not set.- Returns:
- the inline style string, or
null
-
setStyle
Sets the inlinestyleattribute on this element.- Parameters:
style- the new style string
-
getParent
Returns the parent element, ornullif this is the root element.- Returns:
- the parent element, or
null
-
getChildren
Returns the list of child elements.- Returns:
- the mutable list of children
-
addChild
Adds a child element to this element, setting its parent reference and caching its index.- Parameters:
child- the child element to add
-
indexInParent
public int indexInParent()Returns the index of this element among its parent's children.- Returns:
- the zero-based index within the parent's children, or 0 if there is no parent
-
previousSibling
Returns the previous sibling element, or null if this is the first child.- Returns:
- the previous sibling, or
nullif none exists
-
isDescendantOf
Checks if this element is a descendant of the given ancestor.- Parameters:
ancestor- the potential ancestor element- Returns:
trueif this element is a descendant of the given ancestor
-
allDescendants
Returns all descendant elements in document order (depth-first). The result is cached since the tree is immutable after parsing.- Returns:
- a list of all descendant elements in depth-first order
-
getTagStart
public int getTagStart()Returns the position of the opening<character in the original HTML string, or-1if not set.- Returns:
- the tag start position, or
-1
-
setTagStart
public void setTagStart(int tagStart) Sets the position of the opening<character in the original HTML string.- Parameters:
tagStart- the tag start position
-
getTagEnd
public int getTagEnd()Returns the position immediately after the closing>character in the original HTML string, or-1if not set.- Returns:
- the tag end position, or
-1
-
setTagEnd
public void setTagEnd(int tagEnd) Sets the position immediately after the closing>character in the original HTML string.- Parameters:
tagEnd- the tag end position
-
getStyleAttrStart
public int getStyleAttrStart()Returns the position of thestyle="substring in the original HTML string, or-1if not set.- Returns:
- the style attribute start position, or
-1
-
setStyleAttrStart
public void setStyleAttrStart(int styleAttrStart) Sets the position of thestyle="substring in the original HTML string.- Parameters:
styleAttrStart- the style attribute start position
-
getStyleAttrEnd
public int getStyleAttrEnd()Returns the position immediately after the closing quote of thestyleattribute in the original HTML string, or-1if not set.- Returns:
- the style attribute end position, or
-1
-
setStyleAttrEnd
public void setStyleAttrEnd(int styleAttrEnd) Sets the position immediately after the closing quote of thestyleattribute in the original HTML string.- Parameters:
styleAttrEnd- the style attribute end position
-
hasPositionInfo
public boolean hasPositionInfo()Whether this element has position information for in-place style modification.- Returns:
trueif both tag start and tag end positions are set
-
toString
-