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.agent; 21 22 import org.jivesoftware.smack.Connection; 23 import org.jivesoftware.smack.packet.IQ; 24 import org.jivesoftware.smack.provider.IQProvider; 25 import org.xmlpull.v1.XmlPullParser; 26 27 28 public class OfferConfirmation extends IQ { 29 private String userJID; 30 private long sessionID; 31 getUserJID()32 public String getUserJID() { 33 return userJID; 34 } 35 setUserJID(String userJID)36 public void setUserJID(String userJID) { 37 this.userJID = userJID; 38 } 39 getSessionID()40 public long getSessionID() { 41 return sessionID; 42 } 43 setSessionID(long sessionID)44 public void setSessionID(long sessionID) { 45 this.sessionID = sessionID; 46 } 47 48 notifyService(Connection con, String workgroup, String createdRoomName)49 public void notifyService(Connection con, String workgroup, String createdRoomName) { 50 NotifyServicePacket packet = new NotifyServicePacket(workgroup, createdRoomName); 51 con.sendPacket(packet); 52 } 53 getChildElementXML()54 public String getChildElementXML() { 55 StringBuilder buf = new StringBuilder(); 56 buf.append("<offer-confirmation xmlns=\"http://jabber.org/protocol/workgroup\">"); 57 buf.append("</offer-confirmation>"); 58 return buf.toString(); 59 } 60 61 public static class Provider implements IQProvider { 62 parseIQ(XmlPullParser parser)63 public IQ parseIQ(XmlPullParser parser) throws Exception { 64 final OfferConfirmation confirmation = new OfferConfirmation(); 65 66 boolean done = false; 67 while (!done) { 68 parser.next(); 69 String elementName = parser.getName(); 70 if (parser.getEventType() == XmlPullParser.START_TAG && "user-jid".equals(elementName)) { 71 try { 72 confirmation.setUserJID(parser.nextText()); 73 } 74 catch (NumberFormatException nfe) { 75 } 76 } 77 else if (parser.getEventType() == XmlPullParser.START_TAG && "session-id".equals(elementName)) { 78 try { 79 confirmation.setSessionID(Long.valueOf(parser.nextText())); 80 } 81 catch (NumberFormatException nfe) { 82 } 83 } 84 else if (parser.getEventType() == XmlPullParser.END_TAG && "offer-confirmation".equals(elementName)) { 85 done = true; 86 } 87 } 88 89 90 return confirmation; 91 } 92 } 93 94 95 /** 96 * Packet for notifying server of RoomName 97 */ 98 private class NotifyServicePacket extends IQ { 99 String roomName; 100 NotifyServicePacket(String workgroup, String roomName)101 NotifyServicePacket(String workgroup, String roomName) { 102 this.setTo(workgroup); 103 this.setType(IQ.Type.RESULT); 104 105 this.roomName = roomName; 106 } 107 getChildElementXML()108 public String getChildElementXML() { 109 return "<offer-confirmation roomname=\"" + roomName + "\" xmlns=\"http://jabber.org/protocol/workgroup" + "\"/>"; 110 } 111 } 112 113 114 } 115