MUCLightSetConfigsIQ.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.Iterator;
  20. import java.util.Map;

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

  22. import org.jivesoftware.smackx.muclight.MultiUserChatLight;

  23. import org.jxmpp.jid.Jid;

  24. /**
  25.  * MUC Light set configurations IQ class.
  26.  *
  27.  * @author Fernando Ramirez
  28.  *
  29.  */
  30. public class MUCLightSetConfigsIQ extends IQ {

  31.     public static final String ELEMENT = QUERY_ELEMENT;
  32.     public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;

  33.     private String roomName;
  34.     private String subject;
  35.     private HashMap<String, String> customConfigs;

  36.     /**
  37.      * MUC Light set configuration IQ constructor.
  38.      *
  39.      * @param roomJid TODO javadoc me please
  40.      * @param roomName TODO javadoc me please
  41.      * @param subject TODO javadoc me please
  42.      * @param customConfigs TODO javadoc me please
  43.      */
  44.     public MUCLightSetConfigsIQ(Jid roomJid, String roomName, String subject, HashMap<String, String> customConfigs) {
  45.         super(ELEMENT, NAMESPACE);
  46.         this.roomName = roomName;
  47.         this.subject = subject;
  48.         this.customConfigs = customConfigs;
  49.         this.setType(Type.set);
  50.         this.setTo(roomJid);
  51.     }

  52.     /**
  53.      * MUC Light set configuration IQ constructor.
  54.      *
  55.      * @param roomJid TODO javadoc me please
  56.      * @param roomName TODO javadoc me please
  57.      * @param customConfigs TODO javadoc me please
  58.      */
  59.     public MUCLightSetConfigsIQ(Jid roomJid, String roomName, HashMap<String, String> customConfigs) {
  60.         this(roomJid, roomName, null, customConfigs);
  61.     }

  62.     @Override
  63.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  64.         xml.rightAngleBracket();
  65.         xml.optElement("roomname", roomName);
  66.         xml.optElement("subject", subject);

  67.         if (customConfigs != null) {
  68.             Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator();
  69.             while (it.hasNext()) {
  70.                 Map.Entry<String, String> pair = it.next();
  71.                 xml.element(pair.getKey(), pair.getValue());
  72.             }
  73.         }

  74.         return xml;
  75.     }

  76. }