public class Message extends ExtensibleStanza
The implementation of the <message/>
element.
This class is thread-safe.Once a client has authenticated with a server and bound a resource to an XML stream as described in [XMPP-CORE], an XMPP server will route XML stanzas to and from that client. One kind of stanza that can be exchanged is
<message/>
(if, that is, messaging functionality is enabled on the server). Exchanging messages is a basic use of XMPP and occurs when a user generates a message stanza that is addressed to another entity. As defined under Section 8, the sender’s server is responsible for delivering the message to the intended recipient (if the recipient is on the same local server) or for routing the message to the recipient’s server (if the recipient is on a remote server). Thus a message stanza is used to “push” information to another entity.
Modifier and Type | Class and Description |
---|---|
static class |
Message.Type
Represents a
<message/> ‘type’ attribute. |
Constructor and Description |
---|
Message() |
Message(Jid to)
Constructs an empty message.
|
Message(Jid to,
Message.Type type)
Constructs a message with a type.
|
Message(Jid to,
Message.Type type,
java.util.Collection<Text> bodies,
java.util.Collection<Text> subjects,
java.lang.String thread,
java.lang.String parentThread,
java.lang.String id,
Jid from,
java.util.Locale language,
java.util.Collection<?> extensions,
StanzaError error)
Constructs a message with all possible values.
|
Message(Jid to,
Message.Type type,
java.lang.String body)
Constructs a message with body and type.
|
Message(Jid to,
Message.Type type,
java.lang.String body,
java.lang.String subject)
Constructs a message with body and type.
|
Message(Jid to,
Message.Type type,
java.lang.String body,
java.lang.String subject,
java.lang.String thread)
Constructs a message with body and type.
|
Message(Jid to,
Message.Type type,
java.lang.String body,
java.lang.String subject,
java.lang.String thread,
java.lang.String parentThread,
java.lang.String id,
Jid from,
java.util.Locale language,
java.util.Collection<?> extensions,
StanzaError error)
Constructs a message with body and type.
|
Modifier and Type | Method and Description |
---|---|
Message |
createError(Condition condition)
Creates an error response for this stanza.
|
Message |
createError(StanzaError error)
Creates an error response for this stanza.
|
java.util.List<Text> |
getBodies()
Gets the bodies.
|
java.lang.String |
getBody()
Gets the default body (which has no language attribute).
|
java.lang.String |
getParentThread()
Gets the parent thread.
|
java.lang.String |
getSubject()
Gets the default subject (which has no language attribute).
|
java.util.List<Text> |
getSubjects()
Gets the subjects.
|
java.lang.String |
getThread()
Gets the thread.
|
Message.Type |
getType()
Gets the message type.
|
boolean |
isNormal()
Indicates, whether this message is a normal message, i.e. if the type or the message is either
Message.Type.NORMAL , null or otherwise unknown, this method returns true. |
void |
setBody(java.lang.String body)
Sets the default body element.
|
void |
setParentThread(java.lang.String parent)
Sets the parent thread.
|
void |
setSubject(java.lang.String subject)
Sets the default subject.
|
void |
setThread(java.lang.String thread)
Sets the thread.
|
void |
setType(Message.Type type)
Sets the message type.
|
java.lang.String |
toString() |
addExtension, addExtensions, addExtensions, getExtensions, getExtensions, putExtension, removeExtension
getError, getExtension, getFrom, getId, getLanguage, getTo, hasExtension, isToItselfOrServer, setError, setFrom, setId, setLanguage, setTo
public Message()
public Message(Jid to)
Constructs an empty message.
to
- The recipient.public Message(Jid to, Message.Type type)
Constructs a message with a type.
to
- The recipient.type
- The message type.public Message(Jid to, Message.Type type, java.lang.String body)
Constructs a message with body and type.
to
- The recipient.body
- The message body.type
- The message type.public Message(Jid to, Message.Type type, java.lang.String body, java.lang.String subject)
Constructs a message with body and type.
to
- The recipient.body
- The message body.type
- The message type.subject
- The subject.public Message(Jid to, Message.Type type, java.lang.String body, java.lang.String subject, java.lang.String thread)
Constructs a message with body and type.
to
- The recipient.body
- The message body.type
- The message type.subject
- The subject.thread
- The thread.public Message(Jid to, Message.Type type, java.lang.String body, java.lang.String subject, java.lang.String thread, java.lang.String parentThread, java.lang.String id, Jid from, java.util.Locale language, java.util.Collection<?> extensions, StanzaError error)
Constructs a message with body and type.
to
- The recipient.body
- The message body.type
- The message type.subject
- The subject.thread
- The thread.parentThread
- The parent thread.from
- The sender.id
- The id.language
- The language.extensions
- The extensions.error
- The error.public Message(Jid to, Message.Type type, java.util.Collection<Text> bodies, java.util.Collection<Text> subjects, java.lang.String thread, java.lang.String parentThread, java.lang.String id, Jid from, java.util.Locale language, java.util.Collection<?> extensions, StanzaError error)
Constructs a message with all possible values.
to
- The recipient.bodies
- The message bodies.type
- The message type.subjects
- The subjects.thread
- The thread.parentThread
- The parent thread.from
- The sender.id
- The id.language
- The language.extensions
- The extensions.error
- The error.public final java.util.List<Text> getBodies()
Gets the bodies.
The
<body/>
element contains human-readable XML character data that specifies the textual contents of the message; this child element is normally included but is OPTIONAL.There are no attributes defined for the
<body/>
element, with the exception of the ‘xml:lang’ attribute. Multiple instances of the<body/>
element MAY be included in a message stanza for the purpose of providing alternate versions of the same body, but only if each instance possesses an ‘xml:lang’ attribute with a distinct language value.
getBody()
public final java.lang.String getBody()
Gets the default body (which has no language attribute).
If there’s no default body, but only bodies with a language attribute, the first body is returned.The
<body/>
element contains human-readable XML character data that specifies the textual contents of the message; this child element is normally included but is OPTIONAL.
If there are no bodies at all, null is returned.
getBodies()
public final void setBody(java.lang.String body)
Sets the default body element.
body
- The body text.getBody()
public final java.util.List<Text> getSubjects()
Gets the subjects.
The
<subject/>
element contains human-readable XML character data that specifies the topic of the message.There are no attributes defined for the
<subject/>
element, with the exception of the ‘xml:lang’ attribute inherited from [XML]. Multiple instances of the<subject/>
element MAY be included for the purpose of providing alternate versions of the same subject, but only if each instance possesses an ‘xml:lang’ attribute with a distinct language value.
getSubject()
public final java.lang.String getSubject()
Gets the default subject (which has no language attribute).
The
<subject/>
element contains human-readable XML character data that specifies the topic of the message.
If there’s no default subject, but only subjects with a language attribute, the first subject is returned.
If there are no subjects at all, null is returned.
getSubjects()
public final void setSubject(java.lang.String subject)
Sets the default subject.
subject
- The subject text.getSubject()
public final Message.Type getType()
Gets the message type. This may also return null. If you want to check for a ‘normal’ message, you should prefer isNormal()
.
Common uses of the message stanza in instant messaging applications include: single messages; messages sent in the context of a one-to-one chat session; messages sent in the context of a multi-user chat room; alerts, notifications, or other information to which no reply is expected; and errors. These uses are differentiated via the ‘type’ attribute.
isNormal()
public final void setType(Message.Type type)
Sets the message type.
type
- The message type.getType()
public final boolean isNormal()
Indicates, whether this message is a normal message, i.e. if the type or the message is either Message.Type.NORMAL
, null or otherwise unknown, this method returns true.
If an application receives a message with no ‘type’ attribute or the application does not understand the value of the ‘type’ attribute provided, it MUST consider the message to be of type “normal” (i.e., “normal” is the default).
getType()
public final java.lang.String getThread()
Gets the thread.
The primary use of the XMPP
<thread/>
element is to uniquely identify a conversation thread or “chat session” between two entities instantiated by<message/>
stanzas of type ‘chat’. However, the XMPP<thread/>
element MAY also be used to uniquely identify an analogous thread between two entities instantiated by<message/>
stanzas of type ‘headline’ or ‘normal’, or among multiple entities in the context of a multi-user chat room instantiated by<message/>
stanzas of type ‘groupchat’. It MAY also be used for<message/>
stanzas not related to a human conversation, such as a game session or an interaction between plugins. The<thread/>
element is not used to identify individual messages, only conversations or messaging sessions.
public final void setThread(java.lang.String thread)
Sets the thread.
thread
- The thread.getThread()
public final java.lang.String getParentThread()
Gets the parent thread.
The
<thread/>
element MAY possess a ‘parent’ attribute that identifies another thread of which the current thread is an offshoot or child. The ‘parent’ attribute MUST conform to the syntax of the<thread/>
element itself and its value MUST be different from the XML character data of the<thread/>
element on which the ‘parent’ attribute is included.
public final void setParentThread(java.lang.String parent)
Sets the parent thread.
parent
- The parent thread.getParentThread()
public final Message createError(StanzaError error)
Stanza
Creates an error response for this stanza.
createError
in class Stanza
error
- The error which is appended to the stanza.Stanza.getError()
public final Message createError(Condition condition)
Stanza
Creates an error response for this stanza.
createError
in class Stanza
condition
- The error condition which is appended to the stanza.Stanza.getError()
Copyright © 2014–2019 XMPP.rocks. All rights reserved.