UnblockContactsIQ.java

  1. /**
  2.  *
  3.  * Copyright 2016-2017 Fernando Ramirez, Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.blocking.element;

  18. import java.util.Collections;
  19. import java.util.List;

  20. import org.jivesoftware.smack.packet.IQ;

  21. import org.jivesoftware.smackx.blocking.BlockingCommandManager;

  22. import org.jxmpp.jid.Jid;

  23. /**
  24.  * Unblock contact IQ class.
  25.  *
  26.  * @author Fernando Ramirez
  27.  * @author Florian Schmaus
  28.  * @see <a href="http://xmpp.org/extensions/xep-0191.html">XEP-0191: Blocking
  29.  *      Command</a>
  30.  */
  31. public class UnblockContactsIQ extends IQ {

  32.     /**
  33.      * unblock element.
  34.      */
  35.     public static final String ELEMENT = "unblock";

  36.     /**
  37.      * the IQ NAMESPACE.
  38.      */
  39.     public static final String NAMESPACE = BlockingCommandManager.NAMESPACE;

  40.     private final List<Jid> jids;

  41.     /**
  42.      * Unblock contacts IQ constructor.
  43.      *
  44.      * @param jids TODO javadoc me please
  45.      */
  46.     public UnblockContactsIQ(List<Jid> jids) {
  47.         super(ELEMENT, NAMESPACE);
  48.         this.setType(Type.set);
  49.         if (jids != null) {
  50.             this.jids = Collections.unmodifiableList(jids);
  51.         } else {
  52.             this.jids = null;
  53.         }
  54.     }

  55.     /**
  56.      * Constructs a new unblock IQ which will unblock <b>all</b> JIDs.
  57.      */
  58.     public UnblockContactsIQ() {
  59.         this(null);
  60.     }

  61.     /**
  62.      * Get the JIDs. This may return null, which means that all JIDs should be or where unblocked.
  63.      *
  64.      * @return the list of JIDs or <code>null</code>.
  65.      */
  66.     public List<Jid> getJids() {
  67.         return jids;
  68.     }

  69.     @Override
  70.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  71.         if (jids == null) {
  72.             xml.setEmptyElement();
  73.             return xml;
  74.         }

  75.         xml.rightAngleBracket();
  76.         for (Jid jid : jids) {
  77.             xml.halfOpenElement("item");
  78.             xml.attribute("jid", jid);
  79.             xml.closeEmptyElement();
  80.         }

  81.         return xml;
  82.     }

  83. }