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.packet; 21 22 import org.jivesoftware.smack.packet.IQ; 23 import org.jivesoftware.smack.provider.IQProvider; 24 import org.xmlpull.v1.XmlPullParser; 25 26 /** 27 * An IQProvider class which has savvy about the offer-revoke tag.<br> 28 * 29 * @author loki der quaeler 30 */ 31 public class OfferRevokeProvider implements IQProvider { 32 33 public IQ parseIQ (XmlPullParser parser) throws Exception { 34 // The parser will be positioned on the opening IQ tag, so get the JID attribute. 35 String userJID = parser.getAttributeValue("", "jid"); 36 // Default the userID to the JID. 37 String userID = userJID; 38 String reason = null; 39 String sessionID = null; 40 boolean done = false; 41 42 while (!done) { 43 int eventType = parser.next(); 44 45 if ((eventType == XmlPullParser.START_TAG) && parser.getName().equals("reason")) { 46 reason = parser.nextText(); 47 } 48 else if ((eventType == XmlPullParser.START_TAG) 49 && parser.getName().equals(SessionID.ELEMENT_NAME)) { 50 sessionID = parser.getAttributeValue("", "id"); 51 } 52 else if ((eventType == XmlPullParser.START_TAG) 53 && parser.getName().equals(UserID.ELEMENT_NAME)) { 54 userID = parser.getAttributeValue("", "id"); 55 } 56 else if ((eventType == XmlPullParser.END_TAG) && parser.getName().equals( 57 "offer-revoke")) 58 { 59 done = true; 60 } 61 } 62 63 return new OfferRevokePacket(userJID, userID, reason, sessionID); 64 } 65 66 public class OfferRevokePacket extends IQ { 67 68 private String userJID; 69 private String userID; 70 private String sessionID; 71 private String reason; 72 73 public OfferRevokePacket (String userJID, String userID, String cause, String sessionID) { 74 this.userJID = userJID; 75 this.userID = userID; 76 this.reason = cause; 77 this.sessionID = sessionID; 78 } 79 80 public String getUserJID() { 81 return userJID; 82 } 83 84 public String getUserID() { 85 return this.userID; 86 } 87 88 public String getReason() { 89 return this.reason; 90 } 91 92 public String getSessionID() { 93 return this.sessionID; 94 } 95 96 public String getChildElementXML () { 97 StringBuilder buf = new StringBuilder(); 98 buf.append("<offer-revoke xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"").append(userID).append("\">"); 99 if (reason != null) { 100 buf.append("<reason>").append(reason).append("</reason>"); 101 } 102 if (sessionID != null) { 103 buf.append(new SessionID(sessionID).toXML()); 104 } 105 if (userID != null) { 106 buf.append(new UserID(userID).toXML()); 107 } 108 buf.append("</offer-revoke>"); 109 return buf.toString(); 110 } 111 } 112 } 113