1 4 package org.oddjob.doclet; 5 6 import java.io.File ; 7 import java.io.FileOutputStream ; 8 import java.io.IOException ; 9 import java.io.PrintWriter ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 13 18 public class ManualWriter { 19 20 File directory = new File ("build/reference"); 21 22 27 public void writePage(PageData page) { 28 try { 29 File file = new File (directory, page.getFileName()); 30 file.getParentFile().mkdirs(); 31 PrintWriter out = new PrintWriter ( 32 new FileOutputStream (file)); 33 34 out.println("<html>"); 35 out.println(" <head>"); 36 out.println(" <title>" + page.getName() + "</title>"); 37 out.println(" </head>"); 38 out.println(" <body>"); 39 out.println(" <h2>" + page.getName() + "</h2>"); 40 if (page.getDescription() != null) { 41 out.println(" <h3>Description</h3>"); 42 out.println(page.getDescription()); 43 } 44 if (page.getAttributes().size() > 0) { 45 out.println(" <h3>Properties</h3>"); 46 out.println(" <table border='1' cellpadding='4' cellspacing='0' width='80%'>"); 47 out.println(" <tr><th>Name</th><th>Description</th><th>Required</th></tr>"); 48 for (Iterator it = page.getAttributes().iterator(); it.hasNext();) { 49 Property prop = (Property) it.next(); 50 out.println(" <tr>"); 51 out.println(" <td>" + prop.getName() + "</td>"); 52 out.println(" <td>" + prop.getDescription() + "</td>"); 53 out.println(" <td>" + prop.getRequired() + "</td>"); 54 out.println(" </tr>"); 55 } 56 out.println(" </table>"); 57 } 58 if (page.getElements().size() > 0) { 59 out.println(" <h3>Elements</h3>"); 60 for (Iterator it = page.getElements().iterator(); it.hasNext();) { 61 Property elem = (Property) it.next(); 62 out.println(" <h4>" + elem.getName() + "</h4>"); 63 if (elem.getRequired() != null) { 64 out.println(" <p>"); 65 out.println(" <i>Required</i>: " + elem.getRequired()); 66 out.println(" </p>"); 67 } 68 out.println(" <p>"); 69 out.println(elem.getDescription()); 70 out.println(" </p>"); 71 } 72 } 73 if (page.getExamples().size() > 0) { 74 out.println(" <h3>Example</h3>"); 75 for (Iterator it = page.getExamples().iterator(); it.hasNext();) { 76 String example = (String ) it.next(); 77 out.println(" <p>"); 78 out.println(example); 79 out.println(" </p>"); 80 } 81 } 82 out.println(" <hr/>"); 83 out.println(" <font size='-1' align='center'>(c) Rob Gordon 2005</font>"); 84 out.println(" </body>"); 85 out.println(" </html>"); 86 out.close(); 87 } 88 catch (IOException e) { 89 e.printStackTrace(); 90 } 91 } 92 93 99 public void writeIndex(PageData[] jobs, PageData[] types) { 100 try { 101 PrintWriter out = new PrintWriter ( 102 new FileOutputStream ( 103 new File (directory, "index.html"))); 104 105 out.println("<html>"); 106 out.println(" <head>"); 107 out.println(" <title>Oddjob Reference</title>"); 108 out.println(" </head>"); 109 out.println(" <body>"); 110 out.println(" <h2>Oddjob Reference</h2>"); 111 out.println(" <ul>"); 112 out.println(" <li>Jobs"); 113 out.println(" <ul>"); 114 for (int i = 0; i < jobs.length; ++i) { 115 PageData p = jobs[i]; 116 out.println(" <li>"); 117 out.println(" <a HREF='" + p.getFileName() 118 + "'>" + p.getName() + "</a> - " + p.getFirstSentence()); 119 out.println(" </li>"); 120 } 121 out.println(" </ul></li>"); 122 out.println(" <li>Types"); 123 out.println(" <ul>"); 124 for (int i = 0; i < types.length; ++i) { 125 PageData p = types[i]; 126 out.println(" <li>"); 127 out.println(" <a HREF='" + p.getFileName() 128 + "'>" + p.getName() + "</a> - " + p.getFirstSentence()); 129 out.println(" </li>"); 130 } 131 out.println(" </ul></li>"); 132 out.println(" </ul>"); 133 134 out.println(" <hr/>"); 135 out.println(" <font size='-1' align='center'>(c) Rob Gordon 2005</font>"); 136 out.println(" </body>"); 137 out.println(" </html>"); 138 out.close(); 139 } 140 catch (IOException e) { 141 e.printStackTrace(); 142 } 143 144 } 145 146 public void writeAll(List all) { 147 for (Iterator it = all.iterator(); it.hasNext(); ) { 148 writePage((PageData) it.next()); 149 } 150 } 151 152 public void createManual(Archiver archiver) { 153 writeIndex(archiver.getJobData(), archiver.getTypeData()); 154 writeAll(archiver.getAll()); 155 156 } 157 158 } 159 | Popular Tags |