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

📄 parserimpl.java

📁 windows 代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    };

    public static class ParseFrameSet implements Parser {

        public void parse( Lexer lexer, Node frameset, short mode )
        {
            Node node;

            lexer.badAccess |=  Report.USING_FRAMES;

            while (true)
            {
                node = lexer.getToken(Lexer.IgnoreWhitespace);
                if (node == null) break;
                if (node.tag == frameset.tag && node.type == Node.EndTag)
                {
                    frameset.closed = true;
                    Node.trimSpaces(lexer, frameset);
                    return;
                }

                /* deal with comments etc. */
                if (Node.insertMisc(frameset, node))
                    continue;

                if (node.tag == null)
                {
                    Report.warning(lexer, frameset, node, Report.DISCARDING_UNEXPECTED);
                    continue; 
                }

                if (node.type == Node.StartTag || node.type == Node.StartEndTag)
                {
                    if (node.tag != null && (node.tag.model & Dict.CM_HEAD) != 0)
                    {
                        moveToHead(lexer, frameset, node);
                        continue;
                    }
                }

                if (node.tag == TagTable.tagBody)
                {
                    lexer.ungetToken();
                    node = lexer.inferredTag("noframes");
                    Report.warning(lexer, frameset, node, Report.INSERTING_TAG);
                }

                if (node.type == Node.StartTag && (node.tag.model & Dict.CM_FRAMES) != 0)
                {
                    Node.insertNodeAtEnd(frameset, node);
                    lexer.excludeBlocks = false;
                    parseTag(lexer, node, Lexer.MixedContent);
                    continue;
                }
                else if (node.type == Node.StartEndTag && (node.tag.model & Dict.CM_FRAMES) != 0)
                {
                    Node.insertNodeAtEnd(frameset, node);
                    continue;
                }

                /* discard unexpected tags */
                Report.warning(lexer, frameset, node, Report.DISCARDING_UNEXPECTED);
            }

            Report.warning(lexer, frameset, node, Report.MISSING_ENDTAG_FOR);
        }

    };

    public static class ParseInline implements Parser {

        public void parse( Lexer lexer, Node element, short mode )
        {
            Node node, parent;

            if ((element.tag.model & Dict.CM_EMPTY) != 0)
                return;

            if (element.tag == TagTable.tagA)
            {
                if (element.attributes == null)
                {
                    Report.warning(lexer, element.parent, element, Report.DISCARDING_UNEXPECTED);
                    Node.discardElement(element);
                    return;
                }
            }

            /*
             ParseInline is used for some block level elements like H1 to H6
             For such elements we need to insert inline emphasis tags currently
             on the inline stack. For Inline elements, we normally push them
             onto the inline stack provided they aren't implicit or OBJECT/APPLET.
             This test is carried out in PushInline and PopInline, see istack.c
             We don't push A or SPAN to replicate current browser behavior
            */
            if (((element.tag.model & Dict.CM_BLOCK) != 0) || (element.tag == TagTable.tagDt))
                lexer.inlineDup( null);
            else if ((element.tag.model & Dict.CM_INLINE) != 0 &&
                        element.tag != TagTable.tagA && element.tag != TagTable.tagSpan)
                lexer.pushInline( element);

            if (element.tag == TagTable.tagNobr)
                lexer.badLayout |= Report.USING_NOBR;
            else if (element.tag == TagTable.tagFont)
                lexer.badLayout |= Report.USING_FONT;

            /* Inline elements may or may not be within a preformatted element */
            if (mode != Lexer.Preformatted)
                mode = Lexer.MixedContent;

            while (true)
            {
                node = lexer.getToken(mode);
                if (node == null) break;
                /* end tag for current element */
                if (node.tag == element.tag && node.type == Node.EndTag)
                {
                    if ((element.tag.model & Dict.CM_INLINE) != 0 &&
                        element.tag != TagTable.tagA)
                        lexer.popInline( node);

                    if (!((mode & Lexer.Preformatted) != 0))
                        Node.trimSpaces(lexer, element);
                    /*
                     if a font element wraps an anchor and nothing else
                     then move the font element inside the anchor since
                     otherwise it won't alter the anchor text color
                    */
                    if (element.tag == TagTable.tagFont &&
                        element.content != null &&
                        element.content == element.last)
                    {
                        Node child = element.content;

                        if (child.tag == TagTable.tagA)
                        {
                            child.parent = element.parent;
                            child.next = element.next;
                            child.prev = element.prev;

                            if (child.prev != null)
                                child.prev.next = child;
                            else
                                child.parent.content = child;

                            if (child.next != null)
                                child.next.prev = child;
                            else
                                child.parent.last = child;

                            element.next = null;
                            element.prev = null;
                            element.parent = child;
                            element.content = child.content;
                            element.last = child.last;
                            child.content = element;
                            child.last = element;
                            for (child = element.content; child != null; child = child.next)
                                child.parent = element;
                        }
                    }
                    element.closed = true;
                    Node.trimSpaces(lexer, element);
                    Node.trimEmptyElement(lexer, element);
                    return;
                }

                /* <u>...<u>  map 2nd <u> to </u> if 1st is explicit */
                /* otherwise emphasis nesting is probably unintentional */
                /* big and small have cumulative effect to leave them alone */
                if (node.type == Node.StartTag
                        && node.tag == element.tag
                        && lexer.isPushed(node)
                        && !node.implicit
                        && !element.implicit
                        && node.tag != null && ((node.tag.model & Dict.CM_INLINE) != 0)
                        && node.tag != TagTable.tagA
                        && node.tag != TagTable.tagFont
                        && node.tag != TagTable.tagBig
                        && node.tag != TagTable.tagSmall)
                {
                    if (element.content != null && node.attributes == null)
                    {
                        Report.warning(lexer, element, node, Report.COERCE_TO_ENDTAG);
                        node.type = Node.EndTag;
                        lexer.ungetToken();
                        continue;
                    }

                    Report.warning(lexer, element, node, Report.NESTED_EMPHASIS);
                }

                if (node.type == Node.TextNode)
                {
                    /* only called for 1st child */
                    if (element.content == null &&
                        !((mode & Lexer.Preformatted) != 0))
                        Node.trimSpaces(lexer, element);

                    if (node.start >= node.end)
                    {
                        continue;
                    }

                    Node.insertNodeAtEnd(element, node);
                    continue;
                }

                /* mixed content model so allow text */
                if (Node.insertMisc(element, node))
                    continue;

                /* deal with HTML tags */
                if (node.tag == TagTable.tagHtml)
                {
                    if (node.type == Node.StartTag || node.type == Node.StartEndTag)
                    {
                        Report.warning(lexer, element, node, Report.DISCARDING_UNEXPECTED);
                        continue;
                    }

                    /* otherwise infer end of inline element */
                    lexer.ungetToken();
                    if (!((mode & Lexer.Preformatted) != 0))
                        Node.trimSpaces(lexer, element);
                    Node.trimEmptyElement(lexer, element);
                    return;
                }

                /* within <dt> or <pre> map <p> to <br> */
                if (node.tag == TagTable.tagP &&
                      node.type == Node.StartTag &&
                      ((mode & Lexer.Preformatted) != 0 ||
                       element.tag == TagTable.tagDt ||
                      element.isDescendantOf(TagTable.tagDt)))
                {
                    node.tag = TagTable.tagBr;
                    node.element = new String("br");
                    Node.trimSpaces(lexer, element);
                    Node.insertNodeAtEnd(element, node);
                    continue;
                }

                /* ignore unknown and PARAM tags */
                if (node.tag == null || node.tag == TagTable.tagParam)
                {
                    Report.warning(lexer, element, node, Report.DISCARDING_UNEXPECTED);
                    continue;
                }

                if (node.tag == TagTable.tagBr && node.type == Node.EndTag)
                    node.type = Node.StartTag;

                if (node.type == Node.EndTag)
                {
                    /* coerce </br> to <br> */
                    if (node.tag == TagTable.tagBr)
                        node.type = Node.StartTag;
                    else if (node.tag == TagTable.tagP)
                    {
                        /* coerce unmatched </p> to <br><br> */
                        if (!element.isDescendantOf(TagTable.tagP))
                        {
                            Node.coerceNode(lexer, node, TagTable.tagBr);
                            Node.trimSpaces(lexer, element);
                            Node.insertNodeAtEnd(element, node);
                            node = lexer.inferredTag("br");
                            continue;
                        }
                    }
                    else if ((node.tag.model & Dict.CM_INLINE) != 0
                                && node.tag != TagTable.tagA
                                        && !((node.tag.model & Dict.CM_OBJECT) != 0)
                                        && (element.tag.model & Dict.CM_INLINE) != 0)
                    {
                        /* allow any inline end tag to end current element */
                        lexer.popInline( element);

                        if (element.tag != TagTable.tagA)
                        {
                            if (node.tag == TagTable.tagA && node.tag != element.tag)
                            {
                               Report.warning(lexer, element, node, Report.MISSING_ENDTAG_BEFORE);
                               lexer.ungetToken();
                            }
                            else
                            {
                                Report.warning(lexer, element, node, Report.NON_MATCHING_ENDTAG);
                            }

                            if (!((mode & Lexer.Preformatted) != 0))
                                Node.trimSpaces(lexer, element);
                            Node.trimEmptyElement(lexer, element);
                            return;
                        }

                        /* if parent is <a> then discard unexpected inline end tag */
                        Report.warning(lexer, element, node, Report.DISCARDING_UNEXPECTED);
                        continue;
                    }  /* special case </tr> etc. for stuff moved in front of table */
                    else if (lexer.exiled
                                && node.tag.model != 0
                                && (node.tag.model & Dict.CM_TABLE) != 0)
                    {
                        lexer.ungetToken();
                        Node.trimSpaces(lexer, element);
                        Node.trimEmptyElement(lexer, element);
                        return;
                    }
                }

                /* allow any header tag to end current header */
                if ((node.tag.model & Dict.CM_HEADING) != 0 && (element.tag.model & Dict.CM_HEADING) != 0)
                {
                    if (node.tag == element.tag)
                    {
                        Report.warning(lexer, element, node, Report.NON_MATCHING_ENDTAG);
                    }
                    else
                    {
                        Report.warning(lexer, element, node, Report.MISSING_ENDTAG_BEFORE);
                        lexer.ungetToken();
                    }
                    if (!((mode & Lexer.Preformatted) != 0))
                        Node.trimSpaces(lexer, element);
                    Node.trimEmptyElement(lexer, element);
                    return;
                }

                /*
                   an <A> tag to ends any open <A> element
                   but <A href=...> is mapped to </A><A href=...>
                */
                if (node.tag == TagTable.tagA && !node.implicit && lexer.isPushed(node))
                {
                 /* coerce <a> to </a> unless it has some attributes */
                    if (node.attributes == null)
                    {
                        node.type = Node.EndTag;
                        Report.warning(lexer, element, node, Report.COERCE_TO_ENDTAG);
                        lexer.popInline( node);
                        lexer.ungetToken();
                        continue;

⌨️ 快捷键说明

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