org.jivesoftware.smack.roster.RosterEntry Java Examples

The following examples show how to use org.jivesoftware.smack.roster.RosterEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmppMessageEngine.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves a contact list of the current XMPP user.
 * 
 * @return A set of object IDs from the {@link org.jivesoftware.smack.roster.Roster Roster} for this 
 * connection. In case of error it just returns empty set (not null).
 */
@Override
public Set<String> getRoster() {
	
	Set<String> rosterSet = new HashSet<String>();
	
	if (connection == null || !connection.isConnected()){
		logger.warning("Invalid connection in descriptor for username '" + objectId + "'.");
		return Collections.emptySet();
	}
	
	Collection<RosterEntry> entries = roster.getEntries();
	for (RosterEntry entry : entries) {
		rosterSet.add(entry.getJid().getLocalpartOrNull().toString());
	}
	
	return rosterSet;
}
 
Example #2
Source File: TransferGroupUI.java    From Spark with Apache License 2.0 6 votes vote down vote up
public TransferGroupUI(String groupName) {
    setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
    setBackground(Color.white);

    final Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
    final RosterGroup rosterGroup = roster.getGroup(groupName);

    final List<RosterEntry> entries = new ArrayList<RosterEntry>(rosterGroup.getEntries());

    Collections.sort(entries, entryComparator);

    for (RosterEntry entry : entries) {
        final UserEntry userEntry = new UserEntry(entry);
        userEntries.add(userEntry);
        add(userEntry);
    }
}
 
Example #3
Source File: ContactList.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Switches all users to Offline and Creates a Reconnection Group
    */
   private synchronized void switchAllUserOffline(final boolean onError)
   {
SwingWorker worker = new SwingWorker() {
    
    @Override
    public Object construct() { 
	mainPanel.add(_reconnectpanelsmall,0);	
	_reconnectpanelsmall.setClosedOnError(onError);
	final Collection<RosterEntry> roster = Roster.getInstanceFor( SparkManager.getConnection() ).getEntries();
	
	for(RosterEntry r : roster)
	{
	    Presence p = new Presence(Presence.Type.unavailable);
	    moveToOfflineGroup(p, r.getJid());
	}
	return true;
    }
};	
worker.start();
   }
 
Example #4
Source File: RosterExchange.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a roster entry to the packet.
 *
 * @param rosterEntry a roster entry to add.
 */
public void addRosterEntry(RosterEntry rosterEntry) {
    // Obtain a String[] from the roster entry groups name
    List<String> groupNamesList = new ArrayList<>();
    String[] groupNames;
    for (RosterGroup group : rosterEntry.getGroups()) {
        groupNamesList.add(group.getName());
    }
    groupNames = groupNamesList.toArray(new String[groupNamesList.size()]);

    // Create a new Entry based on the rosterEntry and add it to the packet
    RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getJid(),
            rosterEntry.getName(), groupNames);

    addRosterEntry(remoteRosterEntry);
}
 
Example #5
Source File: ContactList.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Removes a contact item from the group.
 *
 * @param item the ContactItem to remove.
 */
private void removeContactFromGroup(ContactItem item) {
    String groupName = item.getGroupName();
    ContactGroup contactGroup = getContactGroup(groupName);
    Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
    RosterEntry entry = roster.getEntry(item.getJid().asBareJid());
    if (entry != null && contactGroup != offlineGroup) {
        try {
            RosterGroup rosterGroup = roster.getGroup(groupName);
            if (rosterGroup != null) {
                RosterEntry rosterEntry = rosterGroup.getEntry(entry.getJid());
                if (rosterEntry != null) {
                    rosterGroup.removeEntry(rosterEntry);
                }
            }
            contactGroup.removeContactItem(contactGroup.getContactItemByJID(item.getJid()));
            checkGroup(contactGroup);
        }
        catch (Exception e) {
            Log.error("Error removing user from contact list.", e);
        }
    }
}
 
Example #6
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void doSetContactName(String address, String name) throws ImException {

    Contact contact = getContact(address);
    contact.setName(name);
    Contact[] contacts = {contact};
    notifyContactsPresenceUpdated(contacts);

    // set name
    try {
        RosterEntry entry = mRoster.getEntry(JidCreate.bareFrom(address));
        // confirm entry still exists
        if (entry == null) {
            return;
        }
        entry.setName(name);
    }
    catch (Exception e)
    {
        throw new ImException(e.toString());
    }
}
 
