BlockContactsIQ.java

  1. /**
  2.  *
  3.  * Copyright 2016 Fernando Ramirez
  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.  * Block contact IQ class.
  25.  *
  26.  * @author Fernando Ramirez
  27.  * @see <a href="http://xmpp.org/extensions/xep-0191.html">XEP-0191: Blocking
  28.  *      Command</a>
  29.  */
  30. public class BlockContactsIQ extends IQ {

  31.     /**
  32.      * block element.
  33.      */
  34.     public static final String ELEMENT = "block";

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

  39.     private final List<Jid> jids;

  40.     /**
  41.      * Block list IQ constructor.
  42.      *
  43.      * @param jids TODO javadoc me please
  44.      */
  45.     public BlockContactsIQ(List<Jid> jids) {
  46.         super(ELEMENT, NAMESPACE);
  47.         this.setType(Type.set);
  48.         this.jids = Collections.unmodifiableList(jids);
  49.     }

  50.     /**
  51.      * Get the JID.
  52.      *
  53.      * @return the list of JIDs
  54.      */
  55.     public List<Jid> getJids() {
  56.         return jids;
  57.     }

  58.     @Override
  59.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  60.         xml.rightAngleBracket();

  61.         if (jids != null) {
  62.             for (Jid jid : jids) {
  63.                 xml.halfOpenElement("item");
  64.                 xml.attribute("jid", jid);
  65.                 xml.closeEmptyElement();
  66.             }
  67.         }

  68.         return xml;
  69.     }

  70. }