Java 类org.jivesoftware.smack.packet.RosterPacket 实例源码

项目:androidpn_enhanced_client    文件:Roster.java   
/**
 * Removes a roster entry from the roster. The roster entry will also be removed from the
 * unfiled entries or from any roster group where it could belong and will no longer be part
 * of the roster. Note that this is an asynchronous call -- Smack must wait for the server
 * to send an updated subscription status.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an XMPP error occurs.
 */
public void removeEntry(RosterEntry entry) throws XMPPException {
    // 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.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
项目:androidpn_enhanced_client    文件:Roster.java   
public void processPacket(Packet packet) {
    if(packet instanceof IQ){
        IQ result = (IQ)packet;
        if(result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()){
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if(persistentStorage!=null){
                for(RosterPacket.Item item : persistentStorage.getEntries()){
                    insertRosterItem(item,addedEntries,updatedEntries,deletedEntries);
                }
                synchronized (Roster.this) {
                    rosterInitialized = true;
                    Roster.this.notifyAll();
                }
                fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries);
            }
        }
    }
    connection.removePacketListener(this);
}
项目:androidPN-client.    文件:Roster.java   
/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * 
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void reload() {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    RosterPacket packet = new RosterPacket();
    if(persistentStorage!=null){
        packet.setVersion(persistentStorage.getRosterVersion());
    }
    requestPacketId = packet.getPacketID();
    PacketFilter idFilter = new PacketIDFilter(requestPacketId);
    connection.addPacketListener(new RosterResultListener(), idFilter);
    connection.sendPacket(packet);
}
项目:androidPN-client.    文件:Roster.java   
public void processPacket(Packet packet) {
    if (packet instanceof IQ) {
        IQ result = (IQ) packet;
        if (result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()) {
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if (persistentStorage != null) {
                for (RosterPacket.Item item : persistentStorage.getEntries()) {
                    insertRosterItem(item, addedEntries, updatedEntries, deletedEntries);
                }
            }
            fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);
        }
    }
    connection.removePacketListener(this);
}
项目:olat    文件:InstantMessagingClient.java   
/**
 * Sends a subscription request to the username answers are handled by the method
 * 
 * @param uname
 * @param groupname
 */
protected void subscribeToUser(final String uname, final String groupname) {
    final Presence presence = new Presence(Presence.Type.subscribe);
    presence.setTo(uname + "@" + jabberServer);
    try {
        connection.sendPacket(presence);

        final RosterPacket rosterPacket = new RosterPacket();
        rosterPacket.setType(IQ.Type.SET);
        final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname);
        item.addGroupName(groupname);
        item.setItemType(RosterPacket.ItemType.both);
        rosterPacket.addRosterItem(item);
        connection.sendPacket(rosterPacket);
    } catch (final RuntimeException e) {
        log.warn("Error while trying to send Instant Messaging packet.", e);
    }
}
项目:olat    文件:InstantMessagingClient.java   
/**
 * Sends a subscription request to the username answers are handled by the method
 * 
 * @param uname
 * @param groupname
 */
protected void subscribeToUser(final String uname, final String groupname) {
    final Presence presence = new Presence(Presence.Type.subscribe);
    presence.setTo(uname + "@" + jabberServer);
    try {
        connection.sendPacket(presence);

        final RosterPacket rosterPacket = new RosterPacket();
        rosterPacket.setType(IQ.Type.SET);
        final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname);
        item.addGroupName(groupname);
        item.setItemType(RosterPacket.ItemType.both);
        rosterPacket.addRosterItem(item);
        connection.sendPacket(rosterPacket);
    } catch (final RuntimeException e) {
        log.warn("Error while trying to send Instant Messaging packet.", e);
    }
}
项目:xmppsupport_v2    文件:Roster.java   
/**
 * Reloads the entire roster from the server. This is an asynchronous
 * operation, which means the method will return immediately, and the roster
 * will be reloaded at a later point when the server responds to the reload
 * request.
 * 
 * @throws IllegalStateException
 *             if connection is not logged in or logged in anonymously
 */