Example #7
Source File: ContactList.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Switches all Users to Offline and Creates an Icon in the CommandBar
    */
   private synchronized void switchAllUserOfflineNoGroupEntry(final boolean onError) {
SwingWorker worker = new SwingWorker() {
    @Override
    public Object construct() {
	_reconnectpanelicon.getPanel().add(_reconnectpanelicon.getButton(), 0);
	_reconnectpanelicon.getPanel().revalidate();
	_reconnectpanelicon.setClosedOnError(onError);
	final Collection<RosterEntry> roster = Roster.getInstanceFor( SparkManager.getConnection()).getEntries();
	for (RosterEntry r : roster) {
	    Presence p = new Presence(Presence.Type.unavailable);
	    moveToOfflineGroup(p, r.getJid());
	}
	return true;
    }
};
worker.start();
   }
 
Example #8
Source File: KonRosterListener.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
/**
 * NOTE: on every (re-)connect all entries are added again (loaded),
 * one method call for all contacts.
 */
@Override
public void entriesAdded(Collection<Jid> addresses) {
    if (mRoster == null || !mLoaded)
        return;

    for (Jid jid: addresses) {
        RosterEntry entry = mRoster.getEntry(jid.asBareJid());
        if (entry == null) {
            LOGGER.warning("jid not in roster: "+jid);
            return;
        }

        LOGGER.config("entry: "+entry.toString());
        mHandler.onEntryAdded(clientToModel(entry));
    }
}
 
Example #9
Source File: RosterExchangeManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a roster group to userID. All the entries of the group will be sent to the
 * target user.
 *
 * @param rosterGroup the roster group to send
 * @param targetUserID the user that will receive the roster entries
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void send(RosterGroup rosterGroup, Jid targetUserID) throws NotConnectedException, InterruptedException {
    XMPPConnection connection = weakRefConnection.get();

    // Create a new message to send the roster
    MessageBuilder msg = connection.getStanzaFactory().buildMessageStanza().to(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange();
    for (RosterEntry entry : rosterGroup.getEntries()) {
        rosterExchange.addRosterEntry(entry);
    }
    msg.addExtension(rosterExchange);

    // Send the message that contains the roster
    connection.sendStanza(msg.build());
}
 
Example #10
Source File: Client.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
public boolean removeFromRoster(JID jid) {
    if (!this.isConnected()) {
        LOGGER.info("not connected");
        return false;
    }
    Roster roster = Roster.getInstanceFor(mConn);
    RosterEntry entry = roster.getEntry(jid.toBareSmack());
    if (entry == null) {
        LOGGER.info("can't find roster entry for jid: "+jid);
        return true;
    }
    try {
        // blocking
        roster.removeEntry(entry);
    } catch (SmackException.NotLoggedInException |
            SmackException.NoResponseException |
            XMPPException.XMPPErrorException |
            SmackException.NotConnectedException |
            InterruptedException ex) {
        LOGGER.log(Level.WARNING, "can't remove contact from roster", ex);
        return false;
    }
    return true;
}
 
Example #11
Source File: Client.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
public void updateRosterEntry(JID jid, String newName) {
    if (!this.isConnected()) {
        LOGGER.info("not connected");
        return;
    }
    Roster roster = Roster.getInstanceFor(mConn);
    RosterEntry entry = roster.getEntry(jid.toBareSmack());
    if (entry == null) {
        LOGGER.warning("can't find roster entry for jid: "+jid);
        return;
    }
    try {
        entry.setName(newName);
    } catch (SmackException.NotConnectedException |
            SmackException.NoResponseException |
            XMPPException.XMPPErrorException |
            InterruptedException ex) {
        LOGGER.log(Level.WARNING, "can't set name for entry", ex);
    }
}
 
Example #12
Source File: UriManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
    * Handles the ?remove URI
    * 
    * @param uri
    *            the decoded uri
    * @throws Exception
    */
   public void handleRemove(URI uri) throws Exception {
// xmpp:[email protected]?remove

   BareJid jid;
   try {
       jid = JidCreate.bareFrom(retrieveJID(uri));
   } catch (XmppStringprepException e) {
       throw new IllegalStateException(e);
   }

   Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
RosterEntry entry = roster.getEntry(jid);
roster.removeEntry(entry);
   }
 
Example #13
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
public void removeAllContacts()
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }
    for (RosterEntry entry : roster.getEntries()) {
        roster.removeEntry(entry);
        Presence presence = new Presence(Presence.Type.unsubscribe);
        presence.setTo(entry.getJid());
        XMPPSession.getInstance().sendStanza(presence);
    }
}
 
