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