001/** 002 * 003 * Copyright 2016-2017 Fernando Ramirez, Florian Schmaus 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 * Unblock contact IQ class. 028 * 029 * @author Fernando Ramirez 030 * @author Florian Schmaus 031 * @see <a href="http://xmpp.org/extensions/xep-0191.html">XEP-0191: Blocking 032 * Command</a> 033 */ 034public class UnblockContactsIQ extends IQ { 035 036 /** 037 * unblock element. 038 */ 039 public static final String ELEMENT = "unblock"; 040 041 /** 042 * the IQ NAMESPACE. 043 */ 044 public static final String NAMESPACE = BlockingCommandManager.NAMESPACE; 045 046 private final List<Jid> jids; 047 048 /** 049 * Unblock contacts IQ constructor. 050 * 051 * @param jids 052 */ 053 public UnblockContactsIQ(List<Jid> jids) { 054 super(ELEMENT, NAMESPACE); 055 this.setType(Type.set); 056 if (jids != null) { 057 this.jids = Collections.unmodifiableList(jids); 058 } else { 059 this.jids = null; 060 } 061 } 062 063 /** 064 * Constructs a new unblock IQ which will unblock <b>all</b> JIDs. 065 */ 066 public UnblockContactsIQ() { 067 this(null); 068 } 069 070 /** 071 * Get the JIDs. This may return null, which means that all JIDs should be or where unblocked. 072 * 073 * @return the list of JIDs or <code>null</code>. 074 */ 075 public List<Jid> getJids() { 076 return jids; 077 } 078 079 @Override 080 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 081 if (jids == null) { 082 xml.setEmptyElement(); 083 return xml; 084 } 085 086 xml.rightAngleBracket(); 087 for (Jid jid : jids) { 088 xml.halfOpenElement("item"); 089 xml.attribute("jid", jid); 090 xml.closeEmptyElement(); 091 } 092 093 return xml; 094 } 095 096}