2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright the original author or authors
|
|
|
|
*
|
|
|
|
* 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.bytestreams.ibb.provider;
|
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
|
|
|
|
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
2014-10-07 21:15:20 +02:00
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
2015-03-21 09:36:28 +01:00
|
|
|
* Parses an In-Band Bytestream data stanza(/packet) which can be a stanza(/packet) extension of
|
2014-02-17 23:58:40 +01:00
|
|
|
* either an IQ stanza or a message stanza.
|
|
|
|
*
|
|
|
|
* @author Henning Staib
|
|
|
|
*/
|
2014-10-07 21:15:20 +02:00
|
|
|
public class DataPacketProvider {
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
public static class IQProvider extends org.jivesoftware.smack.provider.IQProvider<Data> {
|
|
|
|
|
|
|
|
private static final PacketExtensionProvider packetExtensionProvider = new PacketExtensionProvider();
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
|
|
|
public Data parse(XmlPullParser parser, int initialDepth)
|
2015-03-13 09:27:18 +01:00
|
|
|
throws Exception {
|
2014-10-07 21:15:20 +02:00
|
|
|
DataPacketExtension data = packetExtensionProvider.parse(parser);
|
2017-12-13 23:10:11 +01:00
|
|
|
return new Data(data);
|
2014-10-07 21:15:20 +02:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
public static class PacketExtensionProvider extends org.jivesoftware.smack.provider.ExtensionElementProvider<DataPacketExtension> {
|
2014-10-07 21:15:20 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public DataPacketExtension parse(XmlPullParser parser,
|
|
|
|
int initialDepth) throws XmlPullParserException,
|
|
|
|
IOException {
|
|
|
|
String sessionID = parser.getAttributeValue("", "sid");
|
|
|
|
long seq = Long.parseLong(parser.getAttributeValue("", "seq"));
|
|
|
|
String data = parser.nextText();
|
|
|
|
return new DataPacketExtension(sessionID, seq, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|