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    public BlockContactsIQ(List<Jid> jids) {
055        super(ELEMENT, NAMESPACE);
056        this.setType(Type.set);
057        this.jids = Collections.unmodifiableList(jids);
058    }
059
060    /**
061     * Get the JID.
062     *
063     * @return the list of JIDs
064     */
065    public List<Jid> getJids() {
066        return jids;
067    }
068
069    @Override
070    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
071        xml.rightAngleBracket();
072
073        if (jids != null) {
074            for (Jid jid : jids) {
075                xml.halfOpenElement("item");
076                xml.attribute("jid", jid);
077                xml.closeEmptyElement();
078            }
079        }
080
081        return xml;
082    }
083
084}