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 java.lang.String |
BODY |
static java.lang.String |
ELEMENT |
DEFAULT_LANGUAGE, ITEM, language, TEXT| Constructor and Description |
|---|
Message()
Creates a new, "normal" message.
|
Message(Message other)
Copy constructor.
|
Message(java.lang.String to)
Creates a new "normal" message to the specified recipient.
|
Message(java.lang.String to,
Message.Type type)
Creates a new message of the specified type to a recipient.
|
Message(java.lang.String to,
java.lang.String body)
Creates a new message to the specified recipient and with the specified body.
|
| Modifier and Type | Method and Description |
|---|---|
Message.Body |
addBody(java.lang.String language,
java.lang.String body)
Adds a body with a corresponding language.
|
Message.Subject |
addSubject(java.lang.String language,
java.lang.String subject)
Adds a subject with a corresponding language.
|
Message |
clone()
Creates and returns a copy of this message stanza.
|
java.util.Set<Message.Body> |
getBodies()
Returns a set of all bodies in this Message, including the default message body accessible
from
getBody(). |
java.lang.String |
getBody()
Returns the default body of the message, or null if the body has not been set.
|
java.lang.String |
getBody(java.lang.String language)
Returns the body corresponding to the language.
|
java.util.List<java.lang.String> |
getBodyLanguages()
Returns all the languages being used for the bodies, not including the default body.
|
java.lang.String |
getSubject()
Returns the default subject of the message, or null if the subject has not been set.
|
java.lang.String |
getSubject(java.lang.String language)
Returns the subject corresponding to the language.
|
java.util.List<java.lang.String> |
getSubjectLanguages()
Returns all the languages being used for the subjects, not including the default subject.
|
java.util.Set<Message.Subject> |
getSubjects()
Returns a set of all subjects in this Message, including the default message subject accessible
from
getSubject(). |
java.lang.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(java.lang.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(java.lang.String language)
Removes the subject with the given language from the message.
|
void |
setBody(java.lang.String body)
Sets the body of the message.
|
void |
setSubject(java.lang.String subject)
Sets the subject of the message.
|
void |
setThread(java.lang.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.
|
XmlStringBuilder |
toXML()
Returns the XML representation of this Element.
|
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensions, getExtensionsXML, getFrom, getLanguage, getPacketID, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, overrideExtension, removeExtension, removeExtension, setError, setFrom, setLanguage, setPacketID, setStanzaId, setTo, toStringpublic static final java.lang.String ELEMENT
public static final java.lang.String BODY
public Message()
public Message(java.lang.String to)
to - the recipient of the message.public Message(java.lang.String to,
Message.Type type)
to - the user to send the message to.type - the message type.public Message(java.lang.String to,
java.lang.String body)
to - the user to send the message to.body - the body of the message.public Message(Message other)
This does not perform a deep clone, as extension elements are shared between the new and old instance.
other - public Message.Type getType()
Message.Type.normal.public void setType(Message.Type type)
type - the type of the message.public java.lang.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 java.lang.String getSubject(java.lang.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 java.util.Set<Message.Subject> getSubjects()
getSubject().public void setSubject(java.lang.String subject)
subject - the subject of the message.public Message.Subject addSubject(java.lang.String language, java.lang.String subject)
language - the language of the subject being added.subject - the subject being added to the message.Message.Subjectjava.lang.NullPointerException - if the subject is null, a null pointer exception is thrownpublic boolean removeSubject(java.lang.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 java.util.List<java.lang.String> getSubjectLanguages()
public java.lang.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 java.lang.String getBody(java.lang.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 java.util.Set<Message.Body> getBodies()
getBody().public void setBody(java.lang.String body)
body - the body of the message.public Message.Body addBody(java.lang.String language, java.lang.String body)
language - the language of the body being added.body - the body being added to the message.Message.Bodyjava.lang.NullPointerException - if the body is null, a null pointer exception is thrownpublic boolean removeBody(java.lang.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 java.util.List<java.lang.String> getBodyLanguages()
public java.lang.String getThread()
public void setThread(java.lang.String thread)
thread - the thread id of the message.public XmlStringBuilder toXML()
Elementpublic 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 java.lang.Object