use of org.jivesoftware.smackx.xroster.packet.RosterExchange in project Smack by igniterealtime.
the class RosterExchangeManager method send.
/**
* Sends a roster entry to userID.
*
* @param rosterEntry the roster entry to send
* @param targetUserID the user that will receive the roster entries
* @throws NotConnectedException
* @throws InterruptedException
*/
public void send(RosterEntry rosterEntry, Jid targetUserID) throws NotConnectedException, InterruptedException {
// Create a new message to send the roster
Message msg = new Message(targetUserID);
// Create a RosterExchange Package and add it to the message
RosterExchange rosterExchange = new RosterExchange();
rosterExchange.addRosterEntry(rosterEntry);
msg.addExtension(rosterExchange);
XMPPConnection connection = weakRefConnection.get();
// Send the message that contains the roster
connection.sendStanza(msg);
}
use of org.jivesoftware.smackx.xroster.packet.RosterExchange in project Smack by igniterealtime.
the class RosterExchangeProvider method parse.
/**
* Parses a RosterExchange stanza(/packet) (extension sub-packet).
*
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @throws IOException
* @throws XmlPullParserException
*/
@Override
public RosterExchange parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
// CHECKSTYLE:OFF
RosterExchange rosterExchange = new RosterExchange();
boolean done = false;
RemoteRosterEntry remoteRosterEntry = null;
Jid jid = null;
String name = "";
ArrayList<String> groupsName = new ArrayList<String>();
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
// Reset this variable since they are optional for each item
groupsName = new ArrayList<String>();
// Initialize the variables from the parsed XML
jid = ParserUtils.getJidAttribute(parser);
name = parser.getAttributeValue("", "name");
}
if (parser.getName().equals("group")) {
groupsName.add(parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("item")) {
// Create packet.
remoteRosterEntry = new RemoteRosterEntry(jid, name, groupsName.toArray(new String[groupsName.size()]));
rosterExchange.addRosterEntry(remoteRosterEntry);
}
if (parser.getName().equals("x")) {
done = true;
}
}
}
// CHECKSTYLE:ON
return rosterExchange;
}
use of org.jivesoftware.smackx.xroster.packet.RosterExchange in project Smack by igniterealtime.
the class RosterExchangeManager method send.
/**
* Sends a roster to userID. All the entries of the roster will be sent to the
* target user.
*
* @param roster the roster to send
* @param targetUserID the user that will receive the roster entries
* @throws NotConnectedException
* @throws InterruptedException
*/
public void send(Roster roster, Jid targetUserID) throws NotConnectedException, InterruptedException {
// Create a new message to send the roster
Message msg = new Message(targetUserID);
// Create a RosterExchange Package and add it to the message
RosterExchange rosterExchange = new RosterExchange(roster);
msg.addExtension(rosterExchange);
XMPPConnection connection = weakRefConnection.get();
// Send the message that contains the roster
connection.sendStanza(msg);
}
use of org.jivesoftware.smackx.xroster.packet.RosterExchange in project Smack by igniterealtime.
the class RosterExchangeManager method send.
/**
* Sends a roster group to userID. All the entries of the group will be sent to the
* target user.
*
* @param rosterGroup the roster group to send
* @param targetUserID the user that will receive the roster entries
* @throws NotConnectedException
* @throws InterruptedException
*/
public void send(RosterGroup rosterGroup, Jid targetUserID) throws NotConnectedException, InterruptedException {
// Create a new message to send the roster
Message msg = new Message(targetUserID);
// Create a RosterExchange Package and add it to the message
RosterExchange rosterExchange = new RosterExchange();
for (RosterEntry entry : rosterGroup.getEntries()) {
rosterExchange.addRosterEntry(entry);
}
msg.addExtension(rosterExchange);
XMPPConnection connection = weakRefConnection.get();
// Send the message that contains the roster
connection.sendStanza(msg);
}
Aggregations