Class Text

    • Method Detail

      • text

        public static Text text​(String text)
        Create a new text node for the given input string without any marks.
        Parameters:
        text - the text that the node contains; must not be empty
        Returns:
        the new text node
        Throws:
        IllegalArgumentException - if the text value is empty
      • text

        public static Stream<Text> text​(String... text)
        Create a stream of text nodes for the given input strings without any marks.
        Parameters:
        text - the text values that the nodes will contain; none of them can be empty
        Returns:
        the stream of new text nodes
        Throws:
        IllegalArgumentException - if any text value is empty or if the specified marks are not compatible
      • text

        public static Stream<Text> text​(Iterable<? extends String> text)
        Create a stream of text nodes for the given input strings without any marks.
        Parameters:
        text - the text values that the nodes will contain; none of them can be empty
        Returns:
        the stream of new text nodes
        Throws:
        IllegalArgumentException - if any text value is empty or if the specified marks are not compatible
      • text

        public static Stream<Text> text​(Stream<? extends String> text)
        Create a stream of text nodes for the given input strings without any marks.
        Parameters:
        text - the text values that the nodes will contain; none of them can be empty
        Returns:
        the stream of new text nodes
        Throws:
        IllegalArgumentException - if any text value is empty or if the specified marks are not compatible
      • text

        public static Text text​(String text,
                                TextMark... marks)
        Create a new text node that also has the specified marks.
        Parameters:
        text - the text that the node contains; must not be empty
        Returns:
        the new text node
        Throws:
        IllegalArgumentException - if any text value is empty or if the specified marks are not compatible
      • copy

        public Text copy()
        Description copied from interface: Element
        Returns a deep copy of this element, including copies of any nodes or marks that it contains. The copy will not necessarily be in exactly the same state as the original in some cases. For example, a text node that is used inside a codeBlock will have the ability to use marks on it disabled, but a copy made of the text node using this method will not similarly disallow marks unless it is also added to a content node with those same restrictions.

        Implementations notes:

        • Implementations should narrow the return type.
        • Implementations should return this if the element is immutable. The @Immutable annotation should be used on the class to offer additional confirmation of this intent.
        • Implementations should return parse(toMap()) if they have state.
        • While there may be cases where it is worthwhile to do something more efficient than the conversion to a map and back, this is discouraged because it would add yet another fragile piece of code that breaks when new data is added to the node. The parse and toMap methods already have to be updated in these circumstances, so it makes sense to take advantage of that.
        Specified by:
        copy in interface Element
        Specified by:
        copy in interface Marked<Text,​TextMark>
        Specified by:
        copy in interface Node
        Specified by:
        copy in class AbstractMarkedNode<Text,​TextMark>
        Returns:
        a copy of this element, or this if the element is immutable anyway
      • uppercase

        public Text uppercase()
        This converts the text string to uppercase using Locale#ROOT semantics. Note that this will not be correct for all locales, most notably Turkish, where it will incorrectly map i to I when it should be İ (U+0130; LATIN CAPITAL LETTER I WITH DOT ABOVE).
        Returns:
        this
      • lowercase

        public Text lowercase()
        This converts the text string to lowercase using Locale#ROOT semantics. Note that this will not be correct for all locales, most notably Turkish, where it will incorrectly map I to i when it should be ı (U+0131; LATIN SMALL LETTER DOTLESS I).
        Returns:
        this
      • text

        public String text()
        Returns the text that is contained within this text node; never null or empty.
        Returns:
        the text that is contained within this text node; never null or empty.
      • hasSameMarks

        public boolean hasSameMarks​(Text other)
      • markIfAllowed

        public boolean markIfAllowed​(TextMark mark)
        Adds the given mark to the node if it is permitted.

        This is intended for cases where the caller would like to apply a mark, but does not consider it an error if that mark is not allowed and does not want to have to catch an exception for it. A common example might be an attempt to mark text as strong(), but not wanting to check first whether this will be permitted or handle the exception if it is not.

        Some reasons why the mark might be disallowed include:

        1. A mark of that type is already present.
        2. It would result in a CodeTextMark and a FormattedTextMark on the same node.
        3. The text node is already the child of another node type (such as codeBlock) that only accepts unmarked text nodes as children.
        Parameters:
        mark - the mark to add to the text node, provided it is compatible with the parent node and any other marks that it already has
        Returns:
        true if the mark was successfully added; false if the mark was disallowed
      • code

        public Text code()
        Add a Code mark to this text.
        Returns:
        this
      • em

        public Text em()
        Add an Em mark to this text.
        Returns:
        this
      • link

        public Text link​(String url)
        Add a Link mark to this text using the given target URL.

        This convenience method doesn't support setting any of the optional attributes for a link. Construct one manually using the Link class directly and add it with mark(TextMark) if these are needed.

        Parameters:
        url - the target URL to be used as the href attribute for this link
        Returns:
        this
      • link

        public Text link​(URL url)
        Add a Link mark to this text using the given target URL.

        This convenience method doesn't support setting any of the optional attributes for a link. Construct one manually using the Link class directly and add it with mark(TextMark) if these are needed.

        Parameters:
        url - the target URL to be used as the href attribute for this link
        Returns:
        this
      • strike

        public Text strike()
        Add a Strike mark to this text.
        Returns:
        this
      • strong

        public Text strong()
        Add a Strong mark to this text.
        Returns:
        this
      • sub

        public Text sub()
        Add a sub mark to this text.
        Returns:
        this
      • sup

        public Text sup()
        Add a sup mark to this text.
        Returns:
        this
      • textColor

        public Text textColor​(String color)
        Add a TextColor mark to this text.
        Parameters:
        color - a color defined in HTML hexadecimal format, such as #daa520.
        Returns:
        this
      • textColor

        public Text textColor​(Color color)
        Add a TextColor mark to this text.
        Parameters:
        color - a color
        Returns:
        this
      • underline

        public Text underline()
        Add an Underline mark to this text.
        Returns:
        this
      • elementType

        public String elementType()
        Description copied from interface: Element
        The type value that identifies this element, such as "paragraph" or "strong".
        Specified by:
        elementType in interface Element
      • toMap

        public Map<String,​?> toMap()
        Description copied from interface: Element
        Transforms this element to a map of String values to various basic object types suitable for direct rendering as JSON content.
        Specified by:
        toMap in interface Element
        Returns:
        the map representation of this ADF element
      • validateText

        protected String validateText​(String text)
      • appendPlainText

        public void appendPlainText​(StringBuilder sb)
        Description copied from interface: Node
        Renders this node as plain-text suitable for viewing by end users. This is equivalent to calling Node.toPlainText() and appending the result to the given buffer, except that it may be slightly more efficient, since it will write directly to the existing buffer instead of using a temporary buffer and having to make a copy of the result.
        Specified by:
        appendPlainText in interface Node
        Overrides:
        appendPlainText in class AbstractNode<Text>
        Parameters:
        sb - where to write the result