コード例 #1
0
 protected void createRoom(Map<String, Object> roomSpec, String serviceName) throws Exception {
   List<String> owners = (List) roomSpec.get("owners");
   JID owner = XMPPServer.getInstance().createJID("admin", null);
   if (owners != null && owners.size() > 0) {
     owner = new JID(owners.get(0));
   } else {
     owners = new ArrayList<String>();
     owners.add(owner.toBareJID());
     roomSpec.put("owners", owners);
   }
   String roomName = (String) roomSpec.get("roomName");
   Boolean isPersistent = (Boolean) roomSpec.get("persistent");
   MUCRoom room =
       XMPPServer.getInstance()
           .getMultiUserChatManager()
           .getMultiUserChatService(serviceName)
           .getChatRoom(roomName.toLowerCase(), owner);
   IntrospectionSupport.setProperties(room, roomSpec);
   room.setRolesToBroadcastPresence(new ArrayList<String>());
   setRoles(room, roomSpec);
   room.setCreationDate(new Date());
   room.setModificationDate(new Date());
   // Unlock the room, because the default configuration lock the room.
   room.unlock(room.getRole());
   System.out.println("isPersistent:" + isPersistent);
   if (isPersistent == null) {
     room.setPersistent(true);
   }
   if (room.isPersistent()) {
     room.saveToDB();
   }
 }
コード例 #2
0
 private void setRoles(MUCRoom room, Map<String, Object> roomSpec) throws Exception {
   List<JID> roles = new ArrayList<JID>();
   Collection<JID> owners = new ArrayList<JID>();
   Collection<JID> existingOwners = new ArrayList<JID>();
   List<String> specOwners = (List) roomSpec.get("owners");
   List<String> specAdmins = (List) roomSpec.get("admins");
   List<String> specMembers = (List) roomSpec.get("members");
   List<String> specOutcasts = (List) roomSpec.get("outcasts");
   List<JID> mucRoomEntityOwners = convertStringsToJIDs(specOwners);
   owners.addAll(room.getOwners());
   // Find same owners
   for (JID jid : owners) {
     if (mucRoomEntityOwners.contains(jid)) {
       existingOwners.add(jid);
     }
   }
   // Don't delete the same owners
   owners.removeAll(existingOwners);
   room.addOwners(convertStringsToJIDs(specOwners), room.getRole());
   // Collect all roles to reset
   roles.addAll(owners);
   roles.addAll(room.getAdmins());
   roles.addAll(room.getMembers());
   roles.addAll(room.getOutcasts());
   for (JID jid : roles) {
     room.addNone(jid, room.getRole());
   }
   room.addOwners(convertStringsToJIDs(specOwners), room.getRole());
   if (specAdmins != null) {
     room.addAdmins(convertStringsToJIDs(specAdmins), room.getRole());
   }
   if (specMembers != null) {
     for (String memberJid : specMembers) {
       room.addMember(new JID(memberJid), null, room.getRole());
     }
   }
   if (specOutcasts != null) {
     for (String outcastJid : specOutcasts) {
       room.addOutcast(new JID(outcastJid), null, room.getRole());
     }
   }
 }