Package org.xmpp.packet
Class Presence
- java.lang.Object
-
- org.xmpp.packet.Packet
-
- org.xmpp.packet.Presence
-
@NotThreadSafe public class Presence extends Packet
Presence packet. Presence packets are used to express an entity's current network availability and to notify other entities of that availability. Presence packets are also used to negotiate and manage subscriptions to the presence of other entities.A presence optionally has a
Presence.Type.- Author:
- Matt Tucker
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPresence.ShowRepresents the presence "show" value.static classPresence.TypeRepresents the type of a presence packet.
-
Field Summary
-
Fields inherited from class org.xmpp.packet.Packet
docFactory, element, fromJID, toJID
-
-
Constructor Summary
Constructors Constructor Description Presence()Constructs a new Presence.Presence(org.dom4j.Element element)Constructs a new Presence using an existing Element.Presence(org.dom4j.Element element, boolean skipValidation)Constructs a new Presence using an existing Element.Presence(Presence.Type type)Constructs a new Presence with the specified type.
-
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.PresencecreateCopy()Returns a deep copy of this Presence.org.dom4j.ElementgetChildElement(String name, String namespace)Returns the first child element of this packet that matches the given name and namespace.intgetPriority()Returns the priority.Presence.ShowgetShow()Returns the presence "show" value, which specifies a particular availability status.StringgetStatus()Returns the status of this presence packet, a natural-language description of availability status.Presence.TypegetType()Returns the type of this presence.booleanisAvailable()Returns true if the presence type is "available".voidsetPriority(int priority)Sets the priority.voidsetShow(Presence.Show show)Sets the presence "show" value, which specifies a particular availability status.voidsetStatus(String status)Sets the status of this presence packet, a natural-language description of availability status.voidsetType(Presence.Type type)Sets the type of this presence.-
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
-
Presence
public Presence()
Constructs a new Presence.
-
Presence
public Presence(Presence.Type type)
Constructs a new Presence with the specified type.- Parameters:
type- the presence type.
-
Presence
public Presence(org.dom4j.Element element)
Constructs a new Presence using an existing Element. This is useful for parsing incoming presence Elements into Presence objects.- Parameters:
element- the presence Element.
-
Presence
public Presence(org.dom4j.Element element, boolean skipValidation)Constructs a new Presence using an existing Element. This is useful for parsing incoming Presence Elements into Presence 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 Presence Element.skipValidation- true if stringprep should not be applied to the TO address.
-
-
Method Detail
-
isAvailable
public boolean isAvailable()
Returns true if the presence type is "available". This is a convenience method that is equivalent to:getType() == null
- Returns:
- true if presense type is "available" else false.
-
getType
public Presence.Type getType()
Returns the type of this presence. If the presence is "available", the type will benull(in XMPP, no value for the type attribute is defined as available).- Returns:
- the presence type or
nullif "available". - See Also:
Presence.Type
-
setType
public void setType(Presence.Type type)
Sets the type of this presence.- Parameters:
type- the presence type.- See Also:
Presence.Type
-
getShow
public Presence.Show getShow()
Returns the presence "show" value, which specifies a particular availability status. If the <show> element is not present, this method will returnnull. The show value can only be set if the presence type is "avaialble". Anullshow value is used to represent "available", which is the default.- Returns:
- the presence show value..
- See Also:
Presence.Show
-
setShow
public void setShow(Presence.Show show)
Sets the presence "show" value, which specifies a particular availability status. The show value can only be set if the presence type is "available". Anullshow value is used to represent "available", which is the default.- Parameters:
show- the presence show value.- Throws:
IllegalArgumentException- if the presence type is not available.- See Also:
Presence.Show
-
getStatus
public String getStatus()
Returns the status of this presence packet, a natural-language description of availability status.- Returns:
- the status.
-
setStatus
public void setStatus(String status)
Sets the status of this presence packet, a natural-language description of availability status.- Parameters:
status- the status.
-
getPriority
public int getPriority()
Returns the priority. The valid priority range is -128 through 128. If no priority element exists in the packet, this method will return the default value of 0.- Returns:
- the priority.
-
setPriority
public void setPriority(int priority)
Sets the priority. The valid priority range is -128 through 128.- Parameters:
priority- the priority.- Throws:
IllegalArgumentException- if the priority is less than -128 or greater than 128.
-
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 Presence createCopy()
Returns a deep copy of this Presence.- Specified by:
createCopyin classPacket- Returns:
- a deep copy of this Presence.
-
-