Class TextNode

  • All Implemented Interfaces:
    java.lang.Cloneable
    Direct Known Subclasses:
    CDataNode

    public class TextNode
    extends LeafNode
    A text node.
    • Constructor Detail

      • TextNode

        public TextNode​(java.lang.String text)
        Create a new TextNode representing the supplied (unencoded) text).
        Parameters:
        text - raw text
        See Also:
        createFromEncoded(String)
    • Method Detail

      • nodeName

        public java.lang.String nodeName()
        Description copied from class: Node
        Get the node name of this node. Use for debugging purposes and not logic switching (for that, use instanceof).
        Specified by:
        nodeName in class Node
        Returns:
        node name
      • text

        public java.lang.String text()
        Get the text content of this text node.
        Returns:
        Unencoded, normalised text.
        See Also:
        getWholeText()
      • text

        public TextNode text​(java.lang.String text)
        Set the text content of this text node.
        Parameters:
        text - unencoded text
        Returns:
        this, for chaining
      • getWholeText

        public java.lang.String getWholeText()
        Get the (unencoded) text of this text node, including any newlines and spaces present in the original.
        Returns:
        text
      • isBlank

        public boolean isBlank()
        Test if this text node is blank -- that is, empty or only whitespace (including newlines).
        Returns:
        true if this document is empty or only whitespace, false if it contains any text content.
      • splitText

        public TextNode splitText​(int offset)
        Split this text node into two nodes at the specified string offset. After splitting, this node will contain the original text up to the offset, and will have a new text node sibling containing the text after the offset.
        Parameters:
        offset - string offset point to split node at.
        Returns:
        the newly created text node containing the text after the offset.
      • outerHtmlHead

        void outerHtmlHead​(java.lang.Appendable accum,
                           int depth,
                           Document.OutputSettings out)
                    throws java.io.IOException
        Description copied from class: Node
        Get the outer HTML of this node.
        Specified by:
        outerHtmlHead in class Node
        Parameters:
        accum - accumulator to place HTML into
        Throws:
        java.io.IOException - if appending to the given accumulator fails.
      • outerHtmlTail

        void outerHtmlTail​(java.lang.Appendable accum,
                           int depth,
                           Document.OutputSettings out)
                    throws java.io.IOException
        Specified by:
        outerHtmlTail in class Node
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Description copied from class: Node
        Gets this node's outer HTML.
        Overrides:
        toString in class Node
        Returns:
        outer HTML.
        See Also:
        Node.outerHtml()
      • clone

        public TextNode clone()
        Description copied from class: Node
        Create a stand-alone, deep copy of this node, and all of its children. The cloned node will have no siblings or parent node. As a stand-alone object, any changes made to the clone or any of its children will not impact the original node.

        The cloned node may be adopted into another Document or node structure using Element.appendChild(Node).

        Overrides:
        clone in class Node
        Returns:
        a stand-alone cloned node, including clones of any children
        See Also:
        Node.shallowClone()
      • createFromEncoded

        public static TextNode createFromEncoded​(java.lang.String encodedText)
        Create a new TextNode from HTML encoded (aka escaped) data.
        Parameters:
        encodedText - Text containing encoded HTML (e.g. <)
        Returns:
        TextNode containing unencoded data (e.g. <)
      • normaliseWhitespace

        static java.lang.String normaliseWhitespace​(java.lang.String text)
      • stripLeadingWhitespace

        static java.lang.String stripLeadingWhitespace​(java.lang.String text)
      • lastCharIsWhitespace

        static boolean lastCharIsWhitespace​(java.lang.StringBuilder sb)