1 5 package org.h2.tools.doc; 6 7 import java.io.File ; 8 import java.io.FileReader ; 9 import java.io.FileWriter ; 10 import java.io.PrintWriter ; 11 12 import org.h2.util.StringUtils; 13 14 public class MergeDocs { 15 16 String baseDir = "docs/html"; 17 18 public static void main(String [] args) throws Exception { 19 new MergeDocs().run(args); 20 } 21 22 private void run(String [] args) throws Exception { 23 String [] pages = { 24 "quickstartText.html", 25 "installation.html", 26 "tutorial.html", 27 "features.html", 28 "performance.html", 29 "advanced.html", 30 "grammar.html", 31 "functions.html", 32 "datatypes.html", 33 "build.html", 34 "history.html", 35 "faq.html", 36 "license.html" 37 }; 38 StringBuffer buff = new StringBuffer (); 39 for(int i=0; i<pages.length; i++) { 40 String text = getContent(pages[i]); 41 for(int j=0; j<pages.length; j++) { 42 text = StringUtils.replaceAll(text, pages[j] + "#", "#"); 43 } 44 text = removeHeaderFooter(text); 45 buff.append(text); 46 } 47 String finalText= buff.toString(); 48 File output = new File (baseDir, "onePage.html"); 49 PrintWriter writer = new PrintWriter (new FileWriter (output)); 50 writer.println("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"><title>"); 51 writer.println("H2 Documentation"); 52 writer.println("</title><link rel=\"stylesheet\" type=\"text/css\" HREF=\"stylesheetPdf.css\"></head><body>"); 53 writer.println(finalText); 54 writer.println("</body></html>"); 55 writer.close(); 56 } 57 58 private String removeHeaderFooter(String text) { 59 62 String start = "<div class=\"contentDiv\""; 63 String end = "</div></td></tr></table></body></html>"; 64 65 int idx = text.indexOf(end); 66 text = text.substring(0, idx); 67 idx = text.indexOf(start); 68 idx = text.indexOf('>', idx); 69 text = text.substring(idx+1); 70 return text; 71 } 72 73 String getContent(String fileName) throws Exception { 74 File file = new File (baseDir, fileName); 75 int length = (int) file.length(); 76 char[] data = new char[length]; 77 FileReader reader = new FileReader (file); 78 int off = 0; 79 while(length > 0) { 80 int len = reader.read(data, off, length); 81 off += len; 82 length -= len; 83 } 84 reader.close(); 85 String s = new String (data); 86 return s; 87 } 88 } 89 | Popular Tags |