public void reload() {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException(
                "Anonymous users can't have a roster.");
    }

    RosterPacket packet = new RosterPacket();
    if (persistentStorage != null) {
        packet.setVersion(persistentStorage.getRosterVersion());
    }
    requestPacketId = packet.getPacketID();
    PacketFilter idFilter = new PacketIDFilter(requestPacketId);
    connection.addPacketListener(new RosterResultListener(), idFilter);
    connection.sendPacket(packet);
}
项目:xmppsupport_v2    文件:Roster.java   
public void processPacket(Packet packet) {
    if (packet instanceof IQ) {
        IQ result = (IQ) packet;
        if (result.getType().equals(IQ.Type.RESULT)
                && result.getExtensions().isEmpty()) {
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if (persistentStorage != null) {
                for (RosterPacket.Item item : persistentStorage
                        .getEntries()) {
                    insertRosterItem(item, addedEntries,
                            updatedEntries, deletedEntries);
                }
            }
            synchronized (Roster.this) {
                rosterInitialized = true;
                Roster.this.notifyAll();
            }
            fireRosterChangedEvent(addedEntries, updatedEntries,
                    deletedEntries);
        }
    }
    connection.removePacketListener(this);
}
项目:AndroidPNClient    文件:Roster.java   
/**
 * Removes a roster entry from the roster. The roster entry will also be removed from the
 * unfiled entries or from any roster group where it could belong and will no longer be part
 * of the roster. Note that this is an asynchronous call -- Smack must wait for the server
 * to send an updated subscription status.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an XMPP error occurs.
 */
public void removeEntry(RosterEntry entry) throws XMPPException {
    // 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.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
项目:AndroidPNClient    文件:Roster.java   
public void processPacket(Packet packet) {
    if(packet instanceof IQ){
        IQ result = (IQ)packet;
        if(result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()){
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if(persistentStorage!=null){
                for(RosterPacket.Item item : persistentStorage.getEntries()){
                    insertRosterItem(item,addedEntries,updatedEntries,deletedEntries);
                }
                synchronized (Roster.this) {
                    rosterInitialized = true;
                    Roster.this.notifyAll();
                }
                fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries);
            }
        }
    }
    connection.removePacketListener(this);
}
项目:Chatting-App-    文件:RosterListener.java   
@Override
public void processPacket(Packet packet) {
    RosterPacket p = (RosterPacket) packet;
    Intent i = new Intent(ACTION_ROSTER);
    i.putExtra(EXTRA_FROM, p.getFrom());
    i.putExtra(EXTRA_TO, p.getTo());
    // here we are not using() because Type is a class, not an enum
    i.putExtra(EXTRA_TYPE, p.getType().toString());
    i.putExtra(EXTRA_PACKET_ID, p.getPacketID());

    Collection<RosterPacket.Item> items = p.getRosterItems();
    String[] list = new String[items.size()];

    int index = 0;
    for (Iterator<RosterPacket.Item> iter = items.iterator(); iter.hasNext(); ) {
        RosterPacket.Item item = iter.next();
        list[index] = item.getUser();
        index++;
    }

    i.putExtra(EXTRA_JIDLIST, list);

    sendBroadcast(i);
}
项目:aceim    文件:XMPPEntityAdapter.java   
public Buddy rosterEntry2Buddy(RosterEntry entry, String ownerJid, Context context, byte serviceId){
    if (entry == null){
        return null;
    }
    Buddy buddy = new Buddy(normalizeJID(entry.getUser()), ownerJid, XMPPApiConstants.PROTOCOL_NAME, serviceId);
    buddy.setName(entry.getName());
    buddy.setId(entry.getUser().hashCode());
    buddy.setGroupId((entry.getGroups() != null && entry.getGroups().size() > 0) ? entry.getGroups().iterator().next().getName() : ApiConstants.NO_GROUP_ID);
    //buddy.clientId = getClientId(entry.getUser());

    if (entry.getStatus()!=null && entry.getStatus().equals(RosterPacket.ItemStatus.SUBSCRIPTION_PENDING)){
        //buddy.visibility = Buddy.VIS_NOT_AUTHORIZED;
    }

    return buddy;
}
项目:telegraph    文件:Roster.java   
/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * 
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void reload() {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    RosterPacket packet = new RosterPacket();
    if(persistentStorage!=null){
        packet.setVersion(persistentStorage.getRosterVersion());
    }
    requestPacketId = packet.getPacketID();
    PacketFilter idFilter = new PacketIDFilter(requestPacketId);
    connection.addPacketListener(new RosterResultListener(), idFilter);
    connection.sendPacket(packet);
}
项目:telegraph    文件:Roster.java   
public void processPacket(Packet packet) {
    if(packet instanceof IQ){
        IQ result = (IQ)packet;
        if(result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()){
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if(persistentStorage!=null){
                for(RosterPacket.Item item : persistentStorage.getEntries()){
                    insertRosterItem(item,addedEntries,updatedEntries,deletedEntries);
                }
                          }
            synchronized (Roster.this) {
                rosterInitialized = true;
                Roster.this.notifyAll();
            }
            fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries);
        }
    }
    connection.removePacketListener(this);
}
项目:NewCommunication-Android    文件:Roster.java   
/**
 * Removes a roster entry from the roster. The roster entry will also be removed from the
 * unfiled entries or from any roster group where it could belong and will no longer be part
 * of the roster. Note that this is an asynchronous call -- Smack must wait for the server
 * to send an updated subscription status.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an XMPP error occurs.
 */
