Smack

org.jivesoftware.smack.packet
Class Presence

java.lang.Object
  extended by org.jivesoftware.smack.packet.Packet
      extended by org.jivesoftware.smack.packet.Presence

public class Presence
extends Packet

Represents XMPP presence packets. Every presence packet has a type, which is one of the following values:

A number of attributes are optional:

Presence packets are used for two purposes. First, to notify the server of our the clients current presence status. Second, they are used to subscribe and unsubscribe users from the roster.

Author:
Matt Tucker
See Also:
RosterPacket

Nested Class Summary
static class Presence.Mode
          An enum to represent the presence mode.
static class Presence.Type
          A enum to represent the presecence type.
 
Field Summary
 
Fields inherited from class org.jivesoftware.smack.packet.Packet
DEFAULT_LANGUAGE, ID_NOT_AVAILABLE
 
Constructor Summary
Presence(Presence.Type type)
          Creates a new presence update.
Presence(Presence.Type type, String status, int priority, Presence.Mode mode)
          Creates a new presence update with a specified status, priority, and mode.
 
Method Summary
 Presence.Mode getMode()
          Returns the mode of the presence update, or null if the mode is not set.
 int getPriority()
          Returns the priority of the presence, or Integer.MIN_VALUE if no priority has been set.
 String getStatus()
          Returns the status message of the presence update, or null if there is not a status.
 Presence.Type getType()
          Returns the type of this presence packet.
 boolean isAvailable()
          Returns true if the presence type is available (online) and false if the user is unavailable (offline), or if this is a presence packet involved in a subscription operation.
 boolean isAway()
          Returns true if the presence type is available and the presence mode is away, extended away, or do not disturb.
 void setLanguage(String language)
          Sets the xml:lang of this Presence.
 void setMode(Presence.Mode mode)
          Sets the mode of the presence update.
 void setPriority(int priority)
          Sets the priority of the presence.
 void setStatus(String status)
          Sets the status message of the presence update.
 void setType(Presence.Type type)
          Sets the type of the presence packet.
 String toString()
           
 String toXML()
          Returns the packet as XML.
 
Methods inherited from class org.jivesoftware.smack.packet.Packet
addExtension, deleteProperty, equals, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensionsXML, getFrom, getPacketID, getProperty, getPropertyNames, getTo, getXmlns, hashCode, nextID, removeExtension, setDefaultXmlns, setError, setFrom, setPacketID, setProperty, setTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Presence

public Presence(Presence.Type type)
Creates a new presence update. Status, priority, and mode are left un-set.

Parameters:
type - the type.

Presence

public Presence(Presence.Type type,
                String status,
                int priority,
                Presence.Mode mode)
Creates a new presence update with a specified status, priority, and mode.

Parameters:
type - the type.
status - a text message describing the presence update.
priority - the priority of this presence update.
mode - the mode type for this presence update.
Method Detail

isAvailable

public boolean isAvailable()
Returns true if the presence type is available (online) and false if the user is unavailable (offline), or if this is a presence packet involved in a subscription operation. This is a convenience method equivalent to getType() == Presence.Type.available. Note that even when the user is available, their presence mode may be away, extended away or do not disturb. Use isAway() to determine if the user is away.

Returns:
true if the presence type is available.

isAway

public boolean isAway()
Returns true if the presence type is available and the presence mode is away, extended away, or do not disturb. False will be returned when the type or mode is any other value, including when the presence type is unavailable (offline). This is a convenience method equivalent to type == Type.available && (mode == Mode.away || mode == Mode.xa || mode == Mode.dnd).

Returns:
true if the presence type is available and the presence mode is away, xa, or dnd.

getType

public Presence.Type getType()
Returns the type of this presence packet.

Returns:
the type of the presence packet.

setType

public void setType(Presence.Type type)
Sets the type of the presence packet.

Parameters:
type - the type of the presence packet.

getStatus

public String getStatus()
Returns the status message of the presence update, or null if there is not a status. The status is free-form text describing a user's presence (i.e., "gone to lunch").

Returns:
the status message.

setStatus

public void setStatus(String status)
Sets the status message of the presence update. The status is free-form text describing a user's presence (i.e., "gone to lunch").

Parameters:
status - the status message.

getPriority

public int getPriority()
Returns the priority of the presence, or Integer.MIN_VALUE if no priority has been set.

Returns:
the priority.

setPriority

public void setPriority(int priority)
Sets the priority of the presence. The valid range is -128 through 128.

Parameters:
priority - the priority of the presence.
Throws:
IllegalArgumentException - if the priority is outside the valid range.

getMode

public Presence.Mode getMode()
Returns the mode of the presence update, or null if the mode is not set. A null presence mode value is interpreted to be the same thing as Presence.Mode.available.

Returns:
the mode.

setMode

public void setMode(Presence.Mode mode)
Sets the mode of the presence update. A null presence mode value is interpreted to be the same thing as Presence.Mode.available.

Parameters:
mode - the mode.

setLanguage

public void setLanguage(String language)
Sets the xml:lang of this Presence.

Parameters:
language - the xml:lang of this Presence.
Since:
3.0.2

toXML

public String toXML()
Description copied from class: Packet
Returns the packet as XML. Every concrete extension of Packet must implement this method. In addition to writing out packet-specific data, every sub-class should also write out the error and the extensions data if they are defined.

Specified by:
toXML in class Packet
Returns:
the XML format of the packet as a String.

toString

public String toString()
Overrides:
toString in class Object

Smack

Copyright © 2003-2007 Jive Software.