Search in sources :

Example 6 with RosterPacket

use of org.jivesoftware.smack.packet.RosterPacket in project ecf by eclipse.

the class RosterGroup method removeEntry.

/**
 * Removes a roster entry from this group. If the entry does not belong to any other group
 * then it will be considered as unfiled, therefore it will be added to the list of unfiled
 * entries.
 * Note that this is an asynchronous call -- Smack must wait for the server
 * to receive the updated roster.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an error occured while trying to remove the entry from the group.
 */
public void removeEntry(RosterEntry entry) throws XMPPException {
    PacketCollector collector = null;
    // server.
    synchronized (entries) {
        if (entries.contains(entry)) {
            RosterPacket packet = new RosterPacket();
            packet.setType(IQ.Type.SET);
            RosterPacket.Item item = RosterEntry.toRosterItem(entry);
            item.removeGroupName(this.getName());
            packet.addRosterItem(item);
            // Wait up to a certain number of seconds for a reply from the server.
            collector = connection.createPacketCollector(new PacketIDFilter(packet.getPacketID()));
            connection.sendPacket(packet);
        }
    }
    if (collector != null) {
        IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        collector.cancel();
        if (response == null) {
            throw new XMPPException("No response from the server.");
        } else // If the server replied with an error, throw an exception.
        if (response.getType() == IQ.Type.ERROR) {
            throw new XMPPException(response.getError());
        }
    }
}
Also used : RosterPacket(org.jivesoftware.smack.packet.RosterPacket) IQ(org.jivesoftware.smack.packet.IQ) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 7 with RosterPacket

use of org.jivesoftware.smack.packet.RosterPacket in project ecf by eclipse.

the class PacketParserUtils method parseRoster.

private static RosterPacket parseRoster(XmlPullParser parser) throws Exception {
    RosterPacket roster = new RosterPacket();
    boolean done = false;
    RosterPacket.Item item = null;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("item")) {
                String jid = parser.getAttributeValue("", "jid");
                String name = parser.getAttributeValue("", "name");
                // Create packet.
                item = new RosterPacket.Item(jid, name);
                // Set status.
                String ask = parser.getAttributeValue("", "ask");
                RosterPacket.ItemStatus status = RosterPacket.ItemStatus.fromString(ask);
                item.setItemStatus(status);
                // Set type.
                String subscription = parser.getAttributeValue("", "subscription");
                RosterPacket.ItemType type = RosterPacket.ItemType.valueOf(subscription != null ? subscription : "none");
                item.setItemType(type);
            }
            if (parser.getName().equals("group") && item != null) {
                final String groupName = parser.nextText();
                if (groupName != null && groupName.trim().length() > 0) {
                    item.addGroupName(groupName);
                }
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("item")) {
                roster.addRosterItem(item);
            }
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return roster;
}
Also used : RosterPacket(org.jivesoftware.smack.packet.RosterPacket)

Example 8 with RosterPacket

use of org.jivesoftware.smack.packet.RosterPacket in project ecf by eclipse.

the class RosterEntry method setName.

/**
 * Sets the name associated with this entry.
 *
 * @param name the name.
 */
public void setName(String name) {
    // Do nothing if the name hasn't changed.
    if (name != null && name.equals(this.name)) {
        return;
    }
    this.name = name;
    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.SET);
    packet.addRosterItem(toRosterItem(this));
    connection.sendPacket(packet);
}
Also used : RosterPacket(org.jivesoftware.smack.packet.RosterPacket)

Aggregations

RosterPacket (org.jivesoftware.smack.packet.RosterPacket)8 IQ (org.jivesoftware.smack.packet.IQ)5 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)4 Iterator (java.util.Iterator)1 IRosterItem (org.eclipse.ecf.presence.roster.IRosterItem)1 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)1 Presence (org.jivesoftware.smack.packet.Presence)1