⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 streaminitiationprovider.java

📁 JBother是纯Java开发的Jabber(即时消息开源软件)客户端。支持群组聊天
💻 JAVA
字号:
/** * $RCSfile$ * $Revision: 2407 $ * $Date: 2004-11-02 17:37:00 -0600 (Tue, 02 Nov 2004) $ * * Copyright 2003-2004 Jive Software. * * All rights reserved. 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.provider;import org.jivesoftware.smack.provider.IQProvider;import org.jivesoftware.smack.packet.IQ;import org.jivesoftware.smackx.packet.DataForm;import org.xmlpull.v1.XmlPullParser;import org.jivesoftware.smackx.packet.*;/** * Implementation of provider class for StreamInitiation objects. * It will parse XML code for <si> messages and return StreamInitiation object. * * @author Lukasz Wiechec */public class StreamInitiationProvider implements IQProvider {    /**     * Parses this IQ Packet     *@param parser the parser to use     *@throws Exception when a parsing error has occurred     */    public IQ parseIQ(XmlPullParser parser) throws Exception {        StreamInitiation si = new StreamInitiation();        boolean done = false;        String fileName = "";        long fileSize = -1;        String fileHash = null;        String description = "";        StreamInitiation.Feature feature = null;        String id = parser.getAttributeValue("","id");        while (!done) {            int eventType = parser.next();            String elementName = parser.getName();            String namespace = parser.getNamespace();            if (eventType == XmlPullParser.START_TAG) {                if (elementName.equals("file")) {                    try {                        fileSize = Long.parseLong(parser.getAttributeValue("","size"));                        fileName = parser.getAttributeValue("","name");                        fileHash = parser.getAttributeValue("","hash");                    }                    catch(Exception ex) { }                } else if (elementName.equals("desc")) {                    int eType = parser.next();                    if( eType == XmlPullParser.END_TAG ) {                        description = "";                    } else {                        description = parser.getText();                        // @todo there is probably better way to do it...                        if(description.equals("<desc/>")) {                            description="";                        }                    }                } else if (elementName.equals("feature")) {                } else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {                    DataFormProvider dataFormProvider = new DataFormProvider();                    DataForm dataForm = (DataForm)dataFormProvider.parseExtension(parser);                    feature = new StreamInitiation.Feature(dataForm.getType());                    feature.setDataForm(dataForm);                }            } else if (eventType == XmlPullParser.END_TAG && elementName.equals("si")) {                done = true;            }        }        if( fileName.length() > 0 && fileSize > -1 ) {            StreamInitiation.FileDetails fd = new StreamInitiation.FileDetails(fileName);            fd.setFileSize(fileSize);            fd.setDescription(description);            fd.setHash(fileHash);            si.setFileDetails(fd);        }        si.setFeature(feature);        si.setSid(id);        return si;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -