MUCAdmin.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.muc.packet;
  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.jivesoftware.smack.packet.IQ;

  22. /**
  23.  * IQ stanza that serves for kicking users, granting and revoking voice, banning users,
  24.  * modifying the ban list, granting and revoking membership and granting and revoking
  25.  * moderator privileges. All these operations are scoped by the
  26.  * 'http://jabber.org/protocol/muc#admin' namespace.
  27.  *
  28.  * @author Gaston Dombiak
  29.  */
  30. public class MUCAdmin extends IQ {

  31.     public static final String ELEMENT = QUERY_ELEMENT;
  32.     public static final String NAMESPACE = MUCInitialPresence.NAMESPACE + "#admin";

  33.     private final List<MUCItem> items = new ArrayList<>();

  34.     public MUCAdmin() {
  35.         super(ELEMENT, NAMESPACE);
  36.     }

  37.     /**
  38.      * Returns a List of item children that holds information about roles, affiliation,
  39.      * jids and nicks.
  40.      *
  41.      * @return a List of item children that holds information about roles, affiliation,
  42.      *          jids and nicks.
  43.      */
  44.     public List<MUCItem> getItems() {
  45.         synchronized (items) {
  46.             return Collections.unmodifiableList(new ArrayList<>(items));
  47.         }
  48.     }

  49.     /**
  50.      * Adds an item child that holds information about roles, affiliation, jids and nicks.
  51.      *
  52.      * @param item the item child that holds information about roles, affiliation, jids and nicks.
  53.      */
  54.     public void addItem(MUCItem item) {
  55.         synchronized (items) {
  56.             items.add(item);
  57.         }
  58.     }

  59.     @Override
  60.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  61.         xml.rightAngleBracket();

  62.         synchronized (items) {
  63.             for (MUCItem item : items) {
  64.                 xml.append(item.toXML());
  65.             }
  66.         }

  67.         return xml;
  68.     }
  69. }