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.muclight.element;
018
019import java.util.HashMap;
020import java.util.Iterator;
021import java.util.Map;
022
023import org.jivesoftware.smack.packet.IQ;
024
025import org.jivesoftware.smackx.muclight.MultiUserChatLight;
026
027import org.jxmpp.jid.Jid;
028
029/**
030 * MUC Light set configurations IQ class.
031 *
032 * @author Fernando Ramirez
033 *
034 */
035public class MUCLightSetConfigsIQ extends IQ {
036
037    public static final String ELEMENT = QUERY_ELEMENT;
038    public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
039
040    private String roomName;
041    private String subject;
042    private HashMap<String, String> customConfigs;
043
044    /**
045     * MUC Light set configuration IQ constructor.
046     *
047     * @param roomJid
048     * @param roomName
049     * @param subject
050     * @param customConfigs
051     */
052    public MUCLightSetConfigsIQ(Jid roomJid, String roomName, String subject, HashMap<String, String> customConfigs) {
053        super(ELEMENT, NAMESPACE);
054        this.roomName = roomName;
055        this.subject = subject;
056        this.customConfigs = customConfigs;
057        this.setType(Type.set);
058        this.setTo(roomJid);
059    }
060
061    /**
062     * MUC Light set configuration IQ constructor.
063     *
064     * @param roomJid
065     * @param roomName
066     * @param customConfigs
067     */
068    public MUCLightSetConfigsIQ(Jid roomJid, String roomName, HashMap<String, String> customConfigs) {
069        this(roomJid, roomName, null, customConfigs);
070    }
071
072    @Override
073    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
074        xml.rightAngleBracket();
075        xml.optElement("roomname", roomName);
076        xml.optElement("subject", subject);
077
078        if (customConfigs != null) {
079            Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator();
080            while (it.hasNext()) {
081                Map.Entry<String, String> pair = it.next();
082                xml.element(pair.getKey(), pair.getValue());
083            }
084        }
085
086        return xml;
087    }
088
089}