Class RosterExchange

java.lang.Object
org.jivesoftware.smackx.xroster.packet.RosterExchange
All Implemented Interfaces:
org.jivesoftware.smack.packet.Element, org.jivesoftware.smack.packet.ExtensionElement, org.jivesoftware.smack.packet.NamedElement, org.jivesoftware.smack.packet.XmlElement, org.jivesoftware.smack.packet.XmlLangElement

public class RosterExchange extends Object implements org.jivesoftware.smack.packet.ExtensionElement
Represents XMPP Roster Item Exchange packets.

The 'jabber:x:roster' namespace (which is not to be confused with the 'jabber:iq:roster' namespace) is used to send roster items from one client to another. A roster item is sent by adding to the <message/> element an <x/> child scoped by the 'jabber:x:roster' namespace. This <x/> element may contain one or more <item/> children (one for each roster item to be sent).

Each <item/> element may possess the following attributes:

<jid/> -- The id of the contact being sent. This attribute is required.
<name/> -- A natural-language nickname for the contact. This attribute is optional.

Each <item/> element may also contain one or more <group/> children specifying the natural-language name of a user-specified group, for the purpose of categorizing this contact into one or more roster groups.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final QName
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty roster exchange package.
    RosterExchange(org.jivesoftware.smack.roster.Roster roster)
    Creates a new roster exchange package with the entries specified in roster.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addRosterEntry(org.jivesoftware.smack.roster.RosterEntry rosterEntry)
    Adds a roster entry to the packet.
    void
    addRosterEntry(RemoteRosterEntry remoteRosterEntry)
    Adds a remote roster entry to the packet.
    Returns the XML element name of the extension sub-packet root element.
    int
    Returns a count of the entries in the roster exchange.
    Returns the XML namespace of the extension sub-packet root element.
    Returns an Iterator for the roster entries in the packet.
    toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace)
    Returns the XML representation of a Roster Item Exchange according the specification.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.jivesoftware.smack.packet.Element

    toXML, toXML

    Methods inherited from interface org.jivesoftware.smack.packet.XmlElement

    getLanguage, getQName
  • Field Details

    • QNAME

      public static final QName QNAME
  • Constructor Details

    • RosterExchange

      public RosterExchange()
      Creates a new empty roster exchange package.
    • RosterExchange

      public RosterExchange(org.jivesoftware.smack.roster.Roster roster)
      Creates a new roster exchange package with the entries specified in roster.
      Parameters:
      roster - the roster to send to other XMPP entity.
  • Method Details

    • addRosterEntry

      public void addRosterEntry(org.jivesoftware.smack.roster.RosterEntry rosterEntry)
      Adds a roster entry to the packet.
      Parameters:
      rosterEntry - a roster entry to add.
    • addRosterEntry

      public void addRosterEntry(RemoteRosterEntry remoteRosterEntry)
      Adds a remote roster entry to the packet.
      Parameters:
      remoteRosterEntry - a remote roster entry to add.
    • getElementName

      public String getElementName()
      Returns the XML element name of the extension sub-packet root element. Always returns "x"
      Specified by:
      getElementName in interface org.jivesoftware.smack.packet.NamedElement
      Returns:
      the XML element name of the stanza extension.
    • getNamespace

      public String getNamespace()
      Returns the XML namespace of the extension sub-packet root element. According the specification the namespace is always "jabber:x:roster" (which is not to be confused with the 'jabber:iq:roster' namespace
      Specified by:
      getNamespace in interface org.jivesoftware.smack.packet.XmlElement
      Returns:
      the XML namespace of the stanza extension.
    • getRosterEntries

      public Iterator<RemoteRosterEntry> getRosterEntries()
      Returns an Iterator for the roster entries in the packet.
      Returns:
      an Iterator for the roster entries in the packet.
    • getEntryCount

      public int getEntryCount()
      Returns a count of the entries in the roster exchange.
      Returns:
      the number of entries in the roster exchange.
    • toXML

      public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace)
      Returns the XML representation of a Roster Item Exchange according the specification. Usually the XML representation will be inside of a Message XML representation like in the following example:
       <message id="MlIpV-4" to="gato1@gato.home" from="gato3@gato.home/Smack">
           <subject>Any subject you want</subject>
           <body>This message contains roster items.</body>
           <x xmlns="jabber:x:roster">
               <item jid="gato1@gato.home"/>
               <item jid="gato2@gato.home"/>
           </x>
       </message>
       
      Specified by:
      toXML in interface org.jivesoftware.smack.packet.Element