001/* 002 * 003 * Copyright 2003-2007 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smackx.workgroup.agent; 019 020import java.io.IOException; 021 022import org.jivesoftware.smack.SmackException.NotConnectedException; 023import org.jivesoftware.smack.XMPPConnection; 024import org.jivesoftware.smack.packet.IQ; 025import org.jivesoftware.smack.packet.IqData; 026import org.jivesoftware.smack.packet.SimpleIQ; 027import org.jivesoftware.smack.packet.XmlEnvironment; 028import org.jivesoftware.smack.provider.IqProvider; 029import org.jivesoftware.smack.xml.XmlPullParser; 030import org.jivesoftware.smack.xml.XmlPullParserException; 031 032import org.jxmpp.JxmppContext; 033import org.jxmpp.jid.Jid; 034 035 036public class OfferConfirmation extends SimpleIQ { 037 private String userJID; 038 private long sessionID; 039 040 public OfferConfirmation() { 041 super("offer-confirmation", "http://jabber.org/protocol/workgroup"); 042 } 043 044 public String getUserJID() { 045 return userJID; 046 } 047 048 public void setUserJID(String userJID) { 049 this.userJID = userJID; 050 } 051 052 public long getSessionID() { 053 return sessionID; 054 } 055 056 public void setSessionID(long sessionID) { 057 this.sessionID = sessionID; 058 } 059 060 061 public void notifyService(XMPPConnection con, Jid workgroup, String createdRoomName) throws NotConnectedException, InterruptedException { 062 NotifyServicePacket packet = new NotifyServicePacket(workgroup, createdRoomName); 063 con.sendStanza(packet); 064 } 065 066 public static class Provider extends IqProvider<OfferConfirmation> { 067 068 @Override 069 public OfferConfirmation parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment, JxmppContext jxmppContext) 070 throws XmlPullParserException, IOException { 071 final OfferConfirmation confirmation = new OfferConfirmation(); 072 073 boolean done = false; 074 while (!done) { 075 parser.next(); 076 if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "user-jid".equals(parser.getName())) { 077 confirmation.setUserJID(parser.nextText()); 078 } 079 else if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT && "session-id".equals(parser.getName())) { 080 confirmation.setSessionID(Long.valueOf(parser.nextText())); 081 } 082 else if (parser.getEventType() == XmlPullParser.Event.END_ELEMENT && "offer-confirmation".equals(parser.getName())) { 083 done = true; 084 } 085 } 086 087 088 return confirmation; 089 } 090 } 091 092 093 /** 094 * Stanza for notifying server of RoomName 095 */ 096 private static class NotifyServicePacket extends IQ { 097 String roomName; 098 099 NotifyServicePacket(Jid workgroup, String roomName) { 100 super("offer-confirmation", "http://jabber.org/protocol/workgroup"); 101 this.setTo(workgroup); 102 this.setType(IQ.Type.result); 103 104 this.roomName = roomName; 105 } 106 107 @Override 108 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { 109 xml.attribute("roomname", roomName); 110 xml.setEmptyElement(); 111 return xml; 112 } 113 } 114 115 116}