GenericSettings.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.settings;

  18. import org.jivesoftware.smackx.workgroup.util.ModelUtil;
  19. import org.jivesoftware.smack.packet.IQ;
  20. import org.jivesoftware.smack.provider.IQProvider;
  21. import org.xmlpull.v1.XmlPullParser;
  22. import org.xmlpull.v1.XmlPullParserException;

  23. import java.io.IOException;
  24. import java.util.HashMap;
  25. import java.util.Map;

  26. public class GenericSettings extends IQ {

  27.     private Map<String, String> map = new HashMap<String, String>();

  28.     private String query;

  29.     public String getQuery() {
  30.         return query;
  31.     }

  32.     public void setQuery(String query) {
  33.         this.query = query;
  34.     }

  35.     public Map<String, String> getMap() {
  36.         return map;
  37.     }

  38.     public void setMap(Map<String, String> map) {
  39.         this.map = map;
  40.     }


  41.     /**
  42.      * Element name of the packet extension.
  43.      */
  44.     public static final String ELEMENT_NAME = "generic-metadata";

  45.     /**
  46.      * Namespace of the packet extension.
  47.      */
  48.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  49.     public GenericSettings() {
  50.         super(ELEMENT_NAME, NAMESPACE);
  51.     }

  52.     @Override
  53.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  54.         buf.append(">");
  55.         if (ModelUtil.hasLength(getQuery())) {
  56.             buf.append("<query>" + getQuery() + "</query>");
  57.         }
  58.         return buf;
  59.     }

  60.     /**
  61.      * Packet extension provider for SoundSetting Packets.
  62.      */
  63.     public static class InternalProvider extends IQProvider<GenericSettings> {

  64.         @Override
  65.         public GenericSettings parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
  66.             GenericSettings setting = new GenericSettings();

  67.             boolean done = false;


  68.             while (!done) {
  69.                 int eventType = parser.next();
  70.                 if ((eventType == XmlPullParser.START_TAG) && ("entry".equals(parser.getName()))) {
  71.                     eventType = parser.next();
  72.                     String name = parser.nextText();
  73.                     eventType = parser.next();
  74.                     String value = parser.nextText();
  75.                     setting.getMap().put(name, value);
  76.                 }
  77.                 else if (eventType == XmlPullParser.END_TAG && ELEMENT_NAME.equals(parser.getName())) {
  78.                     done = true;
  79.                 }
  80.             }

  81.             return setting;
  82.         }
  83.     }


  84. }