当前位置: 首页>>代码示例>>Java>>正文


Java Presence.getChildElement方法代码示例

本文整理汇总了Java中org.xmpp.packet.Presence.getChildElement方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.getChildElement方法的具体用法?Java Presence.getChildElement怎么用?Java Presence.getChildElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xmpp.packet.Presence的用法示例。


在下文中一共展示了Presence.getChildElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addParticipant

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
@Override
public Presence addParticipant(JID jid, String reason, MUCRole senderRole)
        throws NotAllowedException, ForbiddenException {
    if (MUCRole.Role.moderator != senderRole.getRole()) {
        throw new ForbiddenException();
    }
    // Update the presence with the new role and inform all occupants
    Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.participant);
    if (updatedPresence != null) {
        Element frag = updatedPresence.getChildElement(
                "x", "http://jabber.org/protocol/muc#user");
        // Add the reason why the user was granted voice
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }
    }
    return updatedPresence;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:19,代码来源:LocalMUCRoom.java

示例2: kickOccupant

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
@Override
public Presence kickOccupant(JID jid, JID actorJID, String actorNickname, String reason)
        throws NotAllowedException {
    // Update the presence with the new role and inform all occupants
    Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.none);
    if (updatedPresence != null) {
        Element frag = updatedPresence.getChildElement(
                "x", "http://jabber.org/protocol/muc#user");

        // Add the status code 307 that indicates that the user was kicked
        frag.addElement("status").addAttribute("code", "307");
        // Add the reason why the user was kicked
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }

        // Effectively kick the occupant from the room
        kickPresence(updatedPresence, actorJID, actorNickname);

        //Inform the other occupants that user has been kicked
        broadcastPresence(updatedPresence, false);
    }
    return updatedPresence;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:25,代码来源:LocalMUCRoom.java

示例3: broadcast

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void broadcast(BroadcastPresenceRequest presenceRequest) {
    String jid = null;
    Presence presence = presenceRequest.getPresence();
    Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
    // Don't include the occupant's JID if the room is semi-anon and the new occupant
    // is not a moderator
    if (!canAnyoneDiscoverJID()) {
        jid = frag.element("item").attributeValue("jid");
    }
    for (MUCRole occupant : occupants.values()) {
        if (!occupant.isLocal()) {
            continue;
        }
        // Don't include the occupant's JID if the room is semi-anon and the new occupant
        // is not a moderator
        if (!canAnyoneDiscoverJID()) {
            if (MUCRole.Role.moderator == occupant.getRole()) {
                frag.element("item").addAttribute("jid", jid);
            }
            else {
                frag.element("item").addAttribute("jid", null);
            }
        }
        occupant.send(presence);
    }
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:27,代码来源:LocalMUCRoom.java

示例4: addParticipant

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public Presence addParticipant(JID jid, String reason, MUCRole senderRole)
        throws NotAllowedException, ForbiddenException {
    if (MUCRole.Role.moderator != senderRole.getRole()) {
        throw new ForbiddenException();
    }
    // Update the presence with the new role and inform all occupants
    Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.participant);
    if (updatedPresence != null) {
        Element frag = updatedPresence.getChildElement(
                "x", "http://jabber.org/protocol/muc#user");
        // Add the reason why the user was granted voice
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }
    }
    return updatedPresence;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:18,代码来源:LocalMUCRoom.java

示例5: kickOccupant

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public Presence kickOccupant(JID jid, JID actorJID, String reason)
        throws NotAllowedException {
    // Update the presence with the new role and inform all occupants
    Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.none);
    if (updatedPresence != null) {
        Element frag = updatedPresence.getChildElement(
                "x", "http://jabber.org/protocol/muc#user");

        // Add the status code 307 that indicates that the user was kicked
        frag.addElement("status").addAttribute("code", "307");
        // Add the reason why the user was kicked
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }

        // Effectively kick the occupant from the room
        kickPresence(updatedPresence, actorJID);
    }
    return updatedPresence;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:21,代码来源:LocalMUCRoom.java

