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

📄 parser.java

📁 cisco-2950交换机的应用程序的源代码
💻 JAVA
字号:
// 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) fieldsfirst ansi 
// Source File Name:   Parser.java

package cisco.dsbu.cms.boot.internal.xmllite;

import java.io.*;
import java.util.LinkedList;
import java.util.List;

// Referenced classes of package cisco.dsbu.cms.boot.internal.xmllite:
//            Buffer, Handler, ParseException, CharString

public class Parser
{

    private static final int DEFAULT_BUFFER_SIZE = 8192;
    private boolean isParsing;
    private Buffer buffer;
    private List handlers;
    private List elements;
    private int ignoreDepth;

    public Parser()
    {
        handlers = new LinkedList();
        elements = new LinkedList();
        ignoreDepth = 0;
        buffer = new Buffer(8192);
    }

    public Parser(int i)
    {
        handlers = new LinkedList();
        elements = new LinkedList();
        ignoreDepth = 0;
        buffer = new Buffer(i);
    }

    public void setSource(Reader reader)
        throws IllegalStateException
    {
        throwExceptionIf(isParsing, "Parsing is already in progress.");
        buffer.setSource(reader);
    }

    public void pushHandler(Handler handler)
    {
        handlers.add(0, handler);
    }

    public Handler popHandler()
    {
        Handler handler = null;
        if(!handlers.isEmpty())
            handler = (Handler)handlers.remove(0);
        return handler;
    }

    public void startParsing()
        throws IllegalStateException, IOException, ParseException
    {
        throwExceptionIf(isParsing, "Parsing is already in progress.");
        throwExceptionIf(handlers.isEmpty(), "A handler has not been set.");
        Handler handler = (Handler)handlers.get(0);
        isParsing = true;
        handler.startDocument(this);
        do
        {
            try
            {
                char c = buffer.peek();
                if(c == '<')
                    handleTagStart(handler);
                else
                if(Character.isWhitespace(c))
                    handleWhiteSpace();
                else
                    handleElementData(handler);
            }
            catch(EOFException eofexception)
            {
                break;
            }
            throwExceptionIf(handlers.isEmpty(), "A handler has not been set.");
            handler = (Handler)handlers.get(0);
        } while(true);
        if(!elements.isEmpty())
        {
            throw new ParseException(this, "Unexpected end-of-document");
        } else
        {
            handler.endDocument(this);
            isParsing = false;
            return;
        }
    }

    private void handleTagStart(Handler handler)
        throws IOException, ParseException
    {
        buffer.readCharacter();
        char c = buffer.peek();
        if(c == '?' || c == '!')
            handleIgnore();
        else
        if(c == '/')
        {
            handleEndElement(handler);
        } else
        {
            if(Character.isWhitespace(c))
                throw new ParseException(this, "White space is not allowed after <");
            handleStartElement(handler);
        }
    }

    private void handleWhiteSpace()
        throws IOException
    {
        do
        {
            int i = buffer.findNonWhiteSpace();
            if(i == -1)
            {
                buffer.readCharacters();
            } else
            {
                buffer.readCharacters(i - 1);
                return;
            }
        } while(true);
    }

    private void handleElementData(Handler handler)
        throws IOException, ParseException
    {
        int i = buffer.find('<');
        if(i == -1)
            throw new ParseException(this, "Element data exceeds buffer size.");
        CharString charstring = buffer.readCharacters(i - 1).trim();
        if(ignoreDepth == 0)
            handler.elementData(this, charstring);
    }

    private void handleIgnore()
        throws IOException
    {
        do
        {
            int i = buffer.find('>');
            if(i == -1)
            {
                buffer.readCharacters();
            } else
            {
                buffer.readCharacters(i);
                return;
            }
        } while(true);
    }

    private void handleEndElement(Handler handler)
        throws IOException, ParseException
    {
        buffer.readCharacter();
        int i = buffer.find('>');
        if(i == -1)
            throw new ParseException(this, "End tag exceeds buffer size.");
        CharString charstring = buffer.readCharacters(i - 1).trim();
        if(ignoreDepth > 0)
        {
            CharString charstring1 = (CharString)elements.get(0);
            if(charstring.equals(charstring1))
            {
                elements.remove(0);
                ignoreDepth--;
            }
        } else
        {
            CharString charstring2 = (CharString)elements.get(0);
            if(!charstring.equals(charstring2))
                throw new ParseException(this, charstring2 + " closed by " + charstring);
            elements.remove(0);
            handler.endElement(this, charstring);
        }
        buffer.readCharacter();
    }

    private void handleStartElement(Handler handler)
        throws IOException, ParseException
    {
        int i = buffer.find('>');
        if(i == -1)
            throw new ParseException(this, "Start tag exceeds buffer size.");
        CharString charstring = buffer.readCharacters(i - 1).trim();
        if(ignoreDepth > 0)
        {
            CharString charstring1 = (CharString)elements.get(0);
            if(charstring.equals(charstring1))
            {
                elements.add(0, charstring1);
                ignoreDepth++;
            }
        } else
        {
            CharString charstring2 = handler.startElement(this, charstring);
            if(charstring2 == null)
            {
                elements.add(0, new CharString(charstring));
                ignoreDepth++;
            } else
            {
                elements.add(0, charstring2);
            }
        }
        buffer.readCharacter();
    }

    private void throwExceptionIf(boolean flag, String s)
        throws IllegalStateException
    {
        if(flag)
            throw new IllegalStateException(s);
        else
            return;
    }
}

⌨️ 快捷键说明

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