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