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

项目:Smack    文件:MultiUserChat.java   
/**
 * Returns a collection of <code>Affiliate</code> that have the specified room affiliation
 * sending a request in the admin namespace.
 *
 * @param affiliation the affiliation of the users in the room.
 * @return a collection of <code>Affiliate</code> that have the specified room affiliation.
 * @throws XMPPErrorException if you don't have enough privileges to get this information.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException 
 */
private List<Affiliate> getAffiliatesByAdmin(MUCAffiliation affiliation) throws NoResponseException, XMPPErrorException, NotConnectedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.get);
    // Set the specified affiliation. This may request the list of owners/admins/members/outcasts.
    MUCItem item = new MUCItem(affiliation);
    iq.addItem(item);

    MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();

    // Get the list of affiliates from the server's answer
    List<Affiliate> affiliates = new ArrayList<Affiliate>();
    for (MUCItem mucadminItem : answer.getItems()) {
        affiliates.add(new Affiliate(mucadminItem));
    }
    return affiliates;
}
项目:Smack    文件:MultiUserChat.java   
/**
 * Returns a list of <code>Occupant</code> that have the specified room role.
 *
 * @param role the role of the occupant in the room.
 * @return a list of <code>Occupant</code> that have the specified room role.
 * @throws XMPPErrorException if an error occured while performing the request to the server or you
 *         don't have enough privileges to get this information.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException 
 */
private List<Occupant> getOccupants(MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.get);
    // Set the specified role. This may request the list of moderators/participants.
    MUCItem item = new MUCItem(role);
    iq.addItem(item);

    MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
    // Get the list of participants from the server's answer
    List<Occupant> participants = new ArrayList<Occupant>();
    for (MUCItem mucadminItem : answer.getItems()) {
        participants.add(new Occupant(mucadminItem));
    }
    return participants;
}
项目: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    文件:MultiUserChat.java   
/**
 * Tries to change the affiliation with an 'muc#admin' namespace
 *
 * @param jid
 * @param affiliation
 * @param reason the reason for the affiliation change (optional)
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 * @throws NotConnectedException 
 */
private void changeAffiliationByAdmin(String jid, MUCAffiliation affiliation, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException
        {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    // Set the new affiliation.
    MUCItem item = new MUCItem(affiliation, jid, reason);
    iq.addItem(item);

    connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
项目:Smack    文件:MultiUserChat.java   
private void changeAffiliationByAdmin(Collection<String> jids, MUCAffiliation affiliation)
                throws NoResponseException, XMPPErrorException, NotConnectedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    for (String jid : jids) {
        // Set the new affiliation.
        MUCItem item = new MUCItem(affiliation, jid);
        iq.addItem(item);
    }

    connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
项目:Smack    文件:MultiUserChat.java   
private void changeRole(String nickname, MUCRole role, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    // Set the new role.
    MUCItem item = new MUCItem(role, nickname, reason);
    iq.addItem(item);

    connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
项目:Smack    文件:MultiUserChat.java   
private void changeRole(Collection<String> nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException  {
    MUCAdmin iq = new MUCAdmin();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    for (String nickname : nicknames) {
        // Set the new role.
        MUCItem item = new MUCItem(role, nickname);
        iq.addItem(item);
    }

    connection.createPacketCollectorAndSend(iq).nextResultOrThrow();
}
项目:Smack    文件:MUCParserUtils.java   
public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
    int initialDepth = parser.getDepth();
    MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
    String nick = parser.getAttributeValue("", "nick");
    MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
    String jid = parser.getAttributeValue("", "jid");
    String actor = null;
    String reason = null;
    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            switch (name) {
            case "actor":
                actor = parser.getAttributeValue("", "jid");
                break;
            case "reason":
                reason = parser.nextText();
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        }
    }
    return new MUCItem(affiliation, role, actor, reason, jid, nick);
}
项目:Smack    文件:Occupant.java   
Occupant(MUCItem item) {
    this.jid = item.getJid();
    this.affiliation = item.getAffiliation();
    this.role = item.getRole();
    this.nick = item.getNick();
}
项目:Smack    文件:Affiliate.java   
Affiliate(MUCItem item) {
    this.jid = item.getJid();
    this.affiliation = item.getAffiliation();
    this.role = item.getRole();
    this.nick = item.getNick();
}