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; 024 025import org.jivesoftware.smackx.muclight.MultiUserChatLight; 026import org.jivesoftware.smackx.muclight.element.MUCLightElements.BlockingElement; 027 028import org.jxmpp.jid.Jid; 029 030/** 031 * MUC Light blocking IQ class. 032 * 033 * @author Fernando Ramirez 034 * 035 */ 036public class MUCLightBlockingIQ extends IQ { 037 038 public static final String ELEMENT = QUERY_ELEMENT; 039 public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.BLOCKING; 040 041 private final HashMap<Jid, Boolean> rooms; 042 private final HashMap<Jid, Boolean> users; 043 044 /** 045 * MUC Light blocking IQ constructor. 046 * 047 * @param rooms TODO javadoc me please 048 * @param users TODO javadoc me please 049 */ 050 public MUCLightBlockingIQ(HashMap<Jid, Boolean> rooms, HashMap<Jid, Boolean> users) { 051 super(ELEMENT, NAMESPACE); 052 this.rooms = rooms; 053 this.users = users; 054 } 055 056 /** 057 * Get rooms JIDs with booleans (true if allow, false if deny). 058 * 059 * @return the rooms JIDs with booleans (true if allow, false if deny) 060 */ 061 public HashMap<Jid, Boolean> getRooms() { 062 return rooms; 063 } 064 065 /** 066 * Get users JIDs with booleans (true if allow, false if deny). 067 * 068 * @return the users JIDs with booleans (true if allow, false if deny) 069 */ 070 public HashMap<Jid, Boolean> getUsers() { 071 return users; 072 } 073 074 @Override 075 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 076 xml.rightAngleBracket(); 077 078 if (rooms != null) { 079 parseBlocking(xml, rooms, true); 080 } 081 082 if (users != null) { 083 parseBlocking(xml, users, false); 084 } 085 086 return xml; 087 } 088 089 private static void parseBlocking(IQChildElementXmlStringBuilder xml, HashMap<Jid, Boolean> map, boolean isRoom) { 090 Iterator<Map.Entry<Jid, Boolean>> it = map.entrySet().iterator(); 091 while (it.hasNext()) { 092 Map.Entry<Jid, Boolean> pair = it.next(); 093 xml.append(new BlockingElement(pair.getKey(), pair.getValue(), isRoom)); 094 } 095 } 096 097}