Package org.jivesoftware.smack.packet

Examples of org.jivesoftware.smack.packet.RosterPacket


            response = null;
            response = new Presence(Presence.Type.subscribe);
            response.setTo(presence.getFrom());
            connection.sendPacket(response);
            // update the roster with the new user
            RosterPacket rosterPacket = new RosterPacket();
            rosterPacket.setType(IQ.Type.SET);
            RosterPacket.Item item = new RosterPacket.Item(presence.getFrom(), parseName(presence.getFrom()));
            item.addGroupName(OLATBUDDIES);
            item.setItemType(RosterPacket.ItemType.both);
            // item.setItemStatus(RosterPacket.ItemStatus.fromString());
            rosterPacket.addRosterItem(item);
            connection.sendPacket(rosterPacket);
          }
        }
        if (presence.getType() == Presence.Type.subscribe) {
          subscribedUsers.add(presence.getFrom());
View Full Code Here


   * jid="guido@localhost" /> </query> </iq>
   *
   * @param uname a valid username
   */
  protected void removeSubscription(String uname) {
    RosterPacket rosterPacket = new RosterPacket();
    rosterPacket.setType(IQ.Type.SET);
    RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname);
    item.setItemType(RosterPacket.ItemType.remove);
    rosterPacket.addRosterItem(item);
    try {
      connection.sendPacket(rosterPacket);
    } catch (RuntimeException e) {
      Tracing.logWarn("Error while trying to send Instant Messaging packet.", e, InstantMessagingClient.class);
    }
View Full Code Here

    Presence presence = new Presence(Presence.Type.subscribe);
    presence.setTo(uname + "@" + jabberServer);
    try {
      connection.sendPacket(presence);

      RosterPacket rosterPacket = new RosterPacket();
      rosterPacket.setType(IQ.Type.SET);
      RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname);
      item.addGroupName(groupname);
      item.setItemType(RosterPacket.ItemType.both);
      rosterPacket.addRosterItem(item);
      connection.sendPacket(rosterPacket);
    } catch (RuntimeException e) {
      Tracing.logWarn("Error while trying to send Instant Messaging packet.", e, InstantMessagingClient.class);
    }
  }
View Full Code Here

            } catch (Exception e) {
                // TODO: what should we do when a processing failure occurs??
                e.printStackTrace();
            }
        } else if (packet instanceof RosterPacket) {
            RosterPacket rosterPacket = (RosterPacket)packet;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Roster packet with : " + rosterPacket.getRosterItemCount() + " item(s)");
                Iterator rosterItems = rosterPacket.getRosterItems();
                while (rosterItems.hasNext()) {
                    Object item = rosterItems.next();
                    LOG.debug("Roster item: " + item);
                }
            }
View Full Code Here

            if (packet instanceof Message) {
                Message message = (Message) packet;
                logger.debug("Received message: " + message + " with " + message.getBody());

            } else if (packet instanceof RosterPacket) {
                RosterPacket rosterPacket = (RosterPacket) packet;

                if (logger.isDebugEnabled()) {
                    logger.debug("Roster packet with : " + rosterPacket.getRosterItemCount());
                    Iterator rosterItems = rosterPacket.getRosterItems();
                    while (rosterItems.hasNext()) {
                        Object item = rosterItems.next();
                        logger.debug("Roster item: " + item);
                    }
                }
View Full Code Here

            // will be fired for each affected entry
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();

            RosterPacket rosterPacket = (RosterPacket) packet;
            for (RosterPacket.Item item : rosterPacket.getRosterItems()) {
                RosterEntry entry = new RosterEntry(item.getUser(), item.getName(),
                        item.getItemType(), item.getItemStatus(), Roster.this, connection);

                // If the packet is of the type REMOVE then remove the entry
                if (RosterPacket.ItemType.remove.equals(item.getItemType())) {
View Full Code Here

        }
        if (connection.isAnonymous()) {
            throw new IllegalStateException("Anonymous users can't have a roster.");
        }

        connection.sendPacket(new RosterPacket());
    }
View Full Code Here

        if (connection.isAnonymous()) {
            throw new IllegalStateException("Anonymous users can't have a roster.");
        }

        // Create and send roster entry creation packet.
        RosterPacket rosterPacket = new RosterPacket();
        rosterPacket.setType(IQ.Type.SET);
        RosterPacket.Item item = new RosterPacket.Item(user, name);
        if (groups != null) {
            for (String group : groups) {
                if (group != null && group.trim().length() > 0) {
                    item.addGroupName(group);
                }
            }
        }
        rosterPacket.addRosterItem(item);
        // Wait up to a certain number of seconds for a reply from the server.
        PacketCollector collector = connection.createPacketCollector(
                new PacketIDFilter(rosterPacket.getPacketID()));
        connection.sendPacket(rosterPacket);
        IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        collector.cancel();
        if (response == null) {
            throw new XMPPException("No response from the server.");
View Full Code Here

        // Only remove the entry if it's in the entry list.
        // The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet)
        if (!entries.containsKey(entry.getUser())) {
            return;
        }
        RosterPacket packet = new RosterPacket();
        packet.setType(IQ.Type.SET);
        RosterPacket.Item item = RosterEntry.toRosterItem(entry);
        // Set the item type as REMOVE so that the server will delete the entry
        item.setItemType(RosterPacket.ItemType.remove);
        packet.addRosterItem(item);
        PacketCollector collector = connection.createPacketCollector(
                new PacketIDFilter(packet.getPacketID()));
        connection.sendPacket(packet);
        IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        collector.cancel();
        if (response == null) {
            throw new XMPPException("No response from the server.");
View Full Code Here

     * @param name the name of the group.
     */
    public void setName(String name) {
        synchronized (entries) {
            for (RosterEntry entry : entries) {
                RosterPacket packet = new RosterPacket();
                packet.setType(IQ.Type.SET);
                RosterPacket.Item item = RosterEntry.toRosterItem(entry);
                item.removeGroupName(this.name);
                item.addGroupName(name);
                packet.addRosterItem(item);
                connection.sendPacket(packet);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.packet.RosterPacket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.