Java 类org.jivesoftware.smackx.muc.packet.MUCUser 实例源码

项目:Smack    文件:MultiUserChat.java   
/**
 * Like {@link #create(String)}, but will return true if the room creation was acknowledged by
 * the service (with an 201 status code). It's up to the caller to decide, based on the return
 * value, if he needs to continue sending the room configuration. If false is returned, the room
 * already existed and the user is able to join right away, without sending a form.
 *
 * @param nickname the nickname to use.
 * @param password the password to use.
 * @param history the amount of discussion history to receive while joining a room.
 * @param timeout the amount of time to wait for a reply from the MUC service(in milliseconds).
 * @return true if the room creation was acknowledged by the service, false otherwise.
 * @throws XMPPErrorException if the room couldn't be created for some reason (e.g. 405 error if
 *         the user is not allowed to create the room)
 * @throws NoResponseException if there was no response from the server.
 */
public synchronized boolean createOrJoin(String nickname, String password, DiscussionHistory history, long timeout)
                throws NoResponseException, XMPPErrorException, SmackException {
    if (joined) {
        throw new IllegalStateException("Creation failed - User already joined the room.");
    }

    Presence presence = enter(nickname, password, history, timeout);

    // Look for confirmation of room creation from the server
    MUCUser mucUser = MUCUser.from(presence);
    if (mucUser != null && mucUser.getStatus().contains(Status.ROOM_CREATED_201)) {
        // Room was created and the user has joined the room
        return true;
    }
    return false;
}
项目:Smack    文件:MUCUserProvider.java   
private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException {
    boolean done = false;
    MUCUser.Invite invite = new MUCUser.Invite();
    invite.setFrom(parser.getAttributeValue("", "from"));
    invite.setTo(parser.getAttributeValue("", "to"));
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("reason")) {
                invite.setReason(parser.nextText());
            }
        }
        else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("invite")) {
                done = true;
            }
        }
    }
    return invite;
}
项目:Smack    文件:MUCUserProvider.java   
private static MUCUser.Decline parseDecline(XmlPullParser parser) throws XmlPullParserException, IOException {
    boolean done = false;
    MUCUser.Decline decline = new MUCUser.Decline();
    decline.setFrom(parser.getAttributeValue("", "from"));
    decline.setTo(parser.getAttributeValue("", "to"));
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("reason")) {
                decline.setReason(parser.nextText());
            }
        }
        else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("decline")) {
                done = true;
            }
        }
    }
    return decline;
}
项目:Smack    文件:MultiUserChatManager.java   
private MultiUserChatManager(XMPPConnection connection) {
    super(connection);
    // Listens for all messages that include a MUCUser extension and fire the invitation
    // listeners if the message includes an invitation.
    StanzaListener invitationPacketListener = new StanzaListener() {
        public void processPacket(Stanza packet) {
            final Message message = (Message) packet;
            // Get the MUCUser extension
            final MUCUser mucUser = MUCUser.from(message);
            // Check if the MUCUser extension includes an invitation
            if (mucUser.getInvite() != null) {
                // Fire event for invitation listeners
                final MultiUserChat muc = getMultiUserChat(packet.getFrom());
                for (final InvitationListener listener : invitationsListeners) {
                    listener.invitationReceived(connection(), muc, mucUser.getInvite().getFrom(),
                                    mucUser.getInvite().getReason(), mucUser.getPassword(), message);
                }
            }
        }
    };
    connection.addAsyncStanzaListener(invitationPacketListener, INVITATION_FILTER);
}
项目:Smack    文件:Occupant.java   
Occupant(Presence presence) {
    MUCUser mucUser = (MUCUser) presence.getExtension("x",
            "http://jabber.org/protocol/muc#user");
    MUCItem item = mucUser.getItem();
    this.jid = item.getJid();
    this.affiliation = item.getAffiliation();
    this.role = item.getRole();
    // Get the nickname from the FROM attribute of the presence
    this.nick = XmppStringUtils.parseResource(presence.getFrom());
}
项目:Smack    文件:MUCUserProvider.java   
/**
 * Parses a MUCUser 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 MUCUser parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
    MUCUser mucUser = new MUCUser();
    outerloop: while (true) {
        switch (parser.next()) {
        case XmlPullParser.START_TAG:
            switch (parser.getName()) {
            case "invite":
                mucUser.setInvite(parseInvite(parser));
                break;
            case "item":
                mucUser.setItem(MUCParserUtils.parseItem(parser));
                break;
            case "password":
                mucUser.setPassword(parser.nextText());
                break;
            case "status":
                String statusString = parser.getAttributeValue("", "code");
                mucUser.addStatusCode(MUCUser.Status.create(statusString));
                break;
            case "decline":
                mucUser.setDecline(parseDecline(parser));
                break;
            case "destroy":
                mucUser.setDestroy(MUCParserUtils.parseDestroy(parser));
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        }
    }

    return mucUser;
}
项目:Smack    文件:Workgroup.java   
private void handlePacket(Stanza packet) {
    if (packet instanceof Message) {
        Message msg = (Message)packet;
        // Check to see if the user left the queue.
        ExtensionElement pe = msg.getExtension("depart-queue", "http://jabber.org/protocol/workgroup");
        ExtensionElement queueStatus = msg.getExtension("queue-status", "http://jabber.org/protocol/workgroup");

        if (pe != null) {
            fireQueueDepartedEvent();
        }
        else if (queueStatus != null) {
            QueueUpdate queueUpdate = (QueueUpdate)queueStatus;
            if (queueUpdate.getPosition() != -1) {
                fireQueuePositionEvent(queueUpdate.getPosition());
            }
            if (queueUpdate.getRemaingTime() != -1) {
                fireQueueTimeEvent(queueUpdate.getRemaingTime());
            }
        }

        else {
            // Check if a room invitation was sent and if the sender is the workgroup
            MUCUser mucUser = (MUCUser)msg.getExtension("x", "http://jabber.org/protocol/muc#user");
            MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null;
            if (invite != null && workgroupJID.equals(invite.getFrom())) {
                String sessionID = null;
                Map<String, List<String>> metaData = null;

                pe = msg.getExtension(SessionID.ELEMENT_NAME,
                        SessionID.NAMESPACE);
                if (pe != null) {
                    sessionID = ((SessionID)pe).getSessionID();
                }

                pe = msg.getExtension(MetaData.ELEMENT_NAME,
                        MetaData.NAMESPACE);
                if (pe != null) {
                    metaData = ((MetaData)pe).getMetaData();
                }

                WorkgroupInvitation inv = new WorkgroupInvitation(connection.getUser(), msg.getFrom(),
                        workgroupJID, sessionID, msg.getBody(),
                        msg.getFrom(), metaData);

                fireInvitationEvent(inv);
            }
        }
    }
}