public void removeEntry(RosterEntry entry) throws XMPPException {
    // 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.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
项目:NewCommunication-Android    文件:Roster.java   
public void processPacket(Packet packet) {
    if(packet instanceof IQ){
        IQ result = (IQ)packet;
        if(result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()){
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if(persistentStorage!=null){
                for(RosterPacket.Item item : persistentStorage.getEntries()){
                    insertRosterItem(item,addedEntries,updatedEntries,deletedEntries);
                }
                synchronized (Roster.this) {
                    rosterInitialized = true;
                    Roster.this.notifyAll();
                }
                fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries);
            }
        }
    }
    connection.removePacketListener(this);
}
项目:asmack-mini    文件:Roster.java   
/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * 
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void reload() {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    RosterPacket packet = new RosterPacket();
    if(persistentStorage!=null){
        packet.setVersion(persistentStorage.getRosterVersion());
    }
    requestPacketId = packet.getPacketID();
    PacketFilter idFilter = new PacketIDFilter(requestPacketId);
    connection.addPacketListener(new RosterResultListener(), idFilter);
    connection.sendPacket(packet);
}
项目:asmack-mini    文件:Roster.java   
public void processPacket(Packet packet) {
    if(packet instanceof IQ){
        IQ result = (IQ)packet;
        if(result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()){
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if(persistentStorage!=null){
                for(RosterPacket.Item item : persistentStorage.getEntries()){
                    insertRosterItem(item,addedEntries,updatedEntries,deletedEntries);
                }
                          }
            synchronized (Roster.this) {
                rosterInitialized = true;
                Roster.this.notifyAll();
            }
            fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries);
        }
    }
    connection.removePacketListener(this);
}
项目:EIM    文件:RosterEntry.java   
/**
 * Creates a new roster entry.
 *
 * @param user the user.
 * @param name the nickname for the entry.
 * @param type the subscription type.
 * @param status the subscription status (related to subscriptions pending to be approbed).
 * @param connection a connection to the XMPP server.
 */
