Collection<String> getSharedUsersForRoster(Group group, Roster roster) { String showInRoster = group.getProperties().get("sharedRoster.showInRoster"); String groupNames = group.getProperties().get("sharedRoster.groupList"); // Answer an empty collection if the group is not being shown in users' rosters if (!"onlyGroup".equals(showInRoster) && !"everybody".equals(showInRoster)) { return new ArrayList<String>(); } // Add the users of the group Collection<String> users = new HashSet<String>(group.getMembers()); users.addAll(group.getAdmins()); // Check if anyone can see this shared group if ("everybody".equals(showInRoster)) { // If the user of the roster belongs to the public group then we should return all users // in the system since they all need to be in the roster with subscription "from" if (group.isUser(roster.getUsername())) { // Add all users in the system for (User user : UserManager.getInstance().getUsers()) { users.add(user.getUsername()); } } } else { // Add the users that may see the group Collection<Group> groupList = parseGroups(groupNames); for (Group groupInList : groupList) { users.addAll(groupInList.getMembers()); users.addAll(groupInList.getAdmins()); } } return users; }