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

📄 mxparser.java

📁 基于Jabber协议的即时消息服务器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * $RCSfile: $ * $Revision: 3135 $ * $Date: 2005-12-01 02:03:04 -0300 (Thu, 01 Dec 2005) $ * * Copyright (C) 2005 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. */package org.jivesoftware.wildfire.net;import org.xmlpull.v1.XmlPullParserException;import org.xmlpull.v1.XmlPullParser;import java.io.IOException;import java.io.Reader;/** * MXParser that returns an IGNORABLE_WHITESPACE event when a whitespace character or a * line feed is received. This parser is useful when not validating documents. * * @author Gaston Dombiak */public class MXParser extends org.xmlpull.mxp1.MXParser {    /**     * Last time a heartbeat was received. Hearbeats are represented as whitespaces     * or \n characters received when an XmlPullParser.END_TAG was parsed. Note that we     * can falsely detect heartbeats when parsing XHTML content but that is fine.     */    private long lastHeartbeat = 0;    protected int nextImpl()        throws XmlPullParserException, IOException    {        text = null;        pcEnd = pcStart = 0;        usePC = false;        bufStart = posEnd;        if(pastEndTag) {            pastEndTag = false;            --depth;            namespaceEnd = elNamespaceCount[ depth ]; // less namespaces available        }        if(emptyElementTag) {            emptyElementTag = false;            pastEndTag = true;            return eventType = END_TAG;        }        // [1] document ::= prolog element Misc*        if(depth > 0) {            if(seenStartTag) {                seenStartTag = false;                return eventType = parseStartTag();            }            if(seenEndTag) {                seenEndTag = false;                return eventType = parseEndTag();            }            // ASSUMPTION: we are _on_ first character of content or markup!!!!            // [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*            char ch;            if(seenMarkup) {  // we have read ahead ...                seenMarkup = false;                ch = '<';            } else if(seenAmpersand) {                seenAmpersand = false;                ch = '&';            } else {                ch = more();            }            posStart = pos - 1; // VERY IMPORTANT: this is correct start of event!!!            // when true there is some potential event TEXT to return - keep gathering            boolean hadCharData = false;            // when true TEXT data is not continous (like <![CDATA[text]]>) and requires PC merging            boolean needsMerging = false;            MAIN_LOOP:            while(true) {                // work on MARKUP                if(ch == '<') {                    if(hadCharData) {                        //posEnd = pos - 1;                        if(tokenize) {                            seenMarkup = true;                            return eventType = TEXT;                        }                    }                    ch = more();                    if(ch == '/') {                        if(!tokenize && hadCharData) {                            seenEndTag = true;                            //posEnd = pos - 2;                            return eventType = TEXT;                        }                        return eventType = parseEndTag();                    } else if(ch == '!') {                        ch = more();                        if(ch == '-') {                            // note: if(tokenize == false) posStart/End is NOT changed!!!!                            parseComment();                            if(tokenize) return eventType = COMMENT;                            if( !usePC && hadCharData ) {                                needsMerging = true;                            } else {                                posStart = pos;  //completely ignore comment                            }                        } else if(ch == '[') {                            //posEnd = pos - 3;                            // must remeber previous posStart/End as it merges with content of CDATA                            //int oldStart = posStart + bufAbsoluteStart;                            //int oldEnd = posEnd + bufAbsoluteStart;                            parseCDSect(hadCharData);                            if(tokenize) return eventType = CDSECT;                            final int cdStart = posStart;                            final int cdEnd = posEnd;                            final int cdLen = cdEnd - cdStart;                            if(cdLen > 0) { // was there anything inside CDATA section?                                hadCharData = true;                                if(!usePC) {                                    needsMerging = true;                                }                            }                            //                          posStart = oldStart;                            //                          posEnd = oldEnd;                            //                          if(cdLen > 0) { // was there anything inside CDATA section?                            //                              if(hadCharData) {                            //                                  // do merging if there was anything in CDSect!!!!                            //                                  //                                    if(!usePC) {                            //                                  //                                        // posEnd is correct already!!!                            //                                  //                                        if(posEnd > posStart) {                            //                                  //                                            joinPC();                            //                                  //                                        } else {                            //                                  //                                            usePC = true;                            //                                  //                                            pcStart = pcEnd = 0;                            //                                  //                                        }                            //                                  //                                    }                            //                                  //                                    if(pcEnd + cdLen >= pc.length) ensurePC(pcEnd + cdLen);                            //                                  //                                    // copy [cdStart..cdEnd) into PC                            //                                  //                                    System.arraycopy(buf, cdStart, pc, pcEnd, cdLen);                            //                                  //                                    pcEnd += cdLen;                            //                                  if(!usePC) {                            //                                      needsMerging = true;                            //                                      posStart = cdStart;                            //                                      posEnd = cdEnd;                            //                                  }                            //                              } else {                            //                                  if(!usePC) {                            //                                      needsMerging = true;                            //                                      posStart = cdStart;                            //                                      posEnd = cdEnd;                            //                                      hadCharData = true;                            //                                  }                            //                              }                            //                              //hadCharData = true;                            //                          } else {                            //                              if( !usePC && hadCharData ) {                            //                                  needsMerging = true;                            //                              }                            //                          }                        } else {                            throw new XmlPullParserException(                                "unexpected character in markup "+printable(ch), this, null);                        }                    } else if(ch == '?') {                        parsePI();                        if(tokenize) return eventType = PROCESSING_INSTRUCTION;                        if( !usePC && hadCharData ) {

⌨️ 快捷键说明

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