001/** 002 * 003 * Copyright the original author or authors 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 */ 017package org.jivesoftware.smackx.bytestreams.ibb.provider; 018 019import java.io.IOException; 020import java.util.Locale; 021 022import org.jivesoftware.smack.provider.IQProvider; 023 024import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType; 025import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; 026 027import org.xmlpull.v1.XmlPullParser; 028import org.xmlpull.v1.XmlPullParserException; 029 030/** 031 * Parses an In-Band Bytestream open packet. 032 * 033 * @author Henning Staib 034 */ 035public class OpenIQProvider extends IQProvider<Open> { 036 037 @Override 038 public Open parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException { 039 String sessionID = parser.getAttributeValue("", "sid"); 040 int blockSize = Integer.parseInt(parser.getAttributeValue("", "block-size")); 041 042 String stanzaValue = parser.getAttributeValue("", "stanza"); 043 StanzaType stanza; 044 if (stanzaValue == null) { 045 stanza = StanzaType.IQ; 046 } 047 else { 048 stanza = StanzaType.valueOf(stanzaValue.toUpperCase(Locale.US)); 049 } 050 051 parser.next(); 052 053 return new Open(sessionID, blockSize, stanza); 054 } 055 056}