Home | History | Annotate | Download | only in provider
      1 /**
      2  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      3  * you may not use this file except in compliance with the License.
      4  * You may obtain a copy of the License at
      5  *
      6  *     http://www.apache.org/licenses/LICENSE-2.0
      7  *
      8  * Unless required by applicable law or agreed to in writing, software
      9  * distributed under the License is distributed on an "AS IS" BASIS,
     10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     11  * See the License for the specific language governing permissions and
     12  * limitations under the License.
     13  */
     14 package org.jivesoftware.smackx.bytestreams.ibb.provider;
     15 
     16 import org.jivesoftware.smack.packet.IQ;
     17 import org.jivesoftware.smack.packet.PacketExtension;
     18 import org.jivesoftware.smack.provider.IQProvider;
     19 import org.jivesoftware.smack.provider.PacketExtensionProvider;
     20 import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
     21 import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
     22 import org.xmlpull.v1.XmlPullParser;
     23 
     24 /**
     25  * Parses an In-Band Bytestream data packet which can be a packet extension of
     26  * either an IQ stanza or a message stanza.
     27  *
     28  * @author Henning Staib
     29  */
     30 public class DataPacketProvider implements PacketExtensionProvider, IQProvider {
     31 
     32     public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
     33         String sessionID = parser.getAttributeValue("", "sid");
     34         long seq = Long.parseLong(parser.getAttributeValue("", "seq"));
     35         String data = parser.nextText();
     36         return new DataPacketExtension(sessionID, seq, data);
     37     }
     38 
     39     public IQ parseIQ(XmlPullParser parser) throws Exception {
     40         DataPacketExtension data = (DataPacketExtension) parseExtension(parser);
     41         IQ iq = new Data(data);
     42         return iq;
     43     }
     44 
     45 }
     46