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 20 package org.jivesoftware.smackx.workgroup.ext.history; 21 22 import org.jivesoftware.smackx.workgroup.util.MetaDataUtils; 23 import org.jivesoftware.smack.packet.IQ; 24 import org.jivesoftware.smack.provider.IQProvider; 25 import org.xmlpull.v1.XmlPullParser; 26 27 import java.util.HashMap; 28 import java.util.List; 29 import java.util.Map; 30 31 public class ChatMetadata extends IQ { 32 33 /** 34 * Element name of the packet extension. 35 */ 36 public static final String ELEMENT_NAME = "chat-metadata"; 37 38 /** 39 * Namespace of the packet extension. 40 */ 41 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 42 43 44 private String sessionID; 45 46 public String getSessionID() { 47 return sessionID; 48 } 49 50 public void setSessionID(String sessionID) { 51 this.sessionID = sessionID; 52 } 53 54 55 private Map<String, List<String>> map = new HashMap<String, List<String>>(); 56 57 public void setMetadata(Map<String, List<String>> metadata){ 58 this.map = metadata; 59 } 60 61 public Map<String, List<String>> getMetadata(){ 62 return map; 63 } 64 65 66 public String getChildElementXML() { 67 StringBuilder buf = new StringBuilder(); 68 69 buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">"); 70 buf.append("<sessionID>").append(getSessionID()).append("</sessionID>"); 71 buf.append("</").append(ELEMENT_NAME).append("> "); 72 73 return buf.toString(); 74 } 75 76 /** 77 * An IQProvider for Metadata packets. 78 * 79 * @author Derek DeMoro 80 */ 81 public static class Provider implements IQProvider { 82 83 public Provider() { 84 super(); 85 } 86 87 public IQ parseIQ(XmlPullParser parser) throws Exception { 88 final ChatMetadata chatM = new ChatMetadata(); 89 90 boolean done = false; 91 while (!done) { 92 int eventType = parser.next(); 93 if (eventType == XmlPullParser.START_TAG) { 94 if (parser.getName().equals("sessionID")) { 95 chatM.setSessionID(parser.nextText()); 96 } 97 else if (parser.getName().equals("metadata")) { 98 Map<String, List<String>> map = MetaDataUtils.parseMetaData(parser); 99 chatM.setMetadata(map); 100 } 101 } 102 else if (eventType == XmlPullParser.END_TAG) { 103 if (parser.getName().equals(ELEMENT_NAME)) { 104 done = true; 105 } 106 } 107 } 108 109 return chatM; 110 } 111 } 112 } 113 114 115 116 117