Class Presence

java.lang.Object
org.xmpp.packet.Packet
org.xmpp.packet.Presence
Direct Known Subclasses:
JoinRoom, LeaveRoom

@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
  • Constructor Details

    • 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 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

      public Presence.Type getType()
      Returns the type of this presence. If the presence is "available", the type will be null (in XMPP, no value for the type attribute is defined as available).
      Returns:
      the presence type or null if "available".
      See Also:
    • setType

      public void setType(Presence.Type type)
      Sets the type of this presence.
      Parameters:
      type - the presence type.
      See Also:
    • 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 return null. The show value can only be set if the presence type is "avaialble". A null show value is used to represent "available", which is the default.
      Returns:
      the presence show value..
      See Also:
    • 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". A null show 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

      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, null will 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 null if 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:
      createCopy in class Packet
      Returns:
      a deep copy of this Presence.