RosterEntry(String user, String name, RosterPacket.ItemType type,
            RosterPacket.ItemStatus status, Roster roster, Connection connection) {
    this.user = user;
    this.name = name;
    this.type = type;
    this.status = status;
    this.roster = roster;
    this.connection = connection;
}
项目:EIM    文件:RosterEntry.java   
/**
 * 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);
}
项目:EIM    文件:RosterEntry.java   
static RosterPacket.Item toRosterItem(RosterEntry entry) {
    RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
    item.setItemType(entry.getType());
    item.setItemStatus(entry.getStatus());
    // Set the correct group names for the item.
    for (RosterGroup group : entry.getGroups()) {
        item.addGroupName(group.getName());
    }
    return item;
}
项目:EIM    文件:Roster.java   
/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * 
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void reload() {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    connection.sendPacket(new RosterPacket());
}
项目:EIM    文件:Roster.java   
/**
 * Removes a roster entry from the roster. The roster entry will also be removed from the
 * unfiled entries or from any roster group where it could belong and will no longer be part
 * of the roster. Note that this is an asynchronous call -- Smack must wait for the server
 * to send an updated subscription status.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an XMPP error occurs.
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void removeEntry(RosterEntry entry) throws XMPPException {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    // 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.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
项目:EIM    文件:RosterGroup.java   
/**
 * Sets the name of the group. Changing the group's name is like moving all the group entries
 * of the group to a new group specified by the new name. Since this group won't have entries 
 * it will be removed from the roster. This means that all the references to this object will 
 * be invalid and will need to be updated to the new group specified by the new name.
 *
 * @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);
        }
    }
}
项目:EIM    文件:RosterGroup.java   
/**
 * Adds a roster entry to this group. If the entry was unfiled then it will be removed from 
 * the unfiled list and will be added to this group.
 * 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 add the entry to the group.
 */
public void addEntry(RosterEntry entry) throws XMPPException {
    PacketCollector collector = null;
    // Only add the entry if it isn't already in the list.
    synchronized (entries) {
        if (!entries.contains(entry)) {
            RosterPacket packet = new RosterPacket();
            packet.setType(IQ.Type.SET);
            RosterPacket.Item item = RosterEntry.toRosterItem(entry);
            item.addGroupName(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.");
        }
        // If the server replied with an error, throw an exception.
        else if (response.getType() == IQ.Type.ERROR) {
            throw new XMPPException(response.getError());
        }
    }
}
项目:EIM    文件:RosterGroup.java   
/**
 * 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;
    // Only remove the entry if it's in the entry list.
    // Remove the entry locally, if we wait for RosterPacketListenerprocess>>Packet(Packet)
    // to take place the entry will exist in the group until a packet is received from the 
    // 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.");
        }
        // If the server replied with an error, throw an exception.
        else if (response.getType() == IQ.Type.ERROR) {
            throw new XMPPException(response.getError());
        }
    }
}
项目:androidpn_enhanced_client    文件:RosterEntry.java   
/**
 * Creates a new roster entry.
 *
 * @param user the user.
 * @param name the nickname for the entry.
 * @param type the subscription type.
 * @param status the subscription status (related to subscriptions pending to be approbed).
 * @param connection a connection to the XMPP server.
 */
RosterEntry(String user, String name, RosterPacket.ItemType type,
            RosterPacket.ItemStatus status, Roster roster, Connection connection) {
    this.user = user;
    this.name = name;
    this.type = type;
    this.status = status;
    this.roster = roster;
    this.connection = connection;
}
项目:androidpn_enhanced_client    文件:RosterEntry.java   
/**
 * 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);
}
项目:androidpn_enhanced_client    文件:RosterEntry.java   
static RosterPacket.Item toRosterItem(RosterEntry entry) {
    RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
    item.setItemType(entry.getType());
    item.setItemStatus(entry.getStatus());
    // Set the correct group names for the item.
    for (RosterGroup group : entry.getGroups()) {
        item.addGroupName(group.getName());
    }
    return item;
}
项目:androidpn_enhanced_client    文件:Roster.java   
/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 */
public void reload() {
    RosterPacket packet = new RosterPacket();
    if(persistentStorage!=null){
        packet.setVersion(persistentStorage.getRosterVersion());
    }
    requestPacketId = packet.getPacketID();
    PacketFilter idFilter = new PacketIDFilter(requestPacketId);
    connection.addPacketListener(new RosterResultListener(), idFilter);
    connection.sendPacket(packet);
}
项目:androidpn_enhanced_client    文件:Roster.java   
private void insertRosterItems(List<RosterPacket.Item> items){
     Collection<String> addedEntries = new ArrayList<String>();
     Collection<String> updatedEntries = new ArrayList<String>();
     Collection<String> deletedEntries = new ArrayList<String>();
     Iterator<RosterPacket.Item> iter = items.iterator();
     while(iter.hasNext()){
         insertRosterItem(iter.next(), addedEntries,updatedEntries,deletedEntries);
     }
     fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);
}
项目:androidpn_enhanced_client    文件:RosterGroup.java   
/**
 * Sets the name of the group. Changing the group's name is like moving all the group entries
 * of the group to a new group specified by the new name. Since this group won't have entries 
 * it will be removed from the roster. This means that all the references to this object will 
 * be invalid and will need to be updated to the new group specified by the new name.
 *
 * @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);
        }
    }
}
项目:androidpn_enhanced_client    文件:RosterGroup.java   
/**
 * Adds a roster entry to this group. If the entry was unfiled then it will be removed from 
 * the unfiled list and will be added to this group.
 * 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 add the entry to the group.
 */
