mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-12 19:02:06 +01:00
Removed the setters methods from RemoteRosterEntry
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2069 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
78289e848b
commit
bceff343af
5 changed files with 34 additions and 51 deletions
|
@ -50,7 +50,7 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.packet;
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -67,18 +67,22 @@ public class RemoteRosterEntry {
|
|||
|
||||
private String user;
|
||||
private String name;
|
||||
private List groupNames;
|
||||
private List groupNames = new ArrayList();
|
||||
|
||||
/**
|
||||
* Creates a new remote roster entry.
|
||||
*
|
||||
* @param user the user.
|
||||
* @param name the user's name.
|
||||
* @param groups the list of group names the entry will belong to, or <tt>null</tt> if the
|
||||
* the roster entry won't belong to a group.
|
||||
*/
|
||||
public RemoteRosterEntry(String user, String name) {
|
||||
public RemoteRosterEntry(String user, String name, String [] groups) {
|
||||
this.user = user;
|
||||
this.name = name;
|
||||
groupNames = new ArrayList();
|
||||
if (groups != null) {
|
||||
groupNames = new ArrayList(Arrays.asList(groups));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,15 +103,6 @@ public class RemoteRosterEntry {
|
|||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user's name.
|
||||
*
|
||||
* @param name the user's name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator for the group names (as Strings) that the roster entry
|
||||
* belongs to.
|
||||
|
@ -135,30 +130,6 @@ public class RemoteRosterEntry {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a group name.
|
||||
*
|
||||
* @param groupName the group name.
|
||||
*/
|
||||
public void addGroupName(String groupName) {
|
||||
synchronized (groupNames) {
|
||||
if (!groupNames.contains(groupName)) {
|
||||
groupNames.add(groupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a group name.
|
||||
*
|
||||
* @param groupName the group name.
|
||||
*/
|
||||
public void removeGroupName(String groupName) {
|
||||
synchronized (groupNames) {
|
||||
groupNames.remove(groupName);
|
||||
}
|
||||
}
|
||||
|
||||
public String toXML() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("<item jid=\"").append(user).append("\"");
|
|
@ -56,6 +56,7 @@ import java.util.*;
|
|||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smackx.*;
|
||||
|
||||
/**
|
||||
* Represents XMPP Roster Item Exchange packets.<p>
|
||||
|
@ -106,14 +107,17 @@ public class RosterExchange implements PacketExtension {
|
|||
* @param rosterEntry a roster entry to add.
|
||||
*/
|
||||
public void addRosterEntry(RosterEntry rosterEntry) {
|
||||
RosterGroup rosterGroup = null;
|
||||
// Obtain a String[] from the roster entry groups name
|
||||
ArrayList groupNamesList = new ArrayList();
|
||||
String[] groupNames;
|
||||
for (Iterator groups = rosterEntry.getGroups(); groups.hasNext();) {
|
||||
groupNamesList.add(((RosterGroup) groups.next()).getName());
|
||||
}
|
||||
groupNames = (String[]) 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.getUser(), rosterEntry.getName());
|
||||
// Add the entry groups to the Entry
|
||||
for (Iterator groups = rosterEntry.getGroups(); groups.hasNext();) {
|
||||
rosterGroup = (RosterGroup) groups.next();
|
||||
remoteRosterEntry.addGroupName(rosterGroup.getName());
|
||||
}
|
||||
RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getUser(), rosterEntry.getName(), groupNames);
|
||||
|
||||
addRosterEntry(remoteRosterEntry);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,11 @@
|
|||
|
||||
package org.jivesoftware.smackx.provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smackx.*;
|
||||
import org.jivesoftware.smackx.packet.*;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
|
@ -84,21 +87,26 @@ public class RosterExchangeProvider implements PacketExtensionProvider {
|
|||
RosterExchange rosterExchange = new RosterExchange();
|
||||
boolean done = false;
|
||||
RemoteRosterEntry remoteRosterEntry = null;
|
||||
String jid = "";
|
||||
String name = "";
|
||||
ArrayList groupsName = new ArrayList();
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (parser.getName().equals("item")) {
|
||||
String jid = parser.getAttributeValue("", "jid");
|
||||
String name = parser.getAttributeValue("", "name");
|
||||
// Create packet.
|
||||
remoteRosterEntry = new RemoteRosterEntry(jid, name);
|
||||
// Reset this variable since they are optional for each item
|
||||
groupsName = new ArrayList();
|
||||
// Initialize the variables from the parsed XML
|
||||
jid = parser.getAttributeValue("", "jid");
|
||||
name = parser.getAttributeValue("", "name");
|
||||
}
|
||||
if (parser.getName().equals("group")) {
|
||||
String groupName = parser.nextText();
|
||||
remoteRosterEntry.addGroupName(groupName);
|
||||
groupsName.add(parser.nextText());
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals("item")) {
|
||||
// Create packet.
|
||||
remoteRosterEntry = new RemoteRosterEntry(jid, name, (String[]) groupsName.toArray(new String[groupsName.size()]));
|
||||
rosterExchange.addRosterEntry(remoteRosterEntry);
|
||||
}
|
||||
if (parser.getName().equals("x")) {
|
||||
|
|
|
@ -57,7 +57,6 @@ import java.util.Iterator;
|
|||
import junit.framework.TestCase;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smackx.packet.RemoteRosterEntry;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Iterator;
|
|||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smackx.*;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
Loading…
Reference in a new issue