Class Message
- java.lang.Object
-
- org.xmpp.packet.Packet
-
- org.xmpp.packet.Message
-
- Direct Known Subclasses:
Invitation
@NotThreadSafe public class Message extends Packet
Message packet.A message can have one of several
Types. For each message type, different message fields are typically used as follows:Message type Field Normal Chat Group Chat Headline Error 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 classMessage.TypeType-safe enumeration for the type of a message.
-
Field Summary
-
Fields inherited from class org.xmpp.packet.Packet
docFactory, element, fromJID, toJID
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.dom4j.ElementaddChildElement(String name, String namespace)Adds a new child element to this packet with the given name and namespace.MessagecreateCopy()Returns a deep copy of this Message.StringgetBody()Returns the body of this message ornullif there is no body.org.dom4j.ElementgetChildElement(String name, String namespace)Returns the first child element of this packet that matches the given name and namespace.StringgetSubject()Returns the subject of this message ornullif there is no subject..StringgetThread()Returns the thread value of this message, an identifier that is used for tracking a conversation thread ("instant messaging session") between two entities.Message.TypegetType()Returns the type of this messagevoidsetBody(String body)Sets the body of this message.voidsetSubject(String subject)Sets the subject of this message.voidsetThread(String thread)Sets the thread value of this message, an identifier that is used for tracking a conversation thread ("instant messaging session") between two entities.voidsetType(Message.Type type)Sets the type of this message.-
Methods inherited from class org.xmpp.packet.Packet
addExtension, deleteExtension, getElement, getError, getExtension, getFrom, getID, getTo, setError, setError, setFrom, setFrom, setID, setTo, setTo, toString, toXML
-
-
-
-
Constructor Detail
-
Message
public Message()
Constructs a new Message.
-
Message
public Message(org.dom4j.Element element)
Constructs a new Message using an existing Element. This is useful for parsing incoming message Elements into Message objects.- Parameters:
element- the message Element.
-
Message
public Message(org.dom4j.Element element, boolean skipValidation)Constructs a new Message using an existing Element. This is useful for parsing incoming message Elements into Message objects. Stringprep validation on the TO address can be disabled. The FROM address will not be validated since the server is the one that sets that value.- Parameters:
element- the message Element.skipValidation- true if stringprep should not be applied to the TO address.
-
-
Method Detail
-
getType
public Message.Type getType()
Returns the type of this message- Returns:
- the message type.
- See Also:
Message.Type
-
setType
public void setType(Message.Type type)
Sets the type of this message.- Parameters:
type- the message type.- See Also:
Message.Type
-
getSubject
public String getSubject()
Returns the subject of this message ornullif there is no subject..- Returns:
- the subject.
-
setSubject
public void setSubject(String subject)
Sets the subject of this message.- Parameters:
subject- the subject.
-
getBody
public String getBody()
Returns the body of this message ornullif there is no body.- Returns:
- the body.
-
setBody
public void setBody(String body)
Sets the body of this message.- Parameters:
body- the body.
-
getThread
public String getThread()
Returns the thread value of this message, an identifier that is used for tracking a conversation thread ("instant messaging session") between two entities. If the thread is not set,nullwill be returned.- Returns:
- the thread value.
-
setThread
public void setThread(String thread)
Sets the thread value of this message, an identifier that is used for tracking a conversation thread ("instant messaging session") between two entities.- Parameters:
thread- thread value.
-
getChildElement
public org.dom4j.Element getChildElement(String name, String namespace)
Returns the first child element of this packet that matches the given name and namespace. If no matching element is found,nullwill be returned. This is a convenience method to avoid manipulating this underlying packet's Element instance directly.Child elements in extended namespaces are used to extend the features of XMPP. Examples include a "user is typing" indicator and invitations to group chat rooms. Although any valid XML can be included in a child element in an extended namespace, many common features have been standardized as XMPP Extension Protocols (XEPs).
- Parameters:
name- the element name.namespace- the element namespace.- Returns:
- the first matching child element, or
nullif there is no matching child element.
-
addChildElement
public org.dom4j.Element addChildElement(String name, String namespace)
Adds a new child element to this packet with the given name and namespace. The newly created Element is returned. This is a convenience method to avoid manipulating this underlying packet's Element instance directly.Child elements in extended namespaces are used to extend the features of XMPP. Examples include a "user is typing" indicator and invitations to group chat rooms. Although any valid XML can be included in a child element in an extended namespace, many common features have been standardized as XMPP Extension Protocols (XEPs).
- Parameters:
name- the element name.namespace- the element namespace.- Returns:
- the newly created child element.
-
createCopy
public Message createCopy()
Returns a deep copy of this Message.- Specified by:
createCopyin classPacket- Returns:
- a deep copy of this Message.
-
-