001/**
002 *
003 * Copyright 2003-2007 Jive Software.
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 */
017
018package org.jivesoftware.smackx.workgroup.settings;
019
020import java.io.IOException;
021import java.util.HashMap;
022import java.util.Map;
023
024import org.jivesoftware.smack.packet.IQ;
025import org.jivesoftware.smack.packet.IqData;
026import org.jivesoftware.smack.packet.XmlEnvironment;
027import org.jivesoftware.smack.provider.IqProvider;
028import org.jivesoftware.smack.util.StringUtils;
029import org.jivesoftware.smack.xml.XmlPullParser;
030import org.jivesoftware.smack.xml.XmlPullParserException;
031
032public class GenericSettings extends IQ {
033
034    private Map<String, String> map = new HashMap<>();
035
036    private String query;
037
038    public String getQuery() {
039        return query;
040    }
041
042    public void setQuery(String query) {
043        this.query = query;
044    }
045
046    public Map<String, String> getMap() {
047        return map;
048    }
049
050    public void setMap(Map<String, String> map) {
051        this.map = map;
052    }
053
054
055    /**
056     * Element name of the stanza extension.
057     */
058    public static final String ELEMENT_NAME = "generic-metadata";
059
060    /**
061     * Namespace of the stanza extension.
062     */
063    public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
064
065    public GenericSettings() {
066        super(ELEMENT_NAME, NAMESPACE);
067    }
068
069    @Override
070    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
071        buf.append('>');
072        if (StringUtils.isNotEmpty(getQuery())) {
073            buf.append("<query>" + getQuery() + "</query>");
074        }
075        return buf;
076    }
077
078    /**
079     * Stanza extension provider for SoundSetting Packets.
080     */
081    public static class InternalProvider extends IqProvider<GenericSettings> {
082
083        @Override
084        public GenericSettings parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
085            GenericSettings setting = new GenericSettings();
086
087            boolean done = false;
088
089
090            while (!done) {
091                XmlPullParser.Event eventType = parser.next();
092                if (eventType == XmlPullParser.Event.START_ELEMENT && "entry".equals(parser.getName())) {
093                    eventType = parser.next();
094                    String name = parser.nextText();
095                    eventType = parser.next();
096                    String value = parser.nextText();
097                    setting.getMap().put(name, value);
098                }
099                else if (eventType == XmlPullParser.Event.END_ELEMENT && ELEMENT_NAME.equals(parser.getName())) {
100                    done = true;
101                }
102            }
103
104            return setting;
105        }
106    }
107
108
109}
110