Example #14
Source File: ContactList.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the users presence.
 *
 * @param presence the user to update.
 * @throws Exception if there is a problem while updating the user's presence.
 */
private synchronized void updateUserPresence(Presence presence) throws Exception {
    if (presence.getError() != null) {
        // We ignore this.
        return;
    }

    final Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );

    final BareJid bareJID = presence.getFrom().asBareJid();

    RosterEntry entry = roster.getEntry(bareJID);
    boolean isPending = entry != null && (entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from)
        && entry.isSubscriptionPending();

    // If online, check to see if they are in the offline group.
    // If so, remove from offline group and add to all groups they
    // belong to.

    if (presence.getType() == Presence.Type.available && offlineGroup.getContactItemByJID(bareJID) != null || ( presence.getFrom().toString().contains( "workgroup." ) )) {
        changeOfflineToOnline(bareJID, entry, presence);
    }
    else if (presence.getType() == Presence.Type.available) {
        updateContactItemsPresence(presence, entry, bareJID);
    }
    else if (presence.getType() == Presence.Type.unavailable && !isPending) {
        // If not available, move to offline group.
        Presence rosterPresence = PresenceManager.getPresence(bareJID);
        if (!rosterPresence.isAvailable()) {
            moveToOfflineGroup(presence, bareJID);
        }
        else {
            updateContactItemsPresence(rosterPresence, entry, bareJID);
        }
    }
    
}
 
Example #15
Source File: ContactList.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the presence of one individual based on their JID.
 *
 * @param presence the users presence.
 * @param entry    the roster entry being updated.
 * @param bareJID  the bare jid of the user.
 */
private void updateContactItemsPresence(Presence presence, RosterEntry entry, BareJid bareJID) {
    for (ContactGroup group : groupList) {
        ContactItem item = group.getContactItemByJID(bareJID);
        if (item != null) {
            if (group == offlineGroup) {
                changeOfflineToOnline(bareJID, entry, presence);
                continue;
            }
            item.setPresence(presence);
            group.fireContactGroupUpdated();
        }
    }
}
 
Example #16
Source File: ContactList.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Called when NEW entries are added.
 *
 * @param addresses the address added.
 */
@Override
public void entriesAdded(final Collection<Jid> addresses) {
    SwingUtilities.invokeLater( () -> {
        Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );

        for (Jid jid : addresses) {
            RosterEntry entry = roster.getEntry(jid.asBareJid());
            addUser(entry);
        }
    } );
}
 
Example #17
Source File: ContactList.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a single user to the ContactList.
 *
 * @param entry the <code>RosterEntry</code> of the the user.
 */
private void addUser(RosterEntry entry) {
    ContactItem newContactItem = UIComponentRegistry.createContactItem(entry.getName(), null, entry.getJid());

    if (entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from) {
        // Ignore, since the new user is pending to be added.
        for (RosterGroup group : entry.getGroups()) {
            ContactGroup contactGroup = getContactGroup(group.getName());
            if (contactGroup == null) {
                contactGroup = addContactGroup(group.getName());
            }

            boolean isPending = entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from
                && entry.isSubscriptionPending();
            if (isPending) {
                contactGroup.setVisible(true);
            }
            contactGroup.addContactItem(newContactItem);

        }
        return;
    }
    else {
        moveToOffline(newContactItem);
    }

    // Update users icon
    Presence presence = Roster.getInstanceFor( SparkManager.getConnection() ).getPresence(entry.getJid());
    try {
        updateUserPresence(presence);
    }
    catch (Exception e) {
        Log.error(e);
    }
}
 
Example #18
Source File: ContactList.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void removeContactFromRoster(ContactItem item) {
    Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
    RosterEntry entry = roster.getEntry(item.getJid().asBareJid());
    if (entry != null) {
        try {
            roster.removeEntry(entry);
        }
        catch (XMPPException | SmackException | InterruptedException e) {
            Log.warning("Unable to remove roster entry.", e);
        }
    }
}
 
