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

📄 xmlparser.java

📁 Sony Ericsson手机上的Facebook客户端全套代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        etag.setLength(0);
                        if(cent == "lt")
                            sb.append('<');
                        else
                        if(cent == "gt")
                            sb.append('>');
                        else
                        if(cent == "amp")
                            sb.append('&');
                        else
                        if(cent == "quot")
                            sb.append('"');
                        else
                        if(cent == "apos")
                            sb.append('\'');
                        else
                        if(cent == "trade")
                            sb.append('\u2122');
                        else
                        if(cent == "ordf")
                            sb.append('\252');
                        else
                        if(cent.startsWith("#"))
                            sb.append((char)Integer.parseInt(cent.substring(1)));
                        else
                            error("Unknown entity: &" + cent + ";", line, col);
                    } else
                    {
                        etag.append((char)c);
                    }
                } else
                if(mode == 11)
                {
                    if(tagName == null)
                    {
                        tagName = sb.toString();
                        if(lowerCase)
                            tagName = tagName.toLowerCase();
                    }
                    if(c != 62)
                        error("Expected > for tag: <" + tagName + "/>", line, col);
                    tags.addElement(tagName);
                    if(listener != null)
                    {
                        listener.startElement(tagName, attrs);
                    } else
                    {
                        parent = node;
                        node = new XMLNode(tagName, parent);
                        node.setParameters(attrs);
                    }
                    tags.removeElementAt(tags.size() - 1);
                    if(listener != null)
                        listener.endElement(tagName);
                    else
                    if(parent != null)
                    {
                        parent.addChild(node);
                        node = parent;
                        parent = parent.getParent();
                    }
                    if(depth == 0)
                    {
                        if(listener != null)
                            listener.endDocument();
                        return false;
                    }
                    ready = true;
                    sb.setLength(0);
                    attrs = new Hashtable();
                    tagName = null;
                    mode = popMode(tagStack);
                } else
                if(mode == 3)
                {
                    if(c == 62)
                    {
                        if(tagName == null)
                        {
                            tagName = sb.toString();
                            if(lowerCase)
                                tagName = tagName.toLowerCase();
                        }
                        sb.setLength(0);
                        tags.addElement(tagName);
                        if(listener != null)
                        {
                            listener.startElement(tagName, attrs);
                        } else
                        {
                            parent = node;
                            node = new XMLNode(tagName, parent);
                            node.setParameters(attrs);
                        }
                        ready = true;
                        depth++;
                        tagName = null;
                        attrs = new Hashtable();
                        mode = popMode(tagStack);
                    } else
                    if(c == 47)
                        mode = 11;
                    else
                    if(c == 45 && sb.toString().equals("!-"))
                        mode = 12;
                    else
                    if(c == 91 && sb.toString().equals("![CDATA"))
                    {
                        mode = 16;
                        sb.setLength(0);
                    } else
                    if(c == 69 && sb.toString().equals("!DOCTYP"))
                    {
                        sb.setLength(0);
                        mode = 14;
                    } else
                    if(isWhitespace(c))
                    {
                        tagName = sb.toString();
                        if(lowerCase)
                            tagName = tagName.toLowerCase();
                        sb.setLength(0);
                        mode = 10;
                    } else
                    {
                        sb.append((char)c);
                    }
                } else
                if(mode == 9)
                {
                    if(c == quotec)
                    {
                        rvalue = sb.toString();
                        sb.setLength(0);
                        if(lowerCase)
                            lvalue = lvalue.toLowerCase();
                        attrs.put(lvalue, rvalue);
                        mode = 10;
                    } else
                    if(" \r\n\t".indexOf(c) >= 0)
                        sb.append(' ');
                    else
                    if(c == 38)
                    {
                        tagStack.push(new Integer(mode));
                        mode = 2;
                        etag.setLength(0);
                    } else
                    {
                        sb.append((char)c);
                    }
                } else
                if(mode == 8)
                {
                    if(c == 34 || c == 39)
                    {
                        quotec = c;
                        mode = 9;
                    } else
                    if(!isWhitespace(c))
                        error("Error in attribute processing", line, col);
                } else
                if(mode == 6)
                {
                    if(isWhitespace(c))
                    {
                        lvalue = sb.toString();
                        sb.setLength(0);
                        mode = 7;
                    } else
                    if(c == 61)
                    {
                        lvalue = sb.toString();
                        sb.setLength(0);
                        mode = 8;
                    } else
                    {
                        sb.append((char)c);
                    }
                } else
                if(mode == 7)
                {
                    if(c == 61)
                        mode = 8;
                    else
                    if(!isWhitespace(c))
                        error("Error in attribute processing.", line, col);
                } else
                if(mode == 10)
                    if(c == 62)
                    {
                        mode = popMode(tagStack);
                        tags.addElement(tagName);
                        if(listener != null)
                        {
                            listener.startElement(tagName, attrs);
                        } else
                        {
                            parent = node;
                            node = new XMLNode(tagName, parent);
                            node.setParameters(attrs);
                        }
                        ready = true;
                        depth++;
                        tagName = null;
                        attrs = new Hashtable();
                    } else
                    if(c == 47)
                        mode = 11;
                    else
                    if(!isWhitespace(c))
                    {
                        mode = 6;
                        sb.append((char)c);
                    }
        } while(true);
        if(mode == 13)
        {
            if(listener != null)
                listener.endDocument();
            return false;
        } else
        {
            return true;
        }
    }

    public void close()
    {
        mode = 13;
    }

    private synchronized void reset()
        throws Exception
    {
        listener = null;
        reader = null;
        sb = null;
        etag = null;
        tagStack = null;
        tags = null;
        if(parseQueue != null)
            if(parseQueue.size() > 1)
            {
                parseQueue.removeElementAt(0);
                Request request = (Request)parseQueue.elementAt(0);
                open(request.in, request.destination);
            } else
            {
                parseQueue = null;
            }
    }

    private int popMode(Stack st)
    {
        if(!st.empty())
            return ((Integer)st.pop()).intValue();
        else
            return 15;
    }

    private static boolean isWhitespace(int character)
    {
        return character <= 32;
    }

    private static void error(String s, int line, int col)
        throws Exception
    {
        System.out.println("Error at line " + line + ", col " + col + ": " + s);
    }

    private static final int TEXT = 1;
    private static final int ENTITY = 2;
    private static final int OPEN_TAG = 3;
    private static final int CLOSE_TAG = 4;
    private static final int START_TAG = 5;
    private static final int ATTRIBUTE_LVALUE = 6;
    private static final int ATTRIBUTE_EQUAL = 7;
    private static final int ATTRIBUTE_RVALUE = 8;
    private static final int QUOTE = 9;
    private static final int IN_TAG = 10;
    private static final int SINGLE_TAG = 11;
    private static final int COMMENT = 12;
    private static final int DONE = 13;
    private static final int DOCTYPE = 14;
    private static final int PRE = 15;
    private static final int CDATA = 16;
    private static XMLParser instance;
    private Vector parseQueue;
    private int depth;
    private XMLListener listener;
    private Reader reader;
    private Vector tags;
    private StringBuffer etag;
    private StringBuffer sb;
    private Stack tagStack;
    private String tagName;
    private String lvalue;
    private String rvalue;
    private Hashtable attrs;
    private boolean eol;
    private int line;
    private int col;
    private int mode;
    private int quotec;
    private boolean lowerCase;
    private XMLNode node;
    private XMLNode parent;

// Unreferenced inner classes:

/* anonymous class */
    static class _cls1
    {
    }

}

⌨️ 快捷键说明

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