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

📄 pprint.java

📁 windows 代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                printTag(lexer, fout, mode, indent, node);

                /* indent content for SELECT, TEXTAREA, MAP, OBJECT and APPLET */

                if (shouldIndent(node))
                {
                    condFlushLine(fout, indent);
                    indent += this.configuration.spaces;

                    for (content = node.content;
                            content != null;
                            content = content.next)
                        printTree(fout, mode, indent, lexer, content);

                    condFlushLine(fout, indent);
                    indent -= this.configuration.spaces;
                    condFlushLine(fout, indent);
                }
                else
                {

                    for (content = node.content;
                            content != null;
                            content = content.next)
                        printTree(fout, mode, indent, lexer, content);
                }

                printEndTag(fout, mode, indent, node);
            }
            else /* other tags */
            {
                condFlushLine(fout, indent);

                if (this.configuration.SmartIndent && node.prev != null)
                    flushLine(fout, indent);

                if (this.configuration.HideEndTags == false ||
                    !(node.tag != null && ((node.tag.model & Dict.CM_OMITST) != 0)))
                {
                    printTag(lexer, fout, mode, indent, node);

                    if (shouldIndent(node))
                        condFlushLine(fout, indent);
                    else if ((node.tag.model & Dict.CM_HTML) != 0 ||
                             node.tag == TagTable.tagNoframes ||
                                ((node.tag.model & Dict.CM_HEAD) != 0 &&
                                !(node.tag == TagTable.tagTitle)))
                        flushLine(fout, indent);
                }

                if (node.tag == TagTable.tagBody && this.configuration.BurstSlides)
                    printSlide(fout, mode, (this.configuration.IndentContent ? indent+this.configuration.spaces : indent), lexer);
                else
                {
                    last = null;

                    for (content = node.content;
                            content != null; content = content.next)
                    {
                        /* kludge for naked text before block level tag */
                        if (last != null && !this.configuration.IndentContent && last.type == Node.TextNode &&
                            content.tag != null && (content.tag.model & Dict.CM_BLOCK) != 0)
                        {
                            flushLine(fout, indent);
                            flushLine(fout, indent);
                        }

                        printTree(fout, mode,
                            (shouldIndent(node) ? indent+this.configuration.spaces : indent), lexer, content);

                        last = content;
                    }
                }

                /* don't flush line for td and th */
                if (shouldIndent(node) ||
                    (((node.tag.model & Dict.CM_HTML) != 0 || node.tag == TagTable.tagNoframes ||
                        ((node.tag.model & Dict.CM_HEAD) != 0 && !(node.tag == TagTable.tagTitle)))
                        && this.configuration.HideEndTags == false))
                {
                    condFlushLine(fout, (this.configuration.IndentContent ? indent+this.configuration.spaces : indent));

                    if (this.configuration.HideEndTags == false || !((node.tag.model & Dict.CM_OPT) != 0))
                    {
                        printEndTag(fout, mode, indent, node);
                        flushLine(fout, indent);
                    }
                }
                else
                {
                    if (this.configuration.HideEndTags == false || !((node.tag.model & Dict.CM_OPT) != 0))
                        printEndTag(fout, mode, indent, node);

                    flushLine(fout, indent);
                }

                if (this.configuration.IndentContent == false &&
                    node.next != null &&
                    this.configuration.HideEndTags == false &&
                    (node.tag.model & (Dict.CM_BLOCK|Dict.CM_LIST|Dict.CM_DEFLIST|Dict.CM_TABLE)) != 0)
                {
                    flushLine(fout, indent);
                }
            }
        }
    }

    public void printXMLTree(Out fout, short mode, int indent,
                             Lexer lexer, Node node)
    {
        if (node == null)
            return;

        if (node.type == Node.TextNode)
        {
            printText(fout, mode, indent,
                        node.textarray, node.start, node.end);
        }
        else if (node.type == Node.CommentTag)
        {
            condFlushLine(fout, indent);
            printComment(fout, 0, node);
            condFlushLine(fout, 0);
        }
        else if (node.type == Node.RootNode)
        {
            Node content;

            for (content = node.content;
                    content != null;
                    content = content.next)
               printXMLTree(fout, mode, indent, lexer, content);
        }
        else if (node.type == Node.DocTypeTag)
            printDocType(fout, indent, node);
        else if (node.type == Node.ProcInsTag)
            printPI(fout, indent, node);
        else if (node.type == Node.SectionTag)
            printSection(fout, indent, node);
        else if (node.type == Node.AspTag)
            printAsp(fout, indent, node);
        else if (node.type == Node.JsteTag)
            printJste(fout, indent, node);
        else if (node.type == Node.PhpTag)
            printPhp(fout, indent, node);
        else if ((node.tag.model & Dict.CM_EMPTY) != 0 || node.type == Node.StartEndTag)
        {
            condFlushLine(fout, indent);
            printTag(lexer, fout, mode, indent, node);
            flushLine(fout, indent);

            if (node.next != null)
                flushLine(fout, indent);
        }
        else /* some kind of container element */
        {
            Node content;
            boolean mixed = false;
            int cindent;

            for (content = node.content; content != null; content = content.next)
            {
                if (content.type == Node.TextNode)
                {
                    mixed = true;
                    break;
                }
            }

            condFlushLine(fout, indent);

            if (ParserImpl.XMLPreserveWhiteSpace(node))
            {
                indent = 0;
                cindent = 0;
                mixed = false;
            }
            else if (mixed)
                cindent = indent;
            else
                cindent = indent + this.configuration.spaces;

            printTag(lexer, fout, mode, indent, node);

            if (!mixed)
                flushLine(fout, indent);
 
            for (content = node.content;
                    content != null;
                    content = content.next)
                printXMLTree(fout, mode, cindent, lexer, content);

            if (!mixed)
                condFlushLine(fout, cindent);
            printEndTag(fout, mode, indent, node);
            condFlushLine(fout, indent);

            if (node.next != null)
                flushLine(fout, indent);
        }
    }


    /* split parse tree by h2 elements and output to separate files */

    /* counts number of h2 children belonging to node */
    public static int countSlides(Node node)
    {
        int n = 1;

        for (node = node.content; node != null; node = node.next)
            if (node.tag == TagTable.tagH2)
                ++n;

        return n;
    }

    /*
       inserts a space gif called "dot.gif" to ensure
       that the  slide is at least n pixels high
     */
    private void printVertSpacer(Out fout, int indent)
    {
        condFlushLine(fout, indent);
        printString(fout, indent , 
        "<img width=\"0\" height=\"0\" hspace=\"1\" src=\"dot.gif\" vspace=\"%d\" align=\"left\">");
        condFlushLine(fout, indent);
    }

    private void printNavBar(Out fout, int indent)
    {
        String buf;

        condFlushLine(fout, indent);
        printString(fout, indent , "<center><small>");

        if (slide > 1)
        {
            buf = "<a href=\"slide" +
                  (new Integer(slide - 1)).toString() +
                  ".html\">previous</a> | ";
            printString(fout, indent , buf);
            condFlushLine(fout, indent);

            if (slide < count)
                printString(fout, indent , "<a href=\"slide1.html\">start</a> | ");
            else
                printString(fout, indent , "<a href=\"slide1.html\">start</a>");

            condFlushLine(fout, indent);
        }

        if (slide < count)
        {
            buf = "<a href=\"slide" +
                  (new Integer(slide + 1)).toString() +
                  ".html\">next</a>";
            printString(fout, indent , buf);
        }

        printString(fout, indent , "</small></center>");
        condFlushLine(fout, indent);
    }

    /*
      Called from printTree to print the content of a slide from
      the node slidecontent. On return slidecontent points to the
      node starting the next slide or null. The variables slide
      and count are used to customise the navigation bar.
    */
    public void printSlide(Out fout, short mode, int indent, Lexer lexer)
    {
        Node content, last;

        /* insert div for onclick handler */
        String s;
        s = "<div onclick=\"document.location='slide" +
            (new Integer(slide < count ? slide + 1 : 1)).toString() +
            ".html'\">";
        printString(fout, indent, s);
        condFlushLine(fout, indent);

        /* first print the h2 element and navbar */
        if (slidecontent.tag == TagTable.tagH2)
        {
            printNavBar(fout, indent);

            /* now print an hr after h2 */

            addC('<', linelen++);


            addC((int)Lexer.foldCase('h',
                                     this.configuration.UpperCaseTags,
                                     this.configuration.XmlTags),
                 linelen++);
            addC((int)Lexer.foldCase('r',
                                     this.configuration.UpperCaseTags,
                                     this.configuration.XmlTags),
                 linelen++);

            if (this.configuration.XmlOut == true)
                printString(fout, indent , " />");
            else
                addC('>', linelen++);


            if (this.configuration.IndentContent == true)
                condFlushLine(fout, indent);

            /* PrintVertSpacer(fout, indent); */

            /*condFlushLine(fout, indent); */

            /* print the h2 element */
            printTree(fout, mode,
                (this.configuration.IndentContent ? indent+this.configuration.spaces : indent), lexer, slidecontent);

            slidecontent = slidecontent.next;
        }
    
        /* now continue until we reach the next h2 */

        last = null;
        content = slidecontent;

        for (; content != null; content = content.next)
        {
            if (content.tag == TagTable.tagH2)
                break;

            /* kludge for naked text before block level tag */
            if (last != null && !this.configuration.IndentContent && last.type == Node.TextNode &&
                content.tag != null && (content.tag.model & Dict.CM_BLOCK) != 0)
            {
                flushLine(fout, indent);
                flushLine(fout, indent);
            }

            printTree(fout, mode,
                (this.configuration.IndentContent ? indent+this.configuration.spaces : indent), lexer, content);

            last = content;
        }

        slidecontent = content;

        /* now print epilog */

        condFlushLine(fout, indent);

        printString(fout, indent , "<br clear=\"all\">");
        condFlushLine(fout, indent);

        addC('<', linelen++);


        addC((int)Lexer.foldCase('h',
                                 this.configuration.UpperCaseTags,
                                 this.configuration.XmlTags),
             linelen++);
        addC((int)Lexer.foldCase('r',
                                 this.configuration.UpperCaseTags,
                                 this.configuration.XmlTags),
             linelen++);

        if (this.configuration.XmlOut == true)
            printString(fout, indent , " />");
        else
            addC('>', linelen++);


        if (this.configuration.IndentContent == true)
            condFlushLine(fout, indent);

        printNavBar(fout, indent);

        /* end tag for div */
        printString(fout, indent, "</div>");
        condFlushLine(fout, indent);
    }


    /*
    Add meta element for page transition effect, this works on IE but not NS
    */

    public void addTransitionEffect(Lexer lexer, Node root, short effect, double duration)
    {
        Node head = Node.findHead(root);
        String transition;

        if (0 <= effect && effect <= 23)
            transition = "revealTrans(Duration=" +
                         (new Double(duration)).toString() +
                         ",Transition=" + effect + ")";
        else
            transition = "blendTrans(Duration=" +
                         (new Double(duration)).toString() + ")";

        if (head != null)
        {
            Node meta = lexer.inferredTag("meta");
            meta.addAttribute("http-equiv", "Page-Enter");
            meta.addAttribute("content", transition);
            Node.insertNodeAtStart(head, meta);
        }
    }

    public void createSlides(Lexer lexer, Node root)
    {
        Node body;
        String buf;
        Out out = new OutImpl();

        body = Node.findBody(root);
        count = countSlides(body);
        slidecontent = body.content;
        addTransitionEffect(lexer, root, EFFECT_BLEND, 3.0);

        for (slide = 1; slide <= count; ++slide)
        {
            buf = "slide" + slide + ".html";
            out.state = StreamIn.FSM_ASCII;
            out.encoding = this.configuration.CharEncoding;

            try
            {
                out.out = new FileOutputStream(buf);
                printTree(out, (short)0, 0, lexer, root);
                flushLine(out, 0);
                out.out.close();
            }
            catch (IOException e)
            {
                System.err.println(buf + e.toString() );
            }
        }

        /*
         delete superfluous slides by deleting slideN.html
         for N = count+1, count+2, etc. until no such file
         is found.     
        */

        for (;;)
        {
            buf = "slide" + slide + "html";

            if (!(new File(buf)).delete())
                break;

            ++slide;
        }
    }

}

⌨️ 快捷键说明

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