Package org.xmpp.packet
Class Presence
java.lang.Object
org.xmpp.packet.Packet
org.xmpp.packet.Presence
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 ClassesModifier and TypeClassDescriptionstatic enumRepresents the presence "show" value.static enumRepresents the type of a presence packet. -
Field Summary
Fields inherited from class org.xmpp.packet.Packet
docFactory, element, fromJID, toJID -
Constructor Summary
ConstructorsConstructorDescriptionPresence()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
Modifier and TypeMethodDescriptionorg.dom4j.ElementaddChildElement(String name, String namespace) Adds a new child element to this packet with the given name and namespace.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.intReturns the priority.getShow()Returns the presence "show" value, which specifies a particular availability status.Returns the status of this presence packet, a natural-language description of availability status.getType()Returns the type of this presence.booleanReturns 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.voidSets 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 Details
-
Presence
public Presence()Constructs a new Presence. -
Presence
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 Details
-
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
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:
-
setType
Sets the type of this presence.- Parameters:
type- the presence type.- See Also:
-
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:
-
setShow
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:
-
getStatus
Returns the status of this presence packet, a natural-language description of availability status.- Returns:
- the status.
-
setStatus
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
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
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
Returns a deep copy of this Presence.- Specified by:
createCopyin classPacket- Returns:
- a deep copy of this Presence.
-