1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | package Torello.BuildJAR.S03_JDU; import Torello.BuildJAR.Build; import static Torello.Java.C.*; import Torello.HTML.HTMLNode; import Torello.HTML.TagNode; import Torello.HTML.TagNodeIndex; import Torello.HTML.SubSection; import Torello.HTML.HTMLPage; import Torello.HTML.DotPair; import Torello.HTML.TC; import Torello.HTML.SD; import Torello.HTML.Util; import Torello.HTML.Replacement; import Torello.HTML.NodeSearch.InnerTagFind; import Torello.HTML.NodeSearch.TagNodePeek; import Torello.HTML.NodeSearch.InnerTagFindInclusive; import Torello.HTML.NodeSearch.TagNodePeekInclusive; import Torello.HTML.NodeSearch.TextComparitor; import Torello.Java.FileRW; import java.util.Vector; import java.io.IOException; // This class updates the file "javadoc/Toello/Java/Function/package-summary.html" // // This is one of the classes that is invoked by the "ExtraTasks" Visitor-Handler of the // Upgrader // // The input page is a Java Doc Generated Web-Page. It is the Package-Summary File for // the Package Torello.Java.Function. There is an HTML <TABLE> in that file, and we need // to convert the <TABLE CLASS=typeSummary> into a table that has three columns of data, // not just two. This allows us to align the "Output:" label on that page. // // If this were not done, the "Output:" label would be horribly skewed all across the page. class FunctionPackageSummary { private static final Vector<HTMLNode> nodesToInsert = HTMLPage.getPageTokens ("</DIV>\n</TD>\n\t<TD CLASS='TJFCOL3 colLast'><DIV CLASS=block>\n", false); private static final String FS = java.io.File.separator; static void run(Appendable a) throws IOException { String fileName = Build.LOCAL_JAVADOC_DIR + "Torello" + FS + "Java" + FS + "Function" + FS + "package-summary.html"; String s = BGREEN + "\nTorello.BuildJAR.S03_JDU.FunctionPackageSummary.run(...)\n" + RESET + "Loading File: " + BYELLOW + fileName + RESET + '\n'; System.out.print(s); a.append(s); Vector<HTMLNode> page = null; try { page = HTMLPage.getPageTokens(FileRW.loadFileToString(fileName), false); } catch (Exception e) { e.printStackTrace(); System.out.println("READ FAILED Sorry Atari"); System.exit(0); } // This just gets the HTML <TABLE CLASS=typeSummary> location DotPair table = InnerTagFindInclusive.first (page, "table", "class", TextComparitor.C, "typeSummary"); // This is a list of HTML Table Rows ('<TR> ... </TR>') as instances of 'SubSection' Vector<SubSection> rows = TagNodePeekInclusive.all(page, table.start, table.end, "tr"); // Iterate the rows, without using the HNLI Iterator's. This will be worlds more // efficient since nodes are being inserted and removed from the page. for (SubSection row : rows) { // Retrieve the second column of each row. If there is no second column, then // null will be retrieved TagNodeIndex col2 = TagNodePeek.nth(row.html, 2, TC.OpeningTags, "td", "th"); // Some rows already have COLSPAN=2, we must set those rows to COLSPAN=3 // Those rows only have ONE <TH> or <TD> element if (col2 == null) { TagNodeIndex col1 = TagNodePeek.first(row.html, TC.OpeningTags, "td", "th"); row.html.setElementAt(col1.n.setAV("COLSPAN", "3", null), col1.index); } else { // The rows that have the HTML Tag <SPAN CLASS=TJF> are the ones that need // a third column. int spanPos = InnerTagFind.nth (row.html, 2, col2.index, -1, "class", TextComparitor.C, "TJF"); // Both cases of the if-branch need to change this <TD> TagNode TD = (TagNode) row.html.elementAt(col2.index); // For Rows that have two-columns, but aren't one of the "Function Pointer" rows, // we just need to make the 2nd column have a "COLSPAN=2" attribute if (spanPos == -1) row.html.setElementAt(TD.setAV("COLSPAN", "2", null), col2.index); else // This row **WAS** a Function-Pointer explanation Row. { // Make Column #2 Smaller, using CSS. Append a CSS Class, then add this // Class to the JavaDoc.css file // THIS LINE IS JUST TO MAKE THE ROWS LOOK NICER (otherwise the "output" blue // bubble is shoved all the way to the left.) row.html.setElementAt(TD.appendCSSClass("TJFCOL2", SD.SingleQuotes), col2.index); // INSERT THE PRE-INSTANTIATED NODES TO CREATE COLUMN #3. row.html.addAll(spanPos, nodesToInsert); } } } // Update the page with the new TABLE ROWS. page = Replacement.run(page, rows, false).a; s = "Writing File: " + BYELLOW + fileName + RESET + '\n'; System.out.print(s); a.append(s); // Write this file to disk. try { FileRW.writeFile(Util.pageToString(page), fileName); } catch (Exception e) { e.printStackTrace(); System.out.println("WRITE FAILED"); System.exit(0); } } } |