MUCLightCreateIQ.java

  1. /**
  2.  *
  3.  * Copyright 2016 Fernando Ramirez
  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.muclight.element;

  18. import java.util.HashMap;
  19. import java.util.List;

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

  21. import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
  22. import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
  23. import org.jivesoftware.smackx.muclight.MultiUserChatLight;
  24. import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationElement;
  25. import org.jivesoftware.smackx.muclight.element.MUCLightElements.OccupantsElement;

  26. import org.jxmpp.jid.EntityJid;
  27. import org.jxmpp.jid.Jid;

  28. /**
  29.  * MUCLight create IQ class.
  30.  *
  31.  * @author Fernando Ramirez
  32.  *
  33.  */
  34. public class MUCLightCreateIQ extends IQ {

  35.     public static final String ELEMENT = QUERY_ELEMENT;
  36.     public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CREATE;

  37.     private MUCLightRoomConfiguration configuration;
  38.     private final HashMap<Jid, MUCLightAffiliation> occupants;

  39.     /**
  40.      * MUCLight create IQ constructor.
  41.      *
  42.      * @param room TODO javadoc me please
  43.      * @param roomName TODO javadoc me please
  44.      * @param subject TODO javadoc me please
  45.      * @param customConfigs TODO javadoc me please
  46.      * @param occupants TODO javadoc me please
  47.      */
  48.     public MUCLightCreateIQ(EntityJid room, String roomName, String subject, HashMap<String, String> customConfigs,
  49.             List<Jid> occupants) {
  50.         super(ELEMENT, NAMESPACE);
  51.         this.configuration = new MUCLightRoomConfiguration(roomName, subject, customConfigs);

  52.         this.occupants = new HashMap<>();
  53.         for (Jid occupant : occupants) {
  54.             this.occupants.put(occupant, MUCLightAffiliation.member);
  55.         }

  56.         this.setType(Type.set);
  57.         this.setTo(room);
  58.     }

  59.     /**
  60.      * MUCLight create IQ constructor.
  61.      *
  62.      * @param room TODO javadoc me please
  63.      * @param roomName TODO javadoc me please
  64.      * @param occupants TODO javadoc me please
  65.      */
  66.     public MUCLightCreateIQ(EntityJid room, String roomName, List<Jid> occupants) {
  67.         this(room, roomName, null, null, occupants);
  68.     }

  69.     /**
  70.      * Get the room configuration.
  71.      *
  72.      * @return the room configuration
  73.      */
  74.     public MUCLightRoomConfiguration getConfiguration() {
  75.         return configuration;
  76.     }

  77.     /**
  78.      * Get the room occupants.
  79.      *
  80.      * @return the room occupants
  81.      */
  82.     public HashMap<Jid, MUCLightAffiliation> getOccupants() {
  83.         return occupants;
  84.     }

  85.     @Override
  86.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  87.         xml.rightAngleBracket();
  88.         xml.append(new ConfigurationElement(configuration));

  89.         if (!occupants.isEmpty()) {
  90.             xml.append(new OccupantsElement(occupants));
  91.         }

  92.         return xml;
  93.     }

  94. }