Search in sources :

Example 1 with IRosterItem

use of org.eclipse.ecf.presence.roster.IRosterItem in project ecf by eclipse.

the class XMPPContainerPresenceHelper method countClientsInRosterGroup.

private int countClientsInRosterGroup(org.eclipse.ecf.presence.roster.RosterGroup group, XMPPID oldID) {
    Collection groupItems = group.getEntries();
    int count = 0;
    for (final Iterator i = groupItems.iterator(); i.hasNext(); ) {
        final IRosterItem item = (IRosterItem) i.next();
        if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
            org.eclipse.ecf.presence.roster.RosterEntry entry = (org.eclipse.ecf.presence.roster.RosterEntry) item;
            XMPPID entryID = (XMPPID) entry.getUser().getID();
            if (entryID.getUsernameAtHost().equals(oldID.getUsernameAtHost()))
                count++;
        }
    }
    return count;
}
Also used : IRosterItem(org.eclipse.ecf.presence.roster.IRosterItem) Iterator(java.util.Iterator) Collection(java.util.Collection) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry) RosterEntry(org.jivesoftware.smack.RosterEntry) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID)

Example 2 with IRosterItem

use of org.eclipse.ecf.presence.roster.IRosterItem in project ecf by eclipse.

the class XMPPContainerPresenceHelper method updatePresence.

private void updatePresence(XMPPID fromID, IPresence newPresence) {
    final Collection rosterItems = roster.getItems();
    List newEntrys = new ArrayList();
    synchronized (rosterItems) {
        for (final Iterator i = roster.getItems().iterator(); i.hasNext(); ) {
            final IRosterItem item = (IRosterItem) i.next();
            if (item instanceof IRosterGroup) {
                AdditionalClientRosterEntry[] es = updatePresenceInGroup((IRosterGroup) item, fromID, newPresence);
                for (int j = 0; j < es.length; j++) {
                    newEntrys.add(es[j]);
                }
            } else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
                AdditionalClientRosterEntry entry = updatePresenceForMatchingEntry((org.eclipse.ecf.presence.roster.RosterEntry) item, fromID, newPresence);
                if (entry != null)
                    newEntrys.add(entry);
            }
        }
    }
    AdditionalClientRosterEntry[] entrys = (AdditionalClientRosterEntry[]) newEntrys.toArray(new AdditionalClientRosterEntry[] {});
    if (entrys.length > 0) {
        for (int i = 0; i < entrys.length; i++) {
            if (entrys[i].add) {
                IRosterEntry entry = new org.eclipse.ecf.presence.roster.RosterEntry(entrys[i].parent, entrys[i].user, entrys[i].presence);
                addUniqueToRoster(new IRosterItem[] { entry });
                fireSetRosterEntry(false, entry);
            } else {
                removeItemFromRoster(rosterItems, fromID);
            }
        }
    }
}
Also used : IRosterItem(org.eclipse.ecf.presence.roster.IRosterItem) ArrayList(java.util.ArrayList) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry) RosterEntry(org.jivesoftware.smack.RosterEntry) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry)

Example 3 with IRosterItem

use of org.eclipse.ecf.presence.roster.IRosterItem in project ecf by eclipse.

the class XMPPContainerPresenceHelper method removeItemFromRoster.

private void removeItemFromRoster(Collection rosterItems, XMPPID itemIDToRemove) {
    boolean removed = false;
    synchronized (rosterItems) {
        for (final Iterator i = rosterItems.iterator(); i.hasNext(); ) {
            final IRosterItem item = (IRosterItem) i.next();
            if (item instanceof org.eclipse.ecf.presence.roster.RosterGroup) {
                final org.eclipse.ecf.presence.roster.RosterGroup group = (org.eclipse.ecf.presence.roster.RosterGroup) item;
                removed = removeItemFromRosterGroup(group, itemIDToRemove);
                // If group is empty, remove it too
                if (group.getEntries().size() == 0)
                    i.remove();
            } else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
                if (((org.eclipse.ecf.presence.roster.RosterEntry) item).getUser().getID().equals(itemIDToRemove)) {
                    i.remove();
                    removed = true;
                }
            }
        }
    }
    if (removed)
        rosterManager.notifyRosterUpdate(roster);
}
Also used : RosterGroup(org.eclipse.ecf.presence.roster.RosterGroup) IRosterItem(org.eclipse.ecf.presence.roster.IRosterItem) Iterator(java.util.Iterator) RosterGroup(org.eclipse.ecf.presence.roster.RosterGroup) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup)

