|
| 1 | +package com.sumingk.core; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.io.FileNotFoundException; |
| 5 | +import java.io.FileOutputStream; |
| 6 | +import java.io.PrintStream; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +/** |
| 10 | + * create by sumingk 2018/11/20 |
| 11 | + * weixin_public_number : blockchain_do/刻意链习 |
| 12 | + * weibo: 刻意链习 |
| 13 | + */ |
| 14 | +public class ContractDoc { |
| 15 | + /** |
| 16 | + * 生成的方法签名文件 |
| 17 | + */ |
| 18 | + public static final String CONTRACT_FILENAME = "/contract_DOC.html"; |
| 19 | + |
| 20 | + public static void main(String[] args) { |
| 21 | + File file = new File(System.getProperty("user.dir") + MethodSign.OUTPUT_FILENAME); |
| 22 | + if (file.exists()) file.delete(); |
| 23 | + MethodSign.anlyContractABI(); |
| 24 | + |
| 25 | + if (!file.exists()) { |
| 26 | + System.err.println("File " + MethodSign.OUTPUT_FILENAME.substring(1) + " does not exist!"); |
| 27 | + return; |
| 28 | + } |
| 29 | + printDocHtml(file); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * 生成contract_doc.html 文档 |
| 34 | + * |
| 35 | + * @param file |
| 36 | + */ |
| 37 | + public static void printDocHtml(File file) { |
| 38 | + StringBuilder sb = new StringBuilder(); |
| 39 | + PrintStream printStream = null; |
| 40 | + |
| 41 | + File apiFile = new File(System.getProperty("user.dir") + CONTRACT_FILENAME); |
| 42 | + if (apiFile.exists()) apiFile.delete(); |
| 43 | + |
| 44 | + try { |
| 45 | + printStream = new PrintStream(new FileOutputStream(apiFile)); |
| 46 | + sb.append("<html>"); |
| 47 | + sb.append("<head>"); |
| 48 | + sb.append("<title>Contract Method API</title>"); |
| 49 | + sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"); |
| 50 | + sb.append("<style type=\"text/css\">"); |
| 51 | + sb.append("TABLE{border-collapse:collapse;border-left:solid 1 #000000; border-top:solid 1 #000000;padding:5px;}"); |
| 52 | + sb.append("TH{border-right:solid 1 #000000;border-bottom:solid 1 #000000;}"); |
| 53 | + sb.append("ol{list-style-type:none;counter-reset:sectioncounter;}"); |
| 54 | + sb.append("TD{font:normal;border-right:solid 1 #000000;border-bottom:solid 1 #000000;}"); |
| 55 | + sb.append("</style></head>"); |
| 56 | + sb.append("<body>"); |
| 57 | + sb.append("<div align=\"left\">"); |
| 58 | + sb.append("<ol>"); |
| 59 | + |
| 60 | + List<String> lists = FileOperate.readFileIntoStringArrList(file); |
| 61 | + if (lists.size() > 0) { |
| 62 | + for (int k = 0; k < lists.size(); k++) { |
| 63 | + String str = lists.get(k).replaceAll("\\s*", ""); |
| 64 | + //排除 空格 空行 |
| 65 | + if (str == null || "".equals(str)) continue; |
| 66 | + if (str.indexOf(".sol") > -1) { |
| 67 | + if (k < lists.size() - 1) { |
| 68 | + String nextStr = lists.get(k + 1); |
| 69 | + nextStr = nextStr.replaceAll("\\s*", ""); |
| 70 | + if (nextStr == null || "".equals(nextStr)) { |
| 71 | + continue; |
| 72 | + } |
| 73 | + sb.append("<li>" + str + "</li>").append("<br/>"); |
| 74 | + } |
| 75 | + } else { |
| 76 | + if (str.indexOf(":") > -1) { |
| 77 | + sb.append("<li>" + str.split(":")[1] + "</li>").append("<br/>"); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + sb.append("</ol>"); |
| 83 | + sb.append("</div></body></html>"); |
| 84 | + printStream.println(sb.toString()); |
| 85 | + } catch (FileNotFoundException e) { |
| 86 | + e.printStackTrace(); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments