Class Text
- java.lang.Object
-
- com.atlassian.adf.model.node.AbstractNode<N>
-
- com.atlassian.adf.model.node.AbstractMarkedNode<Text,TextMark>
-
- com.atlassian.adf.model.node.Text
-
- All Implemented Interfaces:
Element,Node,CaptionContent,InlineContent,Marked<Text,TextMark>
@Documentation(state=INCOMPLETE, date="2023-07-26", comment="documentation around marks is unclear and omits the \'annotation\' mark") public class Text extends AbstractMarkedNode<Text,TextMark> implements CaptionContent, InlineContent
Holds document text. The HTML equivalent is any bare text to be displayed, such as would be found inside aparagraph. Except where otherwise noted, text nodes can be augmented with any of themarkelements to enhance how they are displayed.Empty text nodes are not permitted; the non-empty text value must be provided.
Example
Java
p(text("Hello world"))ADF
{ "type": "paragraph", "content": [ { "type": "text", "text": "Hello world" } ] }Result
Hello world
- See Also:
- Node - text
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.atlassian.adf.model.node.AbstractNode
AbstractNode.ToStringHelper
-
-
Field Summary
-
Fields inherited from class com.atlassian.adf.model.node.AbstractMarkedNode
marks
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Textappend(String text)protected voidappendMarkedNodeFields(AbstractNode.ToStringHelper buf)voidappendPlainText(StringBuilder sb)Renders this node as plain-text suitable for viewing by end users.Textcode()Add aCodemark to this text.Textcopy()Returns a deep copy of this element, including copies of any nodes or marks that it contains.StringelementType()Thetypevalue that identifies this element, such as"paragraph"or"strong".Textem()Add anEmmark to this text.booleanhasSameMarks(Text other)Textlink(String url)Add aLinkmark to this text using the given target URL.Textlink(URL url)Add aLinkmark to this text using the given target URL.Textlowercase()This converts the text string to lowercase usingLocale#ROOTsemantics.Textmark(TextMark mark)Adds the given mark to this marked node.Class<TextMark>markClass()Returns the type of marks that may be applied to this node.protected booleanmarkedNodeEquals(Text other)protected intmarkedNodeHashCode()booleanmarkIfAllowed(TextMark mark)Adds the given mark to the node if it is permitted.Textset(String text)Textstrike()Add aStrikemark to this text.Textstrong()Add aStrongmark to this text.Textsub()Add asubmark to this text.Textsup()Add asupmark to this text.Stringtext()Returns the text that is contained within this text node; nevernullor empty.static Stream<Text>text(Iterable<? extends String> text)Create a stream of text nodes for the given input strings without any marks.static Texttext(String text)Create a new text node for the given input string without any marks.static Stream<Text>text(String... text)Create a stream of text nodes for the given input strings without any marks.static Texttext(String text, TextMark... marks)Create a new text node that also has the specified marks.static Texttext(String text, Iterable<? extends TextMark> marks)static Texttext(String text, Stream<? extends TextMark> marks)static Stream<Text>text(Stream<? extends String> text)Create a stream of text nodes for the given input strings without any marks.TexttextColor(Colors.Named color)Add aTextColormark to this text.TexttextColor(Color color)Add aTextColormark to this text.TexttextColor(String color)Add aTextColormark to this text.Map<String,?>toMap()Transforms this element to a map ofStringvalues to various basic object types suitable for direct rendering as JSON content.Textunderline()Add anUnderlinemark to this text.protected Factory<TextMark>unsupportedMarkFactory()Textuppercase()This converts the text string to uppercase usingLocale#ROOTsemantics.protected StringvalidateText(String text)-
Methods inherited from class com.atlassian.adf.model.node.AbstractMarkedNode
appendNodeFields, createMarkHolder, mark, markedNodeValidate, marks, marks, markTypes, nodeEquals, nodeHashCode, parseMarks, validate
-
Methods inherited from class com.atlassian.adf.model.node.AbstractNode
doubleEq, doubleHash, equals, hashCode, isSupported, mapWithType, numberEq, numberHash, self, toPlainText, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.atlassian.adf.model.Element
isSupported, validate
-
Methods inherited from interface com.atlassian.adf.model.node.Node
toPlainText
-
-
-
-
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 marksare 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 marksare 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 marksare 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 marksare not compatible
-
text
public static Text text(String text, Iterable<? extends TextMark> marks)
- See Also:
text(String, TextMark[])
-
text
public static Text text(String text, Stream<? extends TextMark> marks)
- See Also:
text(String, TextMark[])
-
copy
public Text copy()
Description copied from interface:ElementReturns 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, atextnode that is used inside acodeBlockwill 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 thisif the element is immutable. The@Immutableannotation 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
parseandtoMapmethods already have to be updated in these circumstances, so it makes sense to take advantage of that.
-
uppercase
public Text uppercase()
This converts the text string to uppercase usingLocale#ROOTsemantics. Note that this will not be correct for all locales, most notably Turkish, where it will incorrectly mapitoIwhen 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 usingLocale#ROOTsemantics. Note that this will not be correct for all locales, most notably Turkish, where it will incorrectly mapItoiwhen 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; nevernullor empty.- Returns:
- the text that is contained within this text node; never
nullor empty.
-
hasSameMarks
public boolean hasSameMarks(Text other)
-
markClass
public Class<TextMark> markClass()
Description copied from interface:MarkedReturns the type of marks that may be applied to this node.
-
mark
public Text mark(TextMark mark)
Description copied from interface:MarkedAdds the given mark to this marked node.
-
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:
- A mark of that type is already present.
- It would result in a
CodeTextMarkand aFormattedTextMarkon the same node. - 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:
trueif the mark was successfully added;falseif the mark was disallowed
-
link
public Text link(String url)
Add aLinkmark 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
Linkclass directly and add it withmark(TextMark)if these are needed.- Parameters:
url- the target URL to be used as thehrefattribute for this link- Returns:
this
-
link
public Text link(URL url)
Add aLinkmark 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
Linkclass directly and add it withmark(TextMark)if these are needed.- Parameters:
url- the target URL to be used as thehrefattribute for this link- Returns:
this
-
textColor
public Text textColor(String color)
Add aTextColormark to this text.- Parameters:
color- a color defined in HTML hexadecimal format, such as#daa520.- Returns:
this
-
textColor
public Text textColor(Color color)
Add aTextColormark to this text.- Parameters:
color- a color- Returns:
this
-
textColor
public Text textColor(Colors.Named color)
Add aTextColormark to this text.- Parameters:
color- one of the standardnamed colors- Returns:
this
-
elementType
public String elementType()
Description copied from interface:ElementThetypevalue that identifies this element, such as"paragraph"or"strong".- Specified by:
elementTypein interfaceElement
-
toMap
public Map<String,?> toMap()
Description copied from interface:ElementTransforms this element to a map ofStringvalues to various basic object types suitable for direct rendering as JSON content.
-
markedNodeEquals
protected boolean markedNodeEquals(Text other)
- Overrides:
markedNodeEqualsin classAbstractMarkedNode<Text,TextMark>
-
markedNodeHashCode
protected int markedNodeHashCode()
- Overrides:
markedNodeHashCodein classAbstractMarkedNode<Text,TextMark>
-
appendMarkedNodeFields
protected void appendMarkedNodeFields(AbstractNode.ToStringHelper buf)
- Overrides:
appendMarkedNodeFieldsin classAbstractMarkedNode<Text,TextMark>
-
unsupportedMarkFactory
@Nullable protected Factory<TextMark> unsupportedMarkFactory()
- Overrides:
unsupportedMarkFactoryin classAbstractMarkedNode<Text,TextMark>
-
appendPlainText
public void appendPlainText(StringBuilder sb)
Description copied from interface:NodeRenders this node as plain-text suitable for viewing by end users. This is equivalent to callingNode.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:
appendPlainTextin interfaceNode- Overrides:
appendPlainTextin classAbstractNode<Text>- Parameters:
sb- where to write the result
-
-