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

📄 xmlparser.java

📁 Sony Ericsson手机上的Facebook客户端全套代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   XMLParser.java

package se.southend.drops.xml;

import java.io.*;
import java.util.*;

// Referenced classes of package se.southend.drops.xml:
//            XMLNode, XMLListener

public class XMLParser
{
    private class Request
    {

        private InputStream in;
        private XMLListener destination;



        private Request(InputStream in, XMLListener destination)
        {
            this.in = in;
            this.destination = destination;
        }

        Request(InputStream x1, XMLListener x2, _cls1 x3)
        {
            this(x1, x2);
        }
    }


    public XMLParser()
    {
        listener = null;
        node = null;
        parent = null;
    }

    public void parseLowerCase(boolean enabled)
    {
        lowerCase = enabled;
    }

    public String getTag()
    {
        return getTag(0);
    }

    public String getTag(int depth)
    {
        return tags != null && tags.size() > depth ? (String)tags.elementAt(tags.size() - depth - 1) : null;
    }

    public int getDepth()
    {
        return depth;
    }

    public int getLineNbr()
    {
        return line;
    }

    public int getColNbr()
    {
        return col;
    }

    public static XMLParser getInstance()
    {
        if(instance == null)
            instance = new XMLParser();
        return instance;
    }

    public synchronized boolean add(InputStream in, XMLListener destination)
        throws Exception
    {
        if(parseQueue == null)
            parseQueue = new Vector(1);
        parseQueue.addElement(new Request(in, destination, null));
        if(parseQueue.size() == 1)
        {
            open(in, destination);
            return true;
        } else
        {
            return false;
        }
    }

    public void open(InputStream in, XMLListener destination)
        throws Exception
    {
        line = 1;
        col = 0;
        mode = 15;
        quotec = 34;
        listener = destination;
        reader = new InputStreamReader(in, "UTF-8");
        sb = new StringBuffer();
        etag = new StringBuffer();
        tagStack = new Stack();
        listener.startDocument();
        tags = new Vector();
        parse();
    }

    public XMLNode open(InputStream in)
        throws Exception
    {
        line = 1;
        col = 0;
        mode = 15;
        quotec = 34;
        reader = new InputStreamReader(in, "UTF-8");
        sb = new StringBuffer();
        etag = new StringBuffer();
        tagStack = new Stack();
        tags = new Vector();
        parse();
        XMLNode root = node;
        node = null;
        parent = null;
        return root;
    }

    private void parse()
        throws Exception
    {
        while(step()) ;
        reset();
    }

    private boolean step()
        throws Exception
    {
        boolean ready = false;
        do
        {
            if(ready)
                break;
            int c = reader.read();
            if(c == -1)
                return false;
            if(mode == 2 && c != 59 && (c < 97 || c > 122))
            {
                sb.append('&');
                sb.append(etag);
                mode = popMode(tagStack);
            }
            if(c == 10 && eol)
            {
                eol = false;
                return step();
            }
            if(eol)
                eol = false;
            else
            if(c == 10)
            {
                line++;
                col = 0;
            } else
            if(c == 13)
            {
                eol = true;
                c = 10;
                line++;
                col = 0;
            } else
            {
                col++;
            }
            if(mode != 13)
                if(mode == 1)
                {
                    if(c == 60)
                    {
                        tagStack.push(new Integer(mode));
                        mode = 5;
                        if(sb.length() > 0)
                        {
                            int i = 0;
                            do
                            {
                                if(i >= sb.length())
                                    break;
                                if(!isWhitespace(sb.charAt(i)))
                                {
                                    if(listener != null)
                                        listener.text(sb.toString());
                                    else
                                    if(node != null)
                                        node.setValue(sb.toString());
                                    ready = true;
                                    break;
                                }
                                i++;
                            } while(true);
                            sb.setLength(0);
                        }
                    } else
                    if(c == 38)
                    {
                        tagStack.push(new Integer(mode));
                        mode = 2;
                        etag.setLength(0);
                    } else
                    {
                        sb.append((char)c);
                    }
                } else
                if(mode == 4)
                {
                    if(c == 62)
                    {
                        mode = popMode(tagStack);
                        tagName = sb.toString();
                        if(lowerCase)
                            tagName = tagName.toLowerCase();
                        sb.setLength(0);
                        depth--;
                        if(depth == 0)
                            mode = 13;
                        tags.removeElementAt(tags.size() - 1);
                        if(listener != null)
                            listener.endElement(tagName);
                        else
                        if(parent != null)
                        {
                            parent.addChild(node);
                            node = parent;
                            parent = parent.getParent();
                        }
                        ready = true;
                    } else
                    {
                        sb.append((char)c);
                    }
                } else
                if(mode == 16)
                {
                    if(c == 62 && sb.toString().endsWith("]]"))
                    {
                        sb.setLength(sb.length() - 2);
                        if(listener != null)
                            listener.text(sb.toString());
                        else
                        if(node != null)
                            node.setValue(sb.toString());
                        ready = true;
                        sb.setLength(0);
                        mode = popMode(tagStack);
                    } else
                    {
                        sb.append((char)c);
                    }
                } else
                if(mode == 12)
                {
                    if(c == 62 && sb.toString().endsWith("--"))
                    {
                        sb.setLength(0);
                        mode = popMode(tagStack);
                    } else
                    {
                        sb.append((char)c);
                    }
                } else
                if(mode == 15)
                {
                    if(c == 60)
                    {
                        mode = 1;
                        tagStack.push(new Integer(mode));
                        mode = 5;
                    }
                } else
                if(mode == 14)
                {
                    if(c == 62)
                    {
                        mode = popMode(tagStack);
                        if(mode == 1)
                            mode = 15;
                    }
                } else
                if(mode == 5)
                {
                    mode = popMode(tagStack);
                    if(c == 47)
                    {
                        tagStack.push(new Integer(mode));
                        mode = 4;
                    } else
                    if(c == 63)
                    {
                        mode = 14;
                    } else
                    {
                        tagStack.push(new Integer(mode));
                        mode = 3;
                        tagName = null;
                        attrs = new Hashtable();
                        sb.append((char)c);
                    }
                } else
                if(mode == 2)
                {
                    if(c == 59)
                    {
                        mode = popMode(tagStack);
                        String cent = etag.toString().intern();

⌨️ 快捷键说明

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