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