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.Iterator;
020import java.util.Map;
021
022import org.jivesoftware.smack.packet.IQ;
023
024import org.jivesoftware.smackx.muclight.MultiUserChatLight;
025
026import org.jxmpp.jid.Jid;
027
028/**
029 * MUC Light set configurations IQ class.
030 *
031 * @author Fernando Ramirez
032 *
033 */
034public class MUCLightSetConfigsIQ extends IQ {
035
036    public static final String ELEMENT = QUERY_ELEMENT;
037    public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
038
039    private String roomName;
040    private String subject;
041    private Map<String, String> customConfigs;
042
043    /**
044     * MUC Light set configuration IQ constructor.
045     *
046     * @param roomJid TODO javadoc me please
047     * @param roomName TODO javadoc me please
048     * @param subject TODO javadoc me please
049     * @param customConfigs TODO javadoc me please
050     */
051    @SuppressWarnings("this-escape")
052    public MUCLightSetConfigsIQ(Jid roomJid, String roomName, String subject, Map<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 TODO javadoc me please
065     * @param roomName TODO javadoc me please
066     * @param customConfigs TODO javadoc me please
067     */
068    public MUCLightSetConfigsIQ(Jid roomJid, String roomName, Map<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}