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;
}
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);
}
}
}
}
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);
}
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[] {});
}
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());
}
}
Aggregations