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

📄 mergedocs.java

📁 非常棒的java数据库
💻 JAVA
字号:
/*
 * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
 * (license2)
 * Initial Developer: H2 Group
 */
package org.h2.tools.doc;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

import org.h2.util.StringUtils;

/**
 * This application merges the html documentation to one file
 * (onePage.html), so that the PDF document can be created.
 */
public class MergeDocs {

    String baseDir = "docs/html";

    public static void main(String[] args) throws Exception {
        new MergeDocs().run(args);
    }

    private void run(String[] args) throws Exception {
        // the order of pages is important here
        String[] pages = { "quickstartText.html", "installation.html", "tutorial.html", "features.html",
                "performance.html", "advanced.html", "grammar.html", "functions.html", "datatypes.html", "build.html",
                "history.html", "faq.html", "license.html" };    
        StringBuffer buff = new StringBuffer();
        for (int i = 0; i < pages.length; i++) {
            String fileName = pages[i];
            String text = getContent(fileName);
            for (int j = 0; j < pages.length; j++) {
                text = StringUtils.replaceAll(text, pages[j] + "#", "#");
            }
            text = removeHeaderFooter(fileName, text);
            buff.append(text);
        }
        String finalText = buff.toString();
        File output = new File(baseDir, "onePage.html");
        PrintWriter writer = new PrintWriter(new FileWriter(output));
        writer.println("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" /><title>");
        writer.println("H2 Documentation");
        writer.println("</title><link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheetPdf.css\" /></head><body>");
        writer.println(finalText);
        writer.println("</body></html>");
        writer.close();
    }

    private String removeHeaderFooter(String fileName, String text) {
        // String start = "<body";
        // String end = "</body>";

        String start = "<div class=\"contentDiv\"";
        String end = "</div></td></tr></table><!-- analytics --></body></html>";

        int idx = text.indexOf(end);
        if (idx < 0) {
            throw new Error("Footer not found in file " + fileName);
        }
        text = text.substring(0, idx);
        idx = text.indexOf(start);
        idx = text.indexOf('>', idx);
        text = text.substring(idx + 1);
        return text;
    }

    String getContent(String fileName) throws Exception {
        File file = new File(baseDir, fileName);
        int length = (int) file.length();
        char[] data = new char[length];
        FileReader reader = new FileReader(file);
        int off = 0;
        while (length > 0) {
            int len = reader.read(data, off, length);
            off += len;
            length -= len;
        }
        reader.close();
        String s = new String(data);
        return s;
    }
}

⌨️ 快捷键说明

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