public final class Message extends Stanza implements TypedCloneable<Message>
Message type | |||||
Field | Normal | Chat | Group Chat | Headline | XMPPError |
subject | SHOULD | SHOULD NOT | SHOULD NOT | SHOULD NOT | SHOULD NOT |
thread | OPTIONAL | SHOULD | OPTIONAL | OPTIONAL | SHOULD NOT |
body | SHOULD | SHOULD | SHOULD | SHOULD | SHOULD NOT |
error | MUST NOT | MUST NOT | MUST NOT | MUST NOT | MUST |
Modifier and Type | Class and Description |
---|---|
static class |
Message.Body
Represents a message body, its language and the content of the message.
|
static class |
Message.Subject
Represents a message subject, its language and the content of the subject.
|
static class |
Message.Type
Represents the type of a message.
|
Modifier and Type | Field and Description |
---|---|
static String |
BODY |
static String |
ELEMENT |
DEFAULT_LANGUAGE, ITEM, language, TEXT
Constructor and Description |
---|
Message()
Creates a new, "normal" message.
|
Message(Jid to)
Creates a new "normal" message to the specified recipient.
|
Message(Jid to,
ExtensionElement extensionElement)
Creates a new message with the specified recipient and extension element.
|
Message(Jid to,
Message.Type type)
Creates a new message of the specified type to a recipient.
|
Message(Jid to,
String body)
Creates a new message to the specified recipient and with the specified body.
|
Message(Message other)
Copy constructor.
|
Message(String to,
String body)
Creates a new message to the specified recipient and with the specified body.
|
Modifier and Type | Method and Description |
---|---|
Message.Body |
addBody(String language,
String body)
Adds a body with a corresponding language.
|
Message.Subject |
addSubject(String language,
String subject)
Adds a subject with a corresponding language.
|
Message |
clone()
Creates and returns a copy of this message stanza.
|
Set<Message.Body> |
getBodies()
Returns a set of all bodies in this Message, including the default message body accessible
from
getBody() . |
String |
getBody()
Returns the default body of the message, or null if the body has not been set.
|
String |
getBody(String language)
Returns the body corresponding to the language.
|
List<String> |
getBodyLanguages()
Returns all the languages being used for the bodies, not including the default body.
|
String |
getSubject()
Returns the default subject of the message, or null if the subject has not been set.
|
String |
getSubject(String language)
Returns the subject corresponding to the language.
|
List<String> |
getSubjectLanguages()
Returns all the languages being used for the subjects, not including the default subject.
|
Set<Message.Subject> |
getSubjects()
Returns a set of all subjects in this Message, including the default message subject accessible
from
getSubject() . |
String |
getThread()
Returns the thread id of the message, which is a unique identifier for a sequence
of "chat" messages.
|
Message.Type |
getType()
Returns the type of the message.
|
boolean |
removeBody(Message.Body body)
Removes the body from the message and returns true if the body was removed.
|
boolean |
removeBody(String language)
Removes the body with the given language from the message.
|
boolean |
removeSubject(Message.Subject subject)
Removes the subject from the message and returns true if the subject was removed.
|
boolean |
removeSubject(String language)
Removes the subject with the given language from the message.
|
void |
setBody(CharSequence body)
Sets the body of the message.
|
void |
setBody(String body)
Sets the body of the message.
|
void |
setSubject(String subject)
Sets the subject of the message.
|
void |
setThread(String thread)
Sets the thread id of the message, which is a unique identifier for a sequence
of "chat" messages.
|
void |
setType(Message.Type type)
Sets the type of the message.
|
String |
toString()
Returns a short String describing the Stanza.
|
XmlStringBuilder |
toXML(String enclosingNamespace)
Returns the XML representation of this Element.
|
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensions, getFrom, getLanguage, getPacketID, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, removeExtension, setError, setError, setFrom, setFrom, setLanguage, setPacketID, setStanzaId, setStanzaId, setTo, setTo
public static final String ELEMENT
public static final String BODY
public Message()
public Message(Jid to)
to
- the recipient of the message.public Message(Jid to, Message.Type type)
to
- the user to send the message to.type
- the message type.public Message(Jid to, String body)
to
- the user to send the message to.body
- the body of the message.public Message(String to, String body) throws XmppStringprepException
to
- the user to send the message to.body
- the body of the message.XmppStringprepException
- if 'to' is not a valid XMPP address.public Message(Jid to, ExtensionElement extensionElement)
to
- extensionElement
- public Message.Type getType()
Message.Type.normal
.public void setType(Message.Type type)
type
- the type of the message.public String getSubject()
The default subject of a message is the subject that corresponds to the message's language.
(see Stanza.getLanguage()
) or if no language is set to the applications default
language (see Stanza.getDefaultLanguage()
).
public String getSubject(String language)
getSubject()
. Null will be returned if the language does not have
a corresponding subject.language
- the language of the subject to return.public Set<Message.Subject> getSubjects()
getSubject()
.public void setSubject(String subject)
subject
- the subject of the message.public Message.Subject addSubject(String language, String subject)
language
- the language of the subject being added.subject
- the subject being added to the message.Message.Subject
NullPointerException
- if the subject is null, a null pointer exception is thrownpublic boolean removeSubject(String language)
language
- the language of the subject which is to be removedpublic boolean removeSubject(Message.Subject subject)
subject
- the subject being removed from the message.public List<String> getSubjectLanguages()
public String getBody()
The default body of a message is the body that corresponds to the message's language.
(see Stanza.getLanguage()
) or if no language is set to the applications default
language (see Stanza.getDefaultLanguage()
).
public String getBody(String language)
getBody()
. Null will be returned if the language does not have
a corresponding body.language
- the language of the body to return.public Set<Message.Body> getBodies()
getBody()
.public void setBody(CharSequence body)
body
- the body of the message.setBody(String)
public void setBody(String body)
body
- the body of the message.public Message.Body addBody(String language, String body)
language
- the language of the body being added.body
- the body being added to the message.Message.Body
NullPointerException
- if the body is null, a null pointer exception is thrownpublic boolean removeBody(String language)
language
- the language of the body which is to be removedpublic boolean removeBody(Message.Body body)
body
- the body being removed from the message.public List<String> getBodyLanguages()
public String getThread()
public void setThread(String thread)
thread
- the thread id of the message.public String toString()
Stanza
public XmlStringBuilder toXML(String enclosingNamespace)
Element
public Message clone()
This does not perform a deep clone, as extension elements are shared between the new and old instance.
clone
in interface TypedCloneable<Message>
clone
in class Object