Search in sources :

Example 1 with RosterExchange

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);
}
Also used : RosterExchange(org.jivesoftware.smackx.xroster.packet.RosterExchange) Message(org.jivesoftware.smack.packet.Message) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 2 with RosterExchange

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;
}
Also used : RosterExchange(org.jivesoftware.smackx.xroster.packet.RosterExchange) Jid(org.jxmpp.jid.Jid) ArrayList(java.util.ArrayList) RemoteRosterEntry(org.jivesoftware.smackx.xroster.RemoteRosterEntry)

Example 3 with 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);
}
Also used : RosterExchange(org.jivesoftware.smackx.xroster.packet.RosterExchange) Message(org.jivesoftware.smack.packet.Message) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 4 with RosterExchange

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);
}
Also used : RosterExchange(org.jivesoftware.smackx.xroster.packet.RosterExchange) Message(org.jivesoftware.smack.packet.Message) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Aggregations

RosterExchange (org.jivesoftware.smackx.xroster.packet.RosterExchange)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 Message (org.jivesoftware.smack.packet.Message)3 ArrayList (java.util.ArrayList)1 RosterEntry (org.jivesoftware.smack.roster.RosterEntry)1 RemoteRosterEntry (org.jivesoftware.smackx.xroster.RemoteRosterEntry)1 Jid (org.jxmpp.jid.Jid)1