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