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.util.Locale; 020 021import org.jivesoftware.smack.packet.IQ; 022import org.jivesoftware.smack.provider.IQProvider; 023import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType; 024import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; 025import org.xmlpull.v1.XmlPullParser; 026 027/** 028 * Parses an In-Band Bytestream open packet. 029 * 030 * @author Henning Staib 031 */ 032public class OpenIQProvider implements IQProvider { 033 034 public IQ parseIQ(XmlPullParser parser) throws Exception { 035 String sessionID = parser.getAttributeValue("", "sid"); 036 int blockSize = Integer.parseInt(parser.getAttributeValue("", "block-size")); 037 038 String stanzaValue = parser.getAttributeValue("", "stanza"); 039 StanzaType stanza = null; 040 if (stanzaValue == null) { 041 stanza = StanzaType.IQ; 042 } 043 else { 044 stanza = StanzaType.valueOf(stanzaValue.toUpperCase(Locale.US)); 045 } 046 047 return new Open(sessionID, blockSize, stanza); 048 } 049 050}