001/** 002 * 003 * Copyright 2016 Fernando Ramirez 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.muclight.element; 018 019import java.util.HashMap; 020import java.util.Iterator; 021import java.util.Map; 022 023import org.jivesoftware.smack.packet.IQ; 024import org.jivesoftware.smackx.muclight.MultiUserChatLight; 025import org.jxmpp.jid.Jid; 026 027/** 028 * MUC Light set configurations IQ class. 029 * 030 * @author Fernando Ramirez 031 * 032 */ 033public class MUCLightSetConfigsIQ extends IQ { 034 035 public static final String ELEMENT = QUERY_ELEMENT; 036 public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION; 037 038 private String roomName; 039 private String subject; 040 private HashMap<String, String> customConfigs; 041 042 /** 043 * MUC Light set configuration IQ constructor. 044 * 045 * @param roomJid 046 * @param roomName 047 * @param subject 048 * @param customConfigs 049 */ 050 public MUCLightSetConfigsIQ(Jid roomJid, String roomName, String subject, HashMap<String, String> customConfigs) { 051 super(ELEMENT, NAMESPACE); 052 this.roomName = roomName; 053 this.subject = subject; 054 this.customConfigs = customConfigs; 055 this.setType(Type.set); 056 this.setTo(roomJid); 057 } 058 059 /** 060 * MUC Light set configuration IQ constructor. 061 * 062 * @param roomJid 063 * @param roomName 064 * @param customConfigs 065 */ 066 public MUCLightSetConfigsIQ(Jid roomJid, String roomName, HashMap<String, String> customConfigs) { 067 this(roomJid, roomName, null, customConfigs); 068 } 069 070 @Override 071 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 072 xml.rightAngleBracket(); 073 xml.optElement("roomname", roomName); 074 xml.optElement("subject", subject); 075 076 if (customConfigs != null) { 077 Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator(); 078 while (it.hasNext()) { 079 Map.Entry<String, String> pair = it.next(); 080 xml.element(pair.getKey(), pair.getValue()); 081 } 082 } 083 084 return xml; 085 } 086 087}