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.blocking.element; 018 019import java.util.Collections; 020import java.util.List; 021 022import org.jivesoftware.smack.packet.IQ; 023import org.jivesoftware.smackx.blocking.BlockingCommandManager; 024import org.jxmpp.jid.Jid; 025 026/** 027 * Block contact IQ class. 028 * 029 * @author Fernando Ramirez 030 * @see <a href="http://xmpp.org/extensions/xep-0191.html">XEP-0191: Blocking 031 * Command</a> 032 */ 033public class BlockContactsIQ extends IQ { 034 035 /** 036 * block element. 037 */ 038 public static final String ELEMENT = "block"; 039 040 /** 041 * the IQ NAMESPACE. 042 */ 043 public static final String NAMESPACE = BlockingCommandManager.NAMESPACE; 044 045 private final List<Jid> jids; 046 047 /** 048 * Block list IQ constructor. 049 * 050 * @param jids 051 */ 052 public BlockContactsIQ(List<Jid> jids) { 053 super(ELEMENT, NAMESPACE); 054 this.setType(Type.set); 055 this.jids = Collections.unmodifiableList(jids); 056 } 057 058 /** 059 * Get the JID. 060 * 061 * @return the list of JIDs 062 */ 063 public List<Jid> getJids() { 064 return jids; 065 } 066 067 @Override 068 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 069 xml.rightAngleBracket(); 070 071 if (jids != null) { 072 for (Jid jid : jids) { 073 xml.halfOpenElement("item"); 074 xml.attribute("jid", jid); 075 xml.closeEmptyElement(); 076 } 077 } 078 079 return xml; 080 } 081 082}