Class HtmlNode

java.lang.Object
guideme.web.html.HtmlNode
Direct Known Subclasses:
HtmlTag, HtmlText

public abstract sealed class HtmlNode extends Object permits HtmlTag, HtmlText
A node in a minimal HTML DOM, used to generate the pages of the website. Use the static factory methods to create nodes.
  • Constructor Details

    • HtmlNode

      public HtmlNode()
  • Method Details

    • name

      public abstract String name()
      Returns the name of the HTML tag or an empty string for text nodes.
      Returns:
      the name of the HTML tag or an empty string for text nodes
    • attribute

      public abstract @Nullable String attribute(String name)
      Returns the value of the attribute, or null if it isn't set or has no value.
      Returns:
      the value of the attribute, or null if it isn't set or has no value
    • hasAttribute

      public final boolean hasAttribute(String name)
    • setAttribute

      public abstract HtmlTag setAttribute(String name, String value)
      Sets an attribute. A null value writes the attribute without a value (i.e. <details open>).
      Throws:
      UnsupportedOperationException - For text nodes.
    • setAttribute

      public final HtmlTag setAttribute(String name, float value)
    • setAttribute

      public final HtmlTag setAttribute(String name, int value)
    • tag

      public static HtmlTag tag(String name)
      Creates an element.
      Throws:
      IllegalArgumentException - If the name is not a valid tag name.
    • tag

      public static HtmlTag tag(String name, HtmlFragment fragment)
    • tag

      public static HtmlTag tag(String name, HtmlNode... children)
    • tag

      public static HtmlTag tag(String name, List<? extends HtmlNode> children)
    • text

      public static HtmlText text(String content)
      Creates a text node, whose content is escaped when written.
    • children

      public abstract List<HtmlNode> children()
    • escapeHtml

      public static String escapeHtml(String text)
      Escapes text for use in element content. Null becomes an empty string.
    • escapeAttribute

      public static String escapeAttribute(String text)
      Escapes text for use in a quoted attribute value. Null becomes an empty string.
    • textContent

      public abstract String textContent()
      Returns the text of this node and its descendants, without markup.
      Returns:
      the text of this node and its descendants, without markup
    • outerHtml

      public abstract String outerHtml()
      Returns the HTML of this node and its descendants.
      Returns:
      the HTML of this node and its descendants