Package org.jivesoftware.smack.packet
Class Message
- java.lang.Object
-
- org.jivesoftware.smack.packet.Stanza
-
- org.jivesoftware.smack.packet.MessageOrPresence<MessageBuilder>
-
- org.jivesoftware.smack.packet.Message
-
- All Implemented Interfaces:
Element
,FullyQualifiedElement
,MessageView
,NamedElement
,StanzaView
,TopLevelStreamElement
,XmlLangElement
public final class Message extends MessageOrPresence<MessageBuilder> implements MessageView
Represents XMPP message packets. A message can be one of several types:- Message.Type.NORMAL -- (Default) a normal text message used in email like interface.
- Message.Type.CHAT -- a typically short text message used in line-by-line chat interfaces.
- Message.Type.GROUP_CHAT -- a chat message sent to a groupchat server for group chats.
- Message.Type.HEADLINE -- a text message to be displayed in scrolling marquee displays.
- Message.Type.ERROR -- indicates a messaging error.
Message Types 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.Thread
static class
Message.Type
Represents the type of a message.
-
Constructor Summary
Constructors Constructor Description Message()
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Message(java.lang.String to, java.lang.String body)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Message(Message other)
Copy constructor.Message(Jid to)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Message(Jid to, java.lang.String body)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Message(Jid to, ExtensionElement extensionElement)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Message(Jid to, Message.Type type)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Message.Body
addBody(java.lang.String language, java.lang.String body)
Deprecated.useStanzaBuilder
instead.Message.Subject
addSubject(java.lang.String language, java.lang.String subject)
Deprecated.MessageBuilder
asBuilder()
MessageBuilder
asBuilder(java.lang.String id)
MessageBuilder
asBuilder(XMPPConnection connection)
Message
clone()
Deprecated.useasBuilder()
instead.java.lang.String
getElementName()
Returns the root element name.Message.Type
getType()
Returns the type of the message.boolean
removeBody(java.lang.String language)
Deprecated.useStanzaBuilder
instead.boolean
removeBody(Message.Body body)
Deprecated.useStanzaBuilder
instead.boolean
removeSubject(java.lang.String language)
Deprecated.boolean
removeSubject(Message.Subject subject)
Deprecated.void
setBody(java.lang.CharSequence body)
Deprecated.useStanzaBuilder
instead.void
setBody(java.lang.String body)
Deprecated.useStanzaBuilder
instead.void
setSubject(java.lang.String subject)
Deprecated.useStanzaBuilder
instead.void
setThread(java.lang.String thread)
Deprecated.useStanzaBuilder
instead.void
setType(Message.Type type)
Deprecated.useStanzaBuilder
instead.java.lang.String
toString()
Returns a short String describing the Stanza.XmlStringBuilder
toXML(XmlEnvironment enclosingXmlEnvironment)
-
Methods inherited from class org.jivesoftware.smack.packet.Stanza
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtension, getExtensionElement, getExtensions, getExtensions, getExtensions, getExtensions, getExtensionsMap, getFrom, getLanguage, getNamespace, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, removeExtension, setError, setError, setFrom, setLanguage, setNewStanzaId, setStanzaId, setStanzaId, setTo, throwIfNoStanzaId
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.packet.FullyQualifiedElement
getQName
-
Methods inherited from interface org.jivesoftware.smack.packet.MessageView
getBodies, getBody, getBody, getBodyLanguages, getMessageBody, getMessageSubject, getSubject, getSubject, getSubjectLanguages, getSubjects, getThread
-
Methods inherited from interface org.jivesoftware.smack.packet.StanzaView
getError, getExtension, getExtension, getExtensions, getExtensions, getExtensions, getFrom, getStanzaId, getTo, hasExtension, hasExtension, hasExtension
-
-
-
-
Field Detail
-
ELEMENT
public static final java.lang.String ELEMENT
- See Also:
- Constant Field Values
-
BODY
public static final java.lang.String BODY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Message
@Deprecated public Message()
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Creates a new, "normal" message.
-
Message
@Deprecated public Message(Jid to)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Creates a new "normal" message to the specified recipient.- Parameters:
to
- the recipient of the message.
-
Message
@Deprecated public Message(Jid to, Message.Type type)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Creates a new message of the specified type to a recipient.- Parameters:
to
- the user to send the message to.type
- the message type.
-
Message
@Deprecated public Message(Jid to, java.lang.String body)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Creates a new message to the specified recipient and with the specified body.- Parameters:
to
- the user to send the message to.body
- the body of the message.
-
Message
@Deprecated public Message(java.lang.String to, java.lang.String body) throws XmppStringprepException
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Creates a new message to the specified recipient and with the specified body.- Parameters:
to
- the user to send the message to.body
- the body of the message.- Throws:
XmppStringprepException
- if 'to' is not a valid XMPP address.
-
Message
@Deprecated public Message(Jid to, ExtensionElement extensionElement)
Deprecated.useStanzaBuilder
, preferable viaStanzaFactory
, instead.Creates a new message with the specified recipient and extension element.- Parameters:
to
- TODO javadoc me pleaseextensionElement
- TODO javadoc me please- Since:
- 4.2
-
-
Method Detail
-
getType
public Message.Type getType()
Description copied from interface:MessageView
Returns the type of the message. If no type has been set this method will returnMessage.Type.normal
.- Specified by:
getType
in interfaceMessageView
- Returns:
- the type of the message.
-
setType
@Deprecated public void setType(Message.Type type)
Deprecated.useStanzaBuilder
instead.Sets the type of the message.- Parameters:
type
- the type of the message.
-
setSubject
@Deprecated public void setSubject(java.lang.String subject)
Deprecated.useStanzaBuilder
instead.Sets the subject of the message. The subject is a short description of message contents.- Parameters:
subject
- the subject of the message.
-
addSubject
@Deprecated public Message.Subject addSubject(java.lang.String language, java.lang.String subject)
Deprecated.Adds a subject with a corresponding language.- Parameters:
language
- the language of the subject being added.subject
- the subject being added to the message.- Returns:
- the new
Message.Subject
- Throws:
java.lang.NullPointerException
- if the subject is null, a null pointer exception is thrown
-
removeSubject
@Deprecated public boolean removeSubject(java.lang.String language)
Deprecated.Removes the subject with the given language from the message.- Parameters:
language
- the language of the subject which is to be removed- Returns:
- true if a subject was removed and false if it was not.
-
removeSubject
@Deprecated public boolean removeSubject(Message.Subject subject)
Deprecated.Removes the subject from the message and returns true if the subject was removed.- Parameters:
subject
- the subject being removed from the message.- Returns:
- true if the subject was successfully removed and false if it was not.
-
setBody
@Deprecated public void setBody(java.lang.CharSequence body)
Deprecated.useStanzaBuilder
instead.Sets the body of the message.- Parameters:
body
- the body of the message.- Since:
- 4.2
- See Also:
setBody(String)
-
setBody
@Deprecated public void setBody(java.lang.String body)
Deprecated.useStanzaBuilder
instead.Sets the body of the message. The body is the main message contents.- Parameters:
body
- the body of the message.
-
addBody
@Deprecated public Message.Body addBody(java.lang.String language, java.lang.String body)
Deprecated.useStanzaBuilder
instead.Adds a body with a corresponding language.- Parameters:
language
- the language of the body being added.body
- the body being added to the message.- Returns:
- the new
Message.Body
- Throws:
java.lang.NullPointerException
- if the body is null, a null pointer exception is thrown- Since:
- 3.0.2
-
removeBody
@Deprecated public boolean removeBody(java.lang.String language)
Deprecated.useStanzaBuilder
instead.Removes the body with the given language from the message.- Parameters:
language
- the language of the body which is to be removed- Returns:
- true if a body was removed and false if it was not.
-
removeBody
@Deprecated public boolean removeBody(Message.Body body)
Deprecated.useStanzaBuilder
instead.Removes the body from the message and returns true if the body was removed.- Parameters:
body
- the body being removed from the message.- Returns:
- true if the body was successfully removed and false if it was not.
- Since:
- 3.0.2
-
setThread
@Deprecated public void setThread(java.lang.String thread)
Deprecated.useStanzaBuilder
instead.Sets the thread id of the message, which is a unique identifier for a sequence of "chat" messages.- Parameters:
thread
- the thread id of the message.
-
getElementName
public java.lang.String getElementName()
Description copied from interface:NamedElement
Returns the root element name.- Specified by:
getElementName
in interfaceNamedElement
- Returns:
- the element name.
-
asBuilder
public MessageBuilder asBuilder()
- Specified by:
asBuilder
in classMessageOrPresence<MessageBuilder>
-
asBuilder
public MessageBuilder asBuilder(java.lang.String id)
- Specified by:
asBuilder
in classMessageOrPresence<MessageBuilder>
-
asBuilder
public MessageBuilder asBuilder(XMPPConnection connection)
- Specified by:
asBuilder
in classMessageOrPresence<MessageBuilder>
-
toString
public java.lang.String toString()
Description copied from class:Stanza
Returns a short String describing the Stanza. This method is suited for log purposes.
-
toXML
public XmlStringBuilder toXML(XmlEnvironment enclosingXmlEnvironment)
-
clone
@Deprecated public Message clone()
Deprecated.useasBuilder()
instead.Creates and returns a copy of this message stanza.This does not perform a deep clone, as extension elements are shared between the new and old instance.
- Overrides:
clone
in classjava.lang.Object
- Returns:
- a clone of this message.
-
-