2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2007 Jive Software.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smackx.workgroup.packet;
|
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2019-02-15 23:21:30 +01:00
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.provider.IQProvider;
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jivesoftware.smack.util.ParserUtils;
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
|
|
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jxmpp.jid.Jid;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An IQProvider class which has savvy about the offer-revoke tag.<br>
|
|
|
|
*
|
|
|
|
* @author loki der quaeler
|
|
|
|
*/
|
2014-10-07 21:15:20 +02:00
|
|
|
public class OfferRevokeProvider extends IQProvider<IQ> {
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
2019-02-15 23:21:30 +01:00
|
|
|
public OfferRevokePacket parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
|
2014-02-17 23:58:40 +01:00
|
|
|
// The parser will be positioned on the opening IQ tag, so get the JID attribute.
|
2015-02-14 17:15:02 +01:00
|
|
|
Jid userJID = ParserUtils.getJidAttribute(parser);
|
2014-02-17 23:58:40 +01:00
|
|
|
// Default the userID to the JID.
|
2015-02-14 17:15:02 +01:00
|
|
|
Jid userID = userJID;
|
2014-02-17 23:58:40 +01:00
|
|
|
String reason = null;
|
|
|
|
String sessionID = null;
|
|
|
|
boolean done = false;
|
|
|
|
|
|
|
|
while (!done) {
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event eventType = parser.next();
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
if ((eventType == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals("reason")) {
|
2014-02-17 23:58:40 +01:00
|
|
|
reason = parser.nextText();
|
|
|
|
}
|
2019-05-06 22:06:13 +02:00
|
|
|
else if ((eventType == XmlPullParser.Event.START_ELEMENT)
|
2014-02-17 23:58:40 +01:00
|
|
|
&& parser.getName().equals(SessionID.ELEMENT_NAME)) {
|
|
|
|
sessionID = parser.getAttributeValue("", "id");
|
|
|
|
}
|
2019-05-06 22:06:13 +02:00
|
|
|
else if ((eventType == XmlPullParser.Event.START_ELEMENT)
|
2014-02-17 23:58:40 +01:00
|
|
|
&& parser.getName().equals(UserID.ELEMENT_NAME)) {
|
2015-02-14 17:15:02 +01:00
|
|
|
userID = ParserUtils.getJidAttribute(parser, "id");
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
2019-05-06 22:06:13 +02:00
|
|
|
else if ((eventType == XmlPullParser.Event.END_ELEMENT) && parser.getName().equals(
|
2018-04-06 10:21:46 +02:00
|
|
|
"offer-revoke")) {
|
2014-02-17 23:58:40 +01:00
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new OfferRevokePacket(userJID, userID, reason, sessionID);
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
public static class OfferRevokePacket extends IQ {
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-05-18 12:55:29 +02:00
|
|
|
public static final String ELEMENT = "offer-revoke";
|
|
|
|
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
|
2017-12-13 23:10:11 +01:00
|
|
|
private final Jid userJID;
|
|
|
|
private final Jid userID;
|
|
|
|
private final String sessionID;
|
|
|
|
private final String reason;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
public OfferRevokePacket (Jid userJID, Jid userID, String cause, String sessionID) {
|
2015-05-18 12:55:29 +02:00
|
|
|
super(ELEMENT, NAMESPACE);
|
2014-02-17 23:58:40 +01:00
|
|
|
this.userJID = userJID;
|
|
|
|
this.userID = userID;
|
|
|
|
this.reason = cause;
|
|
|
|
this.sessionID = sessionID;
|
|
|
|
}
|
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
public Jid getUserJID() {
|
2014-02-17 23:58:40 +01:00
|
|
|
return userJID;
|
|
|
|
}
|
|
|
|
|
2015-02-14 17:15:02 +01:00
|
|
|
public Jid getUserID() {
|
2014-02-17 23:58:40 +01:00
|
|
|
return this.userID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getReason() {
|
|
|
|
return this.reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSessionID() {
|
|
|
|
return this.sessionID;
|
|
|
|
}
|
|
|
|
|
2014-11-07 21:12:01 +01:00
|
|
|
@Override
|
|
|
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
|
|
|
buf.append(" jid=\"").append(userID).append("\">");
|
2014-02-17 23:58:40 +01:00
|
|
|
if (reason != null) {
|
|
|
|
buf.append("<reason>").append(reason).append("</reason>");
|
|
|
|
}
|
|
|
|
if (sessionID != null) {
|
2019-02-04 13:27:41 +01:00
|
|
|
buf.append(new SessionID(sessionID).toXML());
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
if (userID != null) {
|
2019-02-04 13:27:41 +01:00
|
|
|
buf.append(new UserID(userID).toXML());
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
2014-11-07 21:12:01 +01:00
|
|
|
return buf;
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|