示例6: kickOccupant

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public Presence kickOccupant(JID jid, JID actorJID, String reason)
        throws NotAllowedException {
    // Update the presence with the new role and inform all occupants
    Presence updatedPresence = changeOccupantRole(jid, MUCRole.Role.none);
    if (updatedPresence != null) {
        Element frag = updatedPresence.getChildElement(
                "x", "http://jabber.org/protocol/muc#user");

        // Add the status code 307 that indicates that the user was kicked
        frag.addElement("status").addAttribute("code", "307");
        // Add the reason why the user was kicked
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }

        // Effectively kick the occupant from the room
        kickPresence(updatedPresence, actorJID);
        
        //Inform the other occupants that user has been kicked
        broadcastPresence(updatedPresence, false);
    }
    return updatedPresence;
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:24,代码来源:LocalMUCRoom.java

示例7: updatePresence

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
 * Updates the presence of the AgentSession with the new received presence. The max number of
 * chats and number of current chats will be updated if that information was included in the presence.
 * If no information was provided then default values of queues, workgroups or general settings will
 * be used instead.
 *
 * @param packet the new presence sent by the agent.
 */
public void updatePresence(Presence packet) {
    // Create a copy of the received Presence to use as the presence of the AgentSession
    Presence sessionPresence = packet.createCopy();
    // Remove the "agent-status" element from the new AgentSession's presence
    Element child = sessionPresence.getChildElement("agent-status", "http://jabber.org/protocol/workgroup");
    sessionPresence.getElement().remove(child);
    // Set the new presence to the AgentSession
    presence = sessionPresence;

    // Set the new maximum number of chats and the number of current chats to the
    // AgentSession based on the values sent within the presence (if any)
    Element elem = packet.getChildElement("agent-status", "http://jabber.org/protocol/workgroup");
    if (elem != null) {
        Iterator<Element> metaIter = elem.elementIterator();
        while (metaIter.hasNext()) {
            Element agentStatusElement = metaIter.next();
            if ("max-chats".equals(agentStatusElement.getName())) {
                String maxChats = agentStatusElement.getText();
                if (maxChats == null || maxChats.trim().length() == 0) {
                    setMaxChats(-1);
                }
                else {
                    setMaxChats(Integer.parseInt(maxChats));
                }
            }
        }
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:37,代码来源:AgentSession.java

示例8: shouldBroadcastPresence

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
 * Checks the role of the sender and returns true if the given presence should be broadcasted
 * 
 * @param presence The presence to check
 * @return true if the presence should be broadcast to the rest of the room
 */
private boolean shouldBroadcastPresence(Presence presence){
    if (presence == null) {
        return false;
    }
    if (hasToCheckRoleToBroadcastPresence()) {
        Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
        // Check if we can broadcast the presence for this role
        if (!canBroadcastPresence(frag.element("item").attributeValue("role"))) {
            return false;
        }
    }
    return true;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:20,代码来源:LocalMUCRoom.java

示例9: process

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void process(Presence packet) {
      // Ignore unavailable presences
      if (Presence.Type.unavailable == packet.getType()) {
          return;
      }

      // Examine the packet and check if it has caps info,
      // if not -- do nothing by returning.
      Element capsElement = packet.getChildElement("c", "http://jabber.org/protocol/caps");
      if (capsElement == null) {
          return;
      }

      // Examine the packet and check if it's in legacy format (pre version 1.4
      // of XEP-0115). If so, do nothing by returning.
// TODO: if this packet is in legacy format, we SHOULD check the 'node',
// 'ver', and 'ext' combinations as specified in the archived version
// 1.3 of the specification, and cache the results. See JM-1447
      final String hashAttribute = capsElement.attributeValue("hash");
      if (hashAttribute == null || hashAttribute.trim().length() == 0) {
          return;
      }
      
      // Examine the packet and check if it has and a 'ver' hash
      // if not -- do nothing by returning.
      final String newVerAttribute = capsElement.attributeValue("ver");
      if (newVerAttribute == null || newVerAttribute.trim().length() == 0) {
          return;
      }

      // Check to see if the 'ver' hash is already in our cache.
      if (isInCapsCache(newVerAttribute)) {
          // The 'ver' hash is in the cache already, so let's update the
          // entityCapabilitiesUserMap for the user that sent the caps
          // packet.
          entityCapabilitiesUserMap.put(packet.getFrom(), newVerAttribute);
      }
      else {
          // The 'ver' hash is not in the cache so send out a disco#info query
          // so that we may begin recognizing this 'ver' hash.
          IQ iq = new IQ(IQ.Type.get);
          iq.setTo(packet.getFrom());

          String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
          iq.setFrom(serverName);

          iq.setChildElement("query", "http://jabber.org/protocol/disco#info");

          String packetId = iq.getID();
          
          final EntityCapabilities caps = new EntityCapabilities();
          caps.setHashAttribute(hashAttribute);
          caps.setVerAttribute(newVerAttribute);
          verAttributes.put(packetId, caps);

          final IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();
          iqRouter.addIQResultListener(packetId, this);
          iqRouter.route(iq);
      }
  }
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:61,代码来源:EntityCapabilitiesManager.java

示例10: broadcast

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void broadcast(BroadcastPresenceRequest presenceRequest) {
    String jid = null;
    Presence presence = presenceRequest.getPresence();
    JID to = presence.getTo();
    Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
    // Don't include the occupant's JID if the room is semi-anon and the new occupant
    // is not a moderator
    if (!canAnyoneDiscoverJID()) {
        jid = frag.element("item").attributeValue("jid");
    }
    for (MUCRole occupant : occupantsByFullJID.values()) {
        if (!occupant.isLocal()) {
            continue;
        }
        // Don't include the occupant's JID if the room is semi-anon and the new occupant
        // is not a moderator
        if (!canAnyoneDiscoverJID()) {
            if (MUCRole.Role.moderator == occupant.getRole()) {
                frag.element("item").addAttribute("jid", jid);
            }
            else {
                frag.element("item").addAttribute("jid", null);
            }
        }
        // Some status codes should only be included in the "self-presence", which is only sent to the user, but not to other occupants.
        if (occupant.getPresence().getFrom().equals(to)) {
            Presence selfPresence = presence.createCopy();
            Element fragSelfPresence = selfPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
            fragSelfPresence.addElement("status").addAttribute("code", "110");

            // Only in the context of entering the room status code 100, 201 and 210 should be sent.
            // http://xmpp.org/registrar/mucstatus.html
            if (presenceRequest.isJoinPresence()) {
                boolean isRoomNew = isLocked() && creationDate.getTime() == lockedTime;
                if (canAnyoneDiscoverJID()) {
                    // // XEP-0045: Example 26.
                    // If the user is entering a room that is non-anonymous (i.e., which informs all occupants of each occupant's full JID as shown above), the service MUST warn the user by including a status code of "100" in the initial presence that the room sends to the new occupant
                    fragSelfPresence.addElement("status").addAttribute("code", "100");
                }
                if (isRoomNew) {
                    fragSelfPresence.addElement("status").addAttribute("code", "201");
                }
            }

            occupant.send(selfPresence);
        } else {
            occupant.send(presence);
        }
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:51,代码来源:LocalMUCRoom.java

示例11: process

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void process(Presence packet) {
    // Ignore unavailable presences
    if (Presence.Type.unavailable == packet.getType()) {
        return;
    }

    // Examine the packet and check if it has caps info,
    // if not -- do nothing by returning.
    Element capsElement = packet.getChildElement("c", "http://jabber.org/protocol/caps");
    if (capsElement == null) {
        return;
    }

    // Examine the packet and check if it's in legacy format (pre version 1.4
    // of XEP-0115). If so, do nothing by returning.
    // TODO: if this packet is in legacy format, we SHOULD check the 'node',
    // 'ver', and 'ext' combinations as specified in the archived version
    // 1.3 of the specification, and cache the results. See JM-1447
    final String hashAttribute = capsElement.attributeValue("hash");
    if (hashAttribute == null || hashAttribute.trim().length() == 0) {
        return;
    }
    
    // Examine the packet and check if it has and a 'ver' hash
    // if not -- do nothing by returning.
    final String newVerAttribute = capsElement.attributeValue("ver");
    if (newVerAttribute == null || newVerAttribute.trim().length() == 0) {
        return;
    }

    // Check to see if the 'ver' hash is already in our cache.
    if (isInCapsCache(newVerAttribute)) {
        // The 'ver' hash is in the cache already, so let's update the
        // entityCapabilitiesUserMap for the user that sent the caps
        // packet.
        entityCapabilitiesUserMap.put(packet.getFrom(), newVerAttribute);
    }
    else {
        // The 'ver' hash is not in the cache so send out a disco#info query
        // so that we may begin recognizing this 'ver' hash.
        IQ iq = new IQ(IQ.Type.get);
        iq.setTo(packet.getFrom());

        String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
        iq.setFrom(serverName);

        iq.setChildElement("query", "http://jabber.org/protocol/disco#info");

        String packetId = iq.getID();
        
        final EntityCapabilities caps = new EntityCapabilities();
        caps.setHashAttribute(hashAttribute);
        caps.setVerAttribute(newVerAttribute);
        verAttributes.put(packetId, caps);

        final IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();
        iqRouter.addIQResultListener(packetId, this);
        iqRouter.route(iq);
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:61,代码来源:EntityCapabilitiesManager.java

示例12: addOutcast

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public List<Presence> addOutcast(JID jid, String reason, MUCRole senderRole)
        throws NotAllowedException, ForbiddenException, ConflictException {
    lock.writeLock().lock();
    try {
        MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
        if (MUCRole.Affiliation.admin != senderRole.getAffiliation()
                && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
            throw new ForbiddenException();
        }
        // Check that the room always has an owner
        if (owners.contains(jid.toBareJID()) && owners.size() == 1) {
            throw new ConflictException();
        }
        // Check if user is already an outcast
        if (outcasts.contains(jid.toBareJID())) {
            // Do nothing
            return Collections.emptyList();
        }

        // Update the affiliation lists
        outcasts.add(jid.toBareJID());
        // Remove the user from other affiliation lists
        if (removeOwner(jid.toBareJID())) {
            oldAffiliation = MUCRole.Affiliation.owner;
        }
        else if (removeAdmin(jid.toBareJID())) {
            oldAffiliation = MUCRole.Affiliation.admin;
        }
        else if (removeMember(jid.toBareJID())) {
            oldAffiliation = MUCRole.Affiliation.member;
        }
        // Update the DB if the room is persistent
        MUCPersistenceManager.saveAffiliationToDB(
            this,
            jid.toBareJID(),
            null,
            MUCRole.Affiliation.outcast,
            oldAffiliation);
    }
    finally {
        lock.writeLock().unlock();
    }
    // Update the presence with the new affiliation and inform all occupants
    // actorJID will be null if the room itself (ie. via admin console) made the request
    JID actorJID = senderRole.getUserAddress();
    List<Presence> updatedPresences = changeOccupantAffiliation(
            jid,
            MUCRole.Affiliation.outcast,
            MUCRole.Role.none);
    Element frag;
    // Add the status code and reason why the user was banned to the presences that will
    // be sent to the room occupants (the banned user will not receive this presences)
    for (Presence presence : updatedPresences) {
        frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
        // Add the status code 301 that indicates that the user was banned
        frag.addElement("status").addAttribute("code", "301");
        // Add the reason why the user was banned
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }

        // Remove the banned users from the room. If a user has joined the room from
        // different client resources, he/she will be kicked from all the client resources
        // Effectively kick the occupant from the room
        kickPresence(presence, actorJID);
    }
    return updatedPresences;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:69,代码来源:LocalMUCRoom.java

示例13: addNone

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public List<Presence> addNone(JID jid, MUCRole senderRole) throws ForbiddenException,
        ConflictException {
    List<Presence> updatedPresences = null;
    boolean wasMember = false;
    lock.writeLock().lock();
    try {
        MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
        if (MUCRole.Affiliation.admin != senderRole.getAffiliation()
                && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
            throw new ForbiddenException();
        }
        // Check that the room always has an owner
        if (owners.contains(jid.toBareJID()) && owners.size() == 1) {
            throw new ConflictException();
        }
        wasMember = members.containsKey(jid.toBareJID()) || admins.contains(jid.toBareJID()) || owners.contains(jid.toBareJID());
        // Remove the user from ALL the affiliation lists
        if (removeOwner(jid.toBareJID())) {
            oldAffiliation = MUCRole.Affiliation.owner;
        }
        else if (removeAdmin(jid.toBareJID())) {
            oldAffiliation = MUCRole.Affiliation.admin;
        }
        else if (removeMember(jid.toBareJID())) {
            oldAffiliation = MUCRole.Affiliation.member;
        }
        else if (removeOutcast(jid.toBareJID())) {
            oldAffiliation = MUCRole.Affiliation.outcast;
        }
        // Remove the affiliation of this user from the DB if the room is persistent
        MUCPersistenceManager.removeAffiliationFromDB(this, jid.toBareJID(), oldAffiliation);
    }
    finally {
        lock.writeLock().unlock();
    }
    // Update the presence with the new affiliation and inform all occupants
    try {
        MUCRole.Role newRole;
        if (isMembersOnly() && wasMember) {
            newRole = MUCRole.Role.none;
        }
        else {
            newRole = isModerated() ? MUCRole.Role.visitor : MUCRole.Role.participant;
        }
        updatedPresences = changeOccupantAffiliation(jid, MUCRole.Affiliation.none, newRole);
        if (isMembersOnly() && wasMember) {
            // If the room is members-only, remove the user from the room including a status
            // code of 321 to indicate that the user was removed because of an affiliation
            // change
            Element frag;
            // Add the status code to the presences that will be sent to the room occupants
            for (Presence presence : updatedPresences) {
                // Set the presence as an unavailable presence
                presence.setType(Presence.Type.unavailable);
                presence.setStatus(null);
                frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
                // Add the status code 321 that indicates that the user was removed because of
                // an affiliation change
                frag.addElement("status").addAttribute("code", "321");

                // Remove the ex-member from the room. If a user has joined the room from
                // different client resources, he/she will be kicked from all the client
                // resources.
                // Effectively kick the occupant from the room
                JID actorJID = senderRole.getUserAddress();
                kickPresence(presence, actorJID);
            }
        }
    }
    catch (NotAllowedException e) {
        // We should never receive this exception....in theory
    }
    return updatedPresences;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:75,代码来源:LocalMUCRoom.java

示例14: broadcast

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void broadcast(BroadcastPresenceRequest presenceRequest) {
    String jid = null;
    Presence presence = presenceRequest.getPresence();
    Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
    // Don't include the occupant's JID if the room is semi-anon and the new occupant
    // is not a moderator
    if (!canAnyoneDiscoverJID()) {
        jid = frag.element("item").attributeValue("jid");
    }
    for (MUCRole occupant : occupantsByFullJID.values()) {
        if (!occupant.isLocal()) {
            continue;
        }
        // Don't include the occupant's JID if the room is semi-anon and the new occupant
        // is not a moderator
        if (!canAnyoneDiscoverJID()) {
            if (MUCRole.Role.moderator == occupant.getRole()) {
                frag.element("item").addAttribute("jid", jid);
            }
            else {
                frag.element("item").addAttribute("jid", null);
            }
        }
        // Some status codes should only be included in the "self-presence", which is only sent to the user, but not to other occupants.
        if (occupant.getPresence().getFrom().equals(presence.getTo())) {
            Presence selfPresence = presence.createCopy();
            Element fragSelfPresence = selfPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
            fragSelfPresence.addElement("status").addAttribute("code", "110");

            // Only in the context of entering the room status code 100, 201 and 210 should be sent.
            // http://xmpp.org/registrar/mucstatus.html
            if (presenceRequest.isJoinPresence()) {
                boolean isRoomNew = isLocked() && creationDate.getTime() == lockedTime;
                if (canAnyoneDiscoverJID()) {
                    // // XEP-0045: Example 26.
                    // If the user is entering a room that is non-anonymous (i.e., which informs all occupants of each occupant's full JID as shown above), the service MUST warn the user by including a status code of "100" in the initial presence that the room sends to the new occupant
                    fragSelfPresence.addElement("status").addAttribute("code", "100");
                }
                if (isRoomNew) {
                    fragSelfPresence.addElement("status").addAttribute("code", "201");
                }
            }

            occupant.send(selfPresence);
        } else {
            occupant.send(presence);
        }
    }
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:50,代码来源:LocalMUCRoom.java

示例15: addOutcast

import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public List<Presence> addOutcast(JID jid, String reason, MUCRole senderRole)
        throws NotAllowedException, ForbiddenException, ConflictException {
    final JID bareJID = jid.asBareJID();
    lock.writeLock().lock();
    try {
        MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
        if (MUCRole.Affiliation.admin != senderRole.getAffiliation()
                && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
            throw new ForbiddenException();
        }
        // Check that the room always has an owner
        if (owners.contains(bareJID) && owners.size() == 1) {
            throw new ConflictException();
        }
        // Check if user is already an outcast
        if (outcasts.contains(bareJID)) {
            // Do nothing
            return Collections.emptyList();
        }

        // Update the affiliation lists
        outcasts.add(bareJID);
        // Remove the user from other affiliation lists
        if (removeOwner(bareJID)) {
            oldAffiliation = MUCRole.Affiliation.owner;
        }
        else if (removeAdmin(bareJID)) {
            oldAffiliation = MUCRole.Affiliation.admin;
        }
        else if (removeMember(bareJID)) {
            oldAffiliation = MUCRole.Affiliation.member;
        }
        // Update the DB if the room is persistent
        MUCPersistenceManager.saveAffiliationToDB(
            this,
            bareJID,
            null,
            MUCRole.Affiliation.outcast,
            oldAffiliation);
    }
    finally {
        lock.writeLock().unlock();
    }
    // Update other cluster nodes with new affiliation
    CacheFactory.doClusterTask(new AddAffiliation(this, jid.toBareJID(), MUCRole.Affiliation.outcast));
    // Update the presence with the new affiliation and inform all occupants
    // actorJID will be null if the room itself (ie. via admin console) made the request
    JID actorJID = senderRole.getUserAddress();
    List<Presence> updatedPresences = changeOccupantAffiliation(
            jid,
            MUCRole.Affiliation.outcast,
            MUCRole.Role.none);
    Element frag;
    // Add the status code and reason why the user was banned to the presences that will
    // be sent to the room occupants (the banned user will not receive this presences)
    for (Presence presence : updatedPresences) {
        frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
        // Add the status code 301 that indicates that the user was banned
        frag.addElement("status").addAttribute("code", "301");
        // Add the reason why the user was banned
        if (reason != null && reason.trim().length() > 0) {
            frag.element("item").addElement("reason").setText(reason);
        }

        // Remove the banned users from the room. If a user has joined the room from
        // different client resources, he/she will be kicked from all the client resources
        // Effectively kick the occupant from the room
        kickPresence(presence, actorJID);
    }
    return updatedPresences;
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:72,代码来源:LocalMUCRoom.java


注:本文中的org.xmpp.packet.Presence.getChildElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。