Example #19
Source File: OTRPrefPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void loadRemoteKeys() {

        for (RosterEntry entry : Roster.getInstanceFor( SparkManager.getConnection() ).getEntries()) {
            SessionID curSession = new SessionID(SparkManager.getConnection().getUser(), entry.getUser(), "Scytale");
            String remoteKey = _keyManager.getRemoteFingerprint(curSession);
            if (remoteKey != null) {
                boolean isVerified = _keyManager.isVerified(curSession);
                _keytable.addEntry(entry.getUser(), remoteKey, isVerified);
            }
        }

        _keytable.addTableChangeListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent e) {
                int col = e.getColumn();
                int row = e.getFirstRow();

                if (col == 2) {
                    boolean selection = (Boolean) _keytable.getValueAt(row, col);
                    String JID = (String) _keytable.getValueAt(row, 0);
                    SessionID curSelectedSession = new SessionID(SparkManager.getConnection().getUser(), JID, "Scytale");
                    if (!selection) {
                        _keyManager.verify(curSelectedSession);
                    } else {
                        _keyManager.unverify(curSelectedSession);
                    }
                }
            }
        });

    }
 
Example #20
Source File: SoftPhonePlugin.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void loadVCards() {
    // Load vCard information.
    final Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
    for (RosterEntry entry : roster.getEntries()) {
        SparkManager.getVCardManager().getVCardFromMemory(entry.getUser());
    }
}
 
Example #21
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
public HashMap<Jid, Presence.Type> getContacts()
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }

    String groupName = "Buddies";

    RosterGroup group = roster.getGroup(groupName);

    if (group == null) {
        roster.createGroup(groupName);
        group = roster.getGroup(groupName);
    }

    HashMap<Jid, Presence.Type> buddies = new HashMap<>();

    List<RosterEntry> entries = group.getEntries();
    for (RosterEntry entry : entries) {
        BareJid jid = entry.getJid();
        Presence.Type status = roster.getPresence(jid).getType();
        buddies.put(jid, status);
    }

    return buddies;
}
 
Example #22
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
public HashMap<Jid, Presence.Type> getContactsWithSubscriptionPending()
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }

    String groupName = "Buddies";

    RosterGroup group = roster.getGroup(groupName);

    if (group == null) {
        roster.createGroup(groupName);
        group = roster.getGroup(groupName);
    }

    HashMap<Jid, Presence.Type> buddiesPending = new HashMap<>();

    List<RosterEntry> entries = group.getEntries();
    for (RosterEntry entry : entries) {
        if (entry.isSubscriptionPending()) {
            BareJid jid = entry.getJid();
            Presence.Type status = roster.getPresence(jid).getType();
            buddiesPending.put(jid, status);
        }
    }

    return buddiesPending;
}
 
Example #23
Source File: MucManager.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public List<RosterEntry> getEntriesByGroup(Roster roster, String groupName) {
    List<RosterEntry> entriesList = new ArrayList<RosterEntry>();
    RosterGroup rosterGroup = roster.getGroup(groupName);
    Collection<RosterEntry> rosterEntries = rosterGroup.getEntries();
    Iterator<RosterEntry> i = rosterEntries.iterator();
    while (i.hasNext()) {
        entriesList.add(i.next());
    }
    return entriesList;
}
 
Example #24
Source File: OmemoManagerSetupHelper.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static void cleanUpRoster(OmemoManager omemoManager) {
    Roster roster = Roster.getInstanceFor(omemoManager.getConnection());
    for (RosterEntry r : roster.getEntries()) {
        try {
            roster.removeEntry(r);
        } catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException |
                XMPPException.XMPPErrorException | SmackException.NotLoggedInException e) {
            // Silent
        }
    }
}
 
Example #25
Source File: RosterExchange.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new roster exchange package with the entries specified in roster.
 *
 * @param roster the roster to send to other XMPP entity.
 */
public RosterExchange(Roster roster) {
    // Add all the roster entries to the new RosterExchange
    for (RosterEntry rosterEntry : roster.getEntries()) {
        this.addRosterEntry(rosterEntry);
    }
}
 
