Search in sources :

Example 1 with RosterGroup

use of org.eclipse.ecf.presence.roster.RosterGroup 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 2 with RosterGroup

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

the class XMPPContainerPresenceHelper method createRosterEntry.

protected IRosterEntry createRosterEntry(ID userID, String name, Iterator grps) {
    final List groups = new ArrayList();
    for (; grps.hasNext(); ) {
        final Object o = grps.next();
        final String groupName = (o instanceof String) ? (String) o : ((RosterGroup) o).getName();
        final IRosterGroup localGrp = new org.eclipse.ecf.presence.roster.RosterGroup(roster, groupName);
        groups.add(localGrp);
    }
    final IUser user = new User(userID, name);
    IRosterEntry newEntry = null;
    if (groups.size() == 0)
        return new org.eclipse.ecf.presence.roster.RosterEntry(roster, user, new org.eclipse.ecf.presence.Presence(IPresence.Type.UNAVAILABLE, IPresence.Type.UNAVAILABLE.toString(), IPresence.Mode.AWAY));
    else
        for (int i = 0; i < groups.size(); i++) {
            final IRosterGroup grp = (IRosterGroup) groups.get(i);
            if (i == 0)
                newEntry = new org.eclipse.ecf.presence.roster.RosterEntry(grp, user, null);
            else {
                grp.getEntries().add(newEntry);
                newEntry.getGroups().add(grp);
            }
        }
    return newEntry;
}
Also used : User(org.eclipse.ecf.core.user.User) IUser(org.eclipse.ecf.core.user.IUser) ArrayList(java.util.ArrayList) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) RosterGroup(org.eclipse.ecf.presence.roster.RosterGroup) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) IUser(org.eclipse.ecf.core.user.IUser) IPresence(org.eclipse.ecf.presence.IPresence) Presence(org.jivesoftware.smack.packet.Presence) List(java.util.List) ArrayList(java.util.ArrayList) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)2 IRosterEntry (org.eclipse.ecf.presence.roster.IRosterEntry)2 IRosterGroup (org.eclipse.ecf.presence.roster.IRosterGroup)2 RosterGroup (org.eclipse.ecf.presence.roster.RosterGroup)2 IUser (org.eclipse.ecf.core.user.IUser)1 User (org.eclipse.ecf.core.user.User)1 IPresence (org.eclipse.ecf.presence.IPresence)1 IRosterItem (org.eclipse.ecf.presence.roster.IRosterItem)1 RosterEntry (org.jivesoftware.smack.RosterEntry)1 Presence (org.jivesoftware.smack.packet.Presence)1