1/**
2 * $Revision$
3 * $Date$
4 *
5 * Copyright 2003-2007 Jive Software.
6 *
7 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20package org.jivesoftware.smackx.workgroup.settings;
21
22import org.jivesoftware.smackx.workgroup.util.ModelUtil;
23import org.jivesoftware.smack.packet.IQ;
24import org.jivesoftware.smack.provider.IQProvider;
25import org.xmlpull.v1.XmlPullParser;
26
27import java.util.HashMap;
28import java.util.Map;
29
30public class GenericSettings extends IQ {
31
32    private Map<String, String> map = new HashMap<String, String>();
33
34    private String query;
35
36    public String getQuery() {
37        return query;
38    }
39
40    public void setQuery(String query) {
41        this.query = query;
42    }
43
44    public Map<String, String> getMap() {
45        return map;
46    }
47
48    public void setMap(Map<String, String> map) {
49        this.map = map;
50    }
51
52
53    /**
54     * Element name of the packet extension.
55     */
56    public static final String ELEMENT_NAME = "generic-metadata";
57
58    /**
59     * Namespace of the packet extension.
60     */
61    public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
62
63    public String getChildElementXML() {
64        StringBuilder buf = new StringBuilder();
65
66        buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
67        buf.append('"');
68        buf.append(NAMESPACE);
69        buf.append('"');
70        buf.append(">");
71        if (ModelUtil.hasLength(getQuery())) {
72            buf.append("<query>" + getQuery() + "</query>");
73        }
74        buf.append("</").append(ELEMENT_NAME).append("> ");
75        return buf.toString();
76    }
77
78
79    /**
80     * Packet extension provider for SoundSetting Packets.
81     */
82    public static class InternalProvider implements IQProvider {
83
84        public IQ parseIQ(XmlPullParser parser) throws Exception {
85            if (parser.getEventType() != XmlPullParser.START_TAG) {
86                throw new IllegalStateException("Parser not in proper position, or bad XML.");
87            }
88
89            GenericSettings setting = new GenericSettings();
90
91            boolean done = false;
92
93
94            while (!done) {
95                int eventType = parser.next();
96                if ((eventType == XmlPullParser.START_TAG) && ("entry".equals(parser.getName()))) {
97                    eventType = parser.next();
98                    String name = parser.nextText();
99                    eventType = parser.next();
100                    String value = parser.nextText();
101                    setting.getMap().put(name, value);
102                }
103                else if (eventType == XmlPullParser.END_TAG && ELEMENT_NAME.equals(parser.getName())) {
104                    done = true;
105                }
106            }
107
108            return setting;
109        }
110    }
111
112
113}
114
115