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.List; 021 022import org.jivesoftware.smack.packet.IQ; 023import org.jivesoftware.smackx.muclight.MUCLightAffiliation; 024import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration; 025import org.jivesoftware.smackx.muclight.MultiUserChatLight; 026import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationElement; 027import org.jivesoftware.smackx.muclight.element.MUCLightElements.OccupantsElement; 028import org.jxmpp.jid.EntityJid; 029import org.jxmpp.jid.Jid; 030 031/** 032 * MUCLight create IQ class. 033 * 034 * @author Fernando Ramirez 035 * 036 */ 037public class MUCLightCreateIQ extends IQ { 038 039 public static final String ELEMENT = QUERY_ELEMENT; 040 public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CREATE; 041 042 private MUCLightRoomConfiguration configuration; 043 private final HashMap<Jid, MUCLightAffiliation> occupants; 044 045 /** 046 * MUCLight create IQ constructor. 047 * 048 * @param room 049 * @param roomName 050 * @param subject 051 * @param customConfigs 052 * @param occupants 053 */ 054 public MUCLightCreateIQ(EntityJid room, String roomName, String subject, HashMap<String, String> customConfigs, 055 List<Jid> occupants) { 056 super(ELEMENT, NAMESPACE); 057 this.configuration = new MUCLightRoomConfiguration(roomName, subject, customConfigs); 058 059 this.occupants = new HashMap<>(); 060 for (Jid occupant : occupants) { 061 this.occupants.put(occupant, MUCLightAffiliation.member); 062 } 063 064 this.setType(Type.set); 065 this.setTo(room); 066 } 067 068 /** 069 * MUCLight create IQ constructor. 070 * 071 * @param room 072 * @param roomName 073 * @param occupants 074 */ 075 public MUCLightCreateIQ(EntityJid room, String roomName, List<Jid> occupants) { 076 this(room, roomName, null, null, occupants); 077 } 078 079 /** 080 * Get the room configuration. 081 * 082 * @return the room configuration 083 */ 084 public MUCLightRoomConfiguration getConfiguration() { 085 return configuration; 086 } 087 088 /** 089 * Get the room occupants. 090 * 091 * @return the room occupants 092 */ 093 public HashMap<Jid, MUCLightAffiliation> getOccupants() { 094 return occupants; 095 } 096 097 @Override 098 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 099 xml.rightAngleBracket(); 100 xml.element(new ConfigurationElement(configuration)); 101 102 if (!occupants.isEmpty()) { 103 xml.element(new OccupantsElement(occupants)); 104 } 105 106 return xml; 107 } 108 109}