Example 4 with IRosterItem

use of org.eclipse.ecf.presence.roster.IRosterItem in project ecf by eclipse.

the class XMPPContainerPresenceHelper method createRosterEntries.

private IRosterItem[] createRosterEntries(Iterator grps, IRosterItem parent, IUser user) {
    final List result = new ArrayList();
    if (grps.hasNext()) {
        for (; grps.hasNext(); ) {
            final Object o = grps.next();
            // Get group name
            final String groupName = (o instanceof String) ? (String) o : ((RosterGroup) o).getName();
            if (groupName == null || groupName.equals("")) {
                createRosterEntries(parent, user, result);
                continue;
            }
            // See if group is already in roster
            org.eclipse.ecf.presence.roster.RosterGroup rosterGroup = findRosterGroup(parent, groupName);
            // Set flag if not
            final boolean groupFound = rosterGroup != null;
            if (!groupFound)
                rosterGroup = new org.eclipse.ecf.presence.roster.RosterGroup(parent, groupName);
            if (findRosterEntry(rosterGroup, user) == null) {
                // Now create new roster entry
                new org.eclipse.ecf.presence.roster.RosterEntry(rosterGroup, user, new org.eclipse.ecf.presence.Presence(IPresence.Type.UNAVAILABLE, IPresence.Type.UNAVAILABLE.toString(), IPresence.Mode.AWAY));
            }
            // Only add localGrp if not already in list
            if (!groupFound)
                result.add(rosterGroup);
        }
    } else
        createRosterEntries(parent, user, result);
    return (IRosterItem[]) result.toArray(new IRosterItem[] {});
}
Also used : RosterGroup(org.eclipse.ecf.presence.roster.RosterGroup) IRosterItem(org.eclipse.ecf.presence.roster.IRosterItem) ArrayList(java.util.ArrayList) RosterGroup(org.eclipse.ecf.presence.roster.RosterGroup) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) List(java.util.List) ArrayList(java.util.ArrayList) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry) RosterEntry(org.jivesoftware.smack.RosterEntry)

Example 5 with IRosterItem

use of org.eclipse.ecf.presence.roster.IRosterItem in project ecf by eclipse.

the class RosterWriterHelper method showRosterItems.

private void showRosterItems(IRosterItem rosterItem) {
    if (rosterItem == null)
        return;
    Collection children = null;
    if (rosterItem instanceof IRoster) {
        System.out.println("Roster: " + rosterItem.getName());
        children = ((IRoster) rosterItem).getItems();
    } else if (rosterItem instanceof IRosterGroup) {
        System.out.println("  Group: " + rosterItem.getName());
        children = ((IRosterGroup) rosterItem).getEntries();
    } else if (rosterItem instanceof IRosterEntry) {
        System.out.println("    Entry: " + rosterItem.getName());
        System.out.println("     Type: " + ((IRosterEntry) rosterItem).getPresence().getType());
        children = null;
    }
    if (children != null) {
        for (Iterator i = children.iterator(); i.hasNext(); ) showRosterItems((IRosterItem) i.next());
    }
}
Also used : IRosterItem(org.eclipse.ecf.presence.roster.IRosterItem) IRoster(org.eclipse.ecf.presence.roster.IRoster) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) Iterator(java.util.Iterator) Collection(java.util.Collection) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry)

Aggregations

IRosterItem (org.eclipse.ecf.presence.roster.IRosterItem)7 Iterator (java.util.Iterator)6 Collection (java.util.Collection)5 IRosterEntry (org.eclipse.ecf.presence.roster.IRosterEntry)5 IRosterGroup (org.eclipse.ecf.presence.roster.IRosterGroup)5 RosterEntry (org.jivesoftware.smack.RosterEntry)4 RosterGroup (org.eclipse.ecf.presence.roster.RosterGroup)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)2 IContainer (org.eclipse.ecf.core.IContainer)1 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)1 IPresenceContainerAdapter (org.eclipse.ecf.presence.IPresenceContainerAdapter)1 IRoster (org.eclipse.ecf.presence.roster.IRoster)1 IRosterManager (org.eclipse.ecf.presence.roster.IRosterManager)1