Search in sources :

Example 6 with MUCOwner

use of org.jivesoftware.smackx.packet.MUCOwner in project ecf by eclipse.

the class MultiUserChat method destroy.

/**
 * Sends a request to the server to destroy the room. The sender of the request
 * should be the room's owner. If the sender of the destroy request is not the room's owner
 * then the server will answer a "Forbidden" error (403).
 *
 * @param reason the reason for the room destruction.
 * @param alternateJID the JID of an alternate location.
 * @throws XMPPException if an error occurs while trying to destroy the room.
 *      An error can occur which will be wrapped by an XMPPException --
 *      XMPP error code 403. The error code can be used to present more
 *      appropiate error messages to end-users.
 */
public void destroy(String reason, String alternateJID) throws XMPPException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.SET);
    // Create the reason for the room destruction
    MUCOwner.Destroy destroy = new MUCOwner.Destroy();
    destroy.setReason(reason);
    destroy.setJid(alternateJID);
    iq.setDestroy(destroy);
    // Wait for a presence packet back from the server.
    PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Send the room destruction request.
    connection.sendPacket(iq);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();
    if (answer == null) {
        throw new XMPPException("No response from server.");
    } else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    // Reset occupant information.
    occupantsMap.clear();
    nickname = null;
    joined = false;
    userHasLeft();
}
Also used : PacketFilter(org.jivesoftware.smack.filter.PacketFilter) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) MUCOwner(org.jivesoftware.smackx.packet.MUCOwner) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 7 with MUCOwner

use of org.jivesoftware.smackx.packet.MUCOwner in project ecf by eclipse.

the class MUCOwnerProvider method parseIQ.

public IQ parseIQ(XmlPullParser parser) throws Exception {
    MUCOwner mucOwner = new MUCOwner();
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("item")) {
                mucOwner.addItem(parseItem(parser));
            } else if (parser.getName().equals("destroy")) {
                mucOwner.setDestroy(parseDestroy(parser));
            } else // Otherwise, it must be a packet extension.
            {
                mucOwner.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return mucOwner;
}
Also used : MUCOwner(org.jivesoftware.smackx.packet.MUCOwner)

Aggregations

MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)7 PacketCollector (org.jivesoftware.smack.PacketCollector)6 XMPPException (org.jivesoftware.smack.XMPPException)6 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)6 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)6 IQ (org.jivesoftware.smack.packet.IQ)5 ArrayList (java.util.ArrayList)1