public void addEntry(RosterEntry entry) throws XMPPException {
    PacketCollector collector = null;
    // Only add the entry if it isn't already in the list.
    synchronized (entries) {
        if (!entries.contains(entry)) {
            RosterPacket packet = new RosterPacket();
            packet.setType(IQ.Type.SET);
            RosterPacket.Item item = RosterEntry.toRosterItem(entry);
            item.addGroupName(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.");
        }
        // If the server replied with an error, throw an exception.
        else if (response.getType() == IQ.Type.ERROR) {
            throw new XMPPException(response.getError());
        }
    }
}
项目:androidpn_enhanced_client    文件:RosterGroup.java   
/**
 * 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;
    // Only remove the entry if it's in the entry list.
    // Remove the entry locally, if we wait for RosterPacketListenerprocess>>Packet(Packet)
    // to take place the entry will exist in the group until a packet is received from the 
    // 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.");
        }
        // If the server replied with an error, throw an exception.
        else if (response.getType() == IQ.Type.ERROR) {
            throw new XMPPException(response.getError());
        }
    }
}
项目:androidPN-client.    文件:RosterEntry.java   
/**
 * Creates a new roster entry.
 *
 * @param user the user.
 * @param name the nickname for the entry.
 * @param type the subscription type.
 * @param status the subscription status (related to subscriptions pending to be approbed).
 * @param connection a connection to the XMPP server.
 */
RosterEntry(String user, String name, RosterPacket.ItemType type,
            RosterPacket.ItemStatus status, Roster roster, Connection connection) {
    this.user = user;
    this.name = name;
    this.type = type;
    this.status = status;
    this.roster = roster;
    this.connection = connection;
}
项目:androidPN-client.    文件:RosterEntry.java   
/**
 * 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);
}
项目:androidPN-client.    文件:RosterEntry.java   
static RosterPacket.Item toRosterItem(RosterEntry entry) {
    RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
    item.setItemType(entry.getType());
    item.setItemStatus(entry.getStatus());
    // Set the correct group names for the item.
    for (RosterGroup group : entry.getGroups()) {
        item.addGroupName(group.getName());
    }
    return item;
}