Class Mention
- java.lang.Object
-
- com.atlassian.adf.model.node.AbstractNode<Mention>
-
- com.atlassian.adf.model.node.Mention
-
- All Implemented Interfaces:
Element,Node,CaptionContent,InlineContent
@Documentation(state=WRONG, date="2023-07-26", comment="the \'accessLevel\' attribute is not restricted and an empty string is often used for it") public class Mention extends AbstractNode<Mention> implements CaptionContent, InlineContent
Represents a user mention.Implementation Note
Although the documentation implies that only the enumeratedMention.AccessLevelvalues should be used for that attribute, the reality is that this was never enforced by the schema, and the editor itself frequently specifies it as an empty string.Example
Java
mention("ABCDE-ABCDE-ABCDE-ABCDE") .text("@jsmith") .userType(APP);ADF
{ "type": "mention", "attrs": { "id": "ABCDE-ABCDE-ABCDE-ABCDE", "text": "@jsmith", "userType": "APP" } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMention.AccessLevelThe well-knownaccessLevelenumerated values that were originally documented for mention nodes.static classMention.UserType-
Nested classes/interfaces inherited from class com.atlassian.adf.model.node.AbstractNode
AbstractNode.ToStringHelper
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<String>accessLevel()Returns the access level for this mention, if set.MentionaccessLevel(Mention.AccessLevel accessLevel)Sets the access level value for the mention.MentionaccessLevel(String accessLevel)Sets the access level value for the mention.protected voidappendNodeFields(AbstractNode.ToStringHelper buf)Allows nodes that have their own fields to augment thetoString()implementation with their own field values.voidappendPlainText(StringBuilder sb)Renders this node as plain-text suitable for viewing by end users.Mentioncopy()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".Stringid()Returns the ID of the mention's target.Mentionid(String id)static Mentionmention(String id)Create a new mention using the given Atlassian Account ID or collection name.protected booleannodeEquals(Mention other)Allows nodes that have their own fields to augment theequalsimplementation with tests for their own field values.protected intnodeHashCode()Allows nodes that have their own fields to augment thehashCodeimplementation with a hash of their own field values.Optional<String>text()Returns the display text for this mention, if set.Mentiontext(String text)Sets the text value for the mention.Map<String,?>toMap()Transforms this element to a map ofStringvalues to various basic object types suitable for direct rendering as JSON content.Optional<Mention.UserType>userType()Returns the user type for this mention, if set.MentionuserType(Mention.UserType userType)Sets the user type value for the mention.MentionuserType(String userType)Sets the user type value for the mention.voidvalidate()Verifies that the node is well-formed (including the state of any descendents that it has).-
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
-
Methods inherited from interface com.atlassian.adf.model.node.Node
toPlainText
-
-
-
-
Method Detail
-
mention
public static Mention mention(String id)
Create a new mention using the given Atlassian Account ID or collection name.- Parameters:
id- the Atlassian Account ID or collection name- Returns:
- the new mention node
-
id
public String id()
Returns the ID of the mention's target.- Returns:
- the ID of the mention's target.
-
accessLevel
public Optional<String> accessLevel()
Returns the access level for this mention, if set.- Returns:
- the access level for this mention, or
empty()if not set.
-
accessLevel
public Mention accessLevel(@Nullable String accessLevel)
Sets the access level value for the mention.- Returns:
this
-
accessLevel
public Mention accessLevel(@Nullable Mention.AccessLevel accessLevel)
Sets the access level value for the mention.- Returns:
this
-
userType
public Optional<Mention.UserType> userType()
Returns the user type for this mention, if set.- Returns:
- the user type for this mention, or
empty()if not set.
-
userType
public Mention userType(@Nullable String userType)
Sets the user type value for the mention.- Returns:
this
-
userType
public Mention userType(@Nullable Mention.UserType userType)
Sets the user type value for the mention.- Returns:
this
-
text
public Optional<String> text()
Returns the display text for this mention, if set.- Returns:
- the display text for this mention, or
empty()if not set.
-
text
public Mention text(@Nullable String text)
Sets the text value for the mention.
NB: As a temporary change (to replicate the behaviour of the TypeScript transformer) until theOMIT_EMPTY_ATTRIBUTESparser feature flag is enabled: iftextis an empty string, it will be treated astext(i.e. "").
Once the feature flag is enabled, we will return to the original behaviour: iftextis an empty string, it will be treated asnull.
If it isn't empty but also does not begin with@, then the value will be prefixed with it automatically.- Parameters:
text- the text that is displayed for the mention, which must begin with an@char.- Returns:
this
-
nodeEquals
protected boolean nodeEquals(Mention other)
Description copied from class:AbstractNodeAllows nodes that have their own fields to augment theequalsimplementation with tests for their own field values.Implementations need not check for identity,
null, or a different node class; those are already covered by theAbstractNode.equals(Object)implementation that is expected to be this method's only consumer.Just as with the relationship between
hashCode,equals, andtoStringfor ordinary Java classes, subclasses ofAbstractNodeshould maintain consistent implementations ofnodeHashCode,nodeEquals, andappendNodeFields.- Overrides:
nodeEqualsin classAbstractNode<Mention>- Returns:
trueif all additional field values that belong to a particular type of content node test as equal;falseif differences are found- See Also:
AbstractNode.nodeHashCode(),AbstractNode.appendNodeFields(ToStringHelper)
-
nodeHashCode
protected int nodeHashCode()
Description copied from class:AbstractNodeAllows nodes that have their own fields to augment thehashCodeimplementation with a hash of their own field values.Implementations need not include the node's class; that is already covered by the
AbstractNode.hashCode()implementation that is expected to be this method's only consumer.Just as with the relationship between
hashCode,equals, andtoStringfor ordinary Java classes, subclasses ofAbstractNodeshould maintain consistent implementations ofnodeHashCode,nodeEquals, andappendNodeFields.- Overrides:
nodeHashCodein classAbstractNode<Mention>- Returns:
- the hash code of any additional field values that belong to a particular type of content node.
- See Also:
AbstractNode.nodeEquals(AbstractNode),AbstractNode.appendNodeFields(ToStringHelper)
-
appendNodeFields
protected void appendNodeFields(AbstractNode.ToStringHelper buf)
Description copied from class:AbstractNodeAllows nodes that have their own fields to augment thetoString()implementation with their own field values.Each field's value should be provided by calling
AbstractNode.ToStringHelper.appendField(String, Object). Thevaluemay benull, in which case the field is omitted, for brevity. It will handle array values gracefully, including arrays of primitive types.Just as with the relationship between
hashCode,equals, andtoStringfor ordinary Java classes, subclasses ofAbstractNodeshould maintain consistent implementations ofnodeHashCode,nodeEquals, andappendNodeFields.- Overrides:
appendNodeFieldsin classAbstractNode<Mention>- Parameters:
buf- where the field values should be written- See Also:
AbstractNode.nodeHashCode(),AbstractNode.nodeEquals(AbstractNode)
-
copy
public Mention 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.
-
elementType
public String elementType()
Description copied from interface:ElementThetypevalue that identifies this element, such as"paragraph"or"strong".- Specified by:
elementTypein interfaceElement
-
validate
public void validate()
Description copied from interface:ElementVerifies that the node is well-formed (including the state of any descendents that it has).
-
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.
-
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<Mention>- Parameters:
sb- where to write the result
-
-