Example #26
Source File: RosterExchangeManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a roster entry to userID.
 *
 * @param rosterEntry the roster entry to send
 * @param targetUserID the user that will receive the roster entries
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void send(RosterEntry rosterEntry, Jid targetUserID) throws NotConnectedException, InterruptedException {
    XMPPConnection connection = weakRefConnection.get();

    // Create a new message to send the roster
    MessageBuilder messageBuilder = connection.getStanzaFactory().buildMessageStanza().to(targetUserID);
    // Create a RosterExchange Package and add it to the message
    RosterExchange rosterExchange = new RosterExchange();
    rosterExchange.addRosterEntry(rosterEntry);
    messageBuilder.addExtension(rosterExchange);

    // Send the message that contains the roster
    connection.sendStanza(messageBuilder.build());
}
 
Example #27
Source File: KonRosterListener.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void entriesUpdated(Collection<Jid> addresses) {
    // note: we don't know what exactly changed here
    for (Jid jid: addresses) {
        RosterEntry entry = mRoster.getEntry(jid.asBareJid());
        if (entry == null) {
            LOGGER.warning("jid not in roster: "+jid);
            return;
        }

        LOGGER.info("entry: "+entry.toString());
        mHandler.onEntryUpdate(clientToModel(entry));
    }
}
 
Example #28
Source File: KonRosterListener.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRosterLoaded(Roster roster) {
    Set<RosterEntry> entries = roster.getEntries();
    LOGGER.info("loading "+entries.size()+" entries");

    mHandler.onLoaded(entries.stream()
            .map(KonRosterListener::clientToModel)
            .collect(Collectors.toList()));
    mLoaded = true;
}
 
Example #29
Source File: IntegrationTestRosterUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static void notInRoster(XMPPConnection c1, XMPPConnection c2) throws NotLoggedInException,
        NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Roster roster = Roster.getInstanceFor(c1);
    RosterEntry c2Entry = roster.getEntry(c2.getUser().asBareJid());
    if (c2Entry == null) {
        return;
    }
    roster.removeEntry(c2Entry);
}
 
Example #30
Source File: ContactList.java    From Spark with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
       if (e.getSource() == addingGroupButton) {
           new RosterDialog().showRosterDialog();
       }
       else if (e.getSource() == chatMenu) {
           if (activeItem != null) {
               SparkManager.getChatManager().activateChat(activeItem.getJid(), activeItem.getDisplayName());
           }
       }
       else if (e.getSource() == addContactMenu) {
           RosterDialog rosterDialog = new RosterDialog();
           if (activeGroup != null) {
               rosterDialog.setDefaultGroup(activeGroup);
           }
           rosterDialog.showRosterDialog();
       }
       else if (e.getSource() == removeContactFromGroupMenu) {
           if (activeItem != null) {
               removeContactFromGroup(activeItem);
           }
       }
       else if (e.getSource() == renameMenu) {
           if (activeItem == null) {
               return;
           }

           String oldAlias = activeItem.getAlias();
           String newAlias = JOptionPane.showInputDialog(this, Res.getString("label.rename.to") + ":", oldAlias);
           
           // if user pressed 'cancel', output will be null.
       	// if user removed alias, output will be an empty String.
           if (newAlias != null) {
            if (!ModelUtil.hasLength(newAlias)) {
            	newAlias = null; // allows you to remove an alias.
            }
            
            BareJid address = activeItem.getJid().asBareJid();
            ContactGroup contactGroup = getContactGroup(activeItem.getGroupName());
            ContactItem contactItem = contactGroup.getContactItemByDisplayName(activeItem.getDisplayName());
            contactItem.setAlias(newAlias);

            final Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
            RosterEntry entry = roster.getEntry(address);
               try
               {
                   entry.setName(newAlias);

                   final BareJid user = address.asBareJid();
                   for ( ContactGroup cg : groupList ) {
                       ContactItem ci = cg.getContactItemByJID(user);
                       if (ci != null) {
                           ci.setAlias(newAlias);
                       }
                   }
               }
               catch ( XMPPException.XMPPErrorException| SmackException.NotConnectedException | SmackException.NoResponseException | InterruptedException e1 )
               {
                   Log.warning( "Unable to set new alias '" + newAlias + "' for roster entry " + address, e1 );
               }
           }
       }
   }