|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.tez.tools.javadoc.util; |
| 20 | + |
| 21 | +import java.io.File; |
| 22 | +import java.io.FileNotFoundException; |
| 23 | +import java.io.FileOutputStream; |
| 24 | +import java.io.IOException; |
| 25 | +import java.io.OutputStreamWriter; |
| 26 | +import java.io.PrintWriter; |
| 27 | + |
| 28 | +import org.apache.tez.dag.api.TezException; |
| 29 | +import org.apache.tez.tools.javadoc.model.Config; |
| 30 | +import org.apache.tez.tools.javadoc.model.ConfigProperty; |
| 31 | + |
| 32 | +public class HtmlWriter extends Writer { |
| 33 | + |
| 34 | + private static final String DEFAULT_STYLESHEET = "default-stylesheet.css"; |
| 35 | + |
| 36 | + public void write(Config config) throws IOException { |
| 37 | + PrintWriter out = null; |
| 38 | + |
| 39 | + if (config.configName == null || config.configName.isEmpty()) { |
| 40 | + throw new RuntimeException("Config Name is null or empty"); |
| 41 | + } |
| 42 | + |
| 43 | + try { |
| 44 | + File file = new File(config.configName + ".html"); |
| 45 | + out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); |
| 46 | + |
| 47 | + out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\" ?>"); |
| 48 | + out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""); |
| 49 | + out.println(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); |
| 50 | + |
| 51 | + out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); |
| 52 | + |
| 53 | + out.println("<head>"); |
| 54 | + out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />"); |
| 55 | + out.println("<title>" + config.configName + "</title>"); |
| 56 | +// out.println("<link rel='stylesheet' type='text/css' href=' " + config.getStyleSheet() + "'/>"); |
| 57 | + out.println("</head>"); |
| 58 | + |
| 59 | + out.println("<style>"); |
| 60 | + out.println("table"); |
| 61 | + out.println("{"); |
| 62 | + out.println(" background-color: #000;"); |
| 63 | + out.println(" border-spacing: 1px;"); |
| 64 | + out.println(" margin: 0 auto 0 auto;"); |
| 65 | + out.println("}"); |
| 66 | + out.println("th"); |
| 67 | + out.println("{"); |
| 68 | + out.println(" background-color: #fff;"); |
| 69 | + out.println(" padding: 5px;"); |
| 70 | + out.println(" margin: 1px;"); |
| 71 | + out.println("}"); |
| 72 | + out.println("td"); |
| 73 | + out.println("{"); |
| 74 | + out.println(" background-color: #fff;"); |
| 75 | + out.println(" padding: 2px;"); |
| 76 | + out.println("}"); |
| 77 | + out.println("table, th, td {"); |
| 78 | + out.println(" border: 1px solid black;"); |
| 79 | + out.println("}"); |
| 80 | + out.println("tr.tr_private td"); |
| 81 | + out.println("{"); |
| 82 | + out.println(" background-color: #FF4500;"); |
| 83 | + out.println(" padding: 2px;"); |
| 84 | + out.println("}"); |
| 85 | + out.println("tr.tr_evolve_unstable td"); |
| 86 | + out.println("{"); |
| 87 | + out.println(" background-color: #FFFFE0;"); |
| 88 | + out.println(" padding: 2px;"); |
| 89 | + out.println("}"); |
| 90 | + out.println("th.th_private"); |
| 91 | + out.println("{"); |
| 92 | + out.println(" background-color: #FF4500;"); |
| 93 | + out.println("}"); |
| 94 | + out.println("th.th_evolve_unstable"); |
| 95 | + out.println("{"); |
| 96 | + out.println(" background-color: #FFFFE0;"); |
| 97 | + out.println("}"); |
| 98 | + |
| 99 | + out.println("</style>"); |
| 100 | + |
| 101 | + out.println("<body>"); |
| 102 | + |
| 103 | + out.println("<div id=\"wrapper\">"); |
| 104 | + out.println("<div id=\"container\">"); |
| 105 | + |
| 106 | + out.println("<h1>" + config.configName + "</h1>"); |
| 107 | + out.println("<hr />"); |
| 108 | + |
| 109 | + out.println("<table>"); |
| 110 | + out.println("<tr>"); |
| 111 | + out.println("<th>" + "Property Name" + "</th>"); |
| 112 | + out.println("<th>" + "Default Value" + "</th>"); |
| 113 | + out.println("<th>" + "Description" + "</th>"); |
| 114 | + out.println("<th>" + "Type" + "</th>"); |
| 115 | + // out.println("<th>" + "Valid Values" + "</th>"); |
| 116 | + out.println("<th class=\"th_private\">" + "Is Private?" + "</th>"); |
| 117 | + out.println("<th class=\"th_evolve_unstable\">" + "Is Unstable?" + "</th>"); |
| 118 | + out.println("<th class=\"th_evolve_unstable\">" + "Is Evolving?" + "</th>"); |
| 119 | + out.println("</tr>"); |
| 120 | + |
| 121 | + for (ConfigProperty configProperty : config.configProperties.values()) { |
| 122 | + if (!isValidConfigProperty(configProperty)) { |
| 123 | + continue; |
| 124 | + } |
| 125 | + |
| 126 | + String altClass = ""; |
| 127 | + if (configProperty.isPrivate) { |
| 128 | + altClass = "class=\"tr_private\""; |
| 129 | + } else if (configProperty.isEvolving || configProperty.isUnstable) { |
| 130 | + altClass = "class=\"tr_evolve_unstable\""; |
| 131 | + } |
| 132 | + |
| 133 | + out.println("<tr " + altClass + ">"); |
| 134 | + out.println("<td>" + configProperty.propertyName + "</td>"); |
| 135 | + out.println("<td>" + configProperty.defaultValue + "</td>"); |
| 136 | + out.println("<td>" + configProperty.description + "</td>"); |
| 137 | + out.println("<td>" + configProperty.type + "</td>"); |
| 138 | + // Re-enable after adding values |
| 139 | + // out.println("<td>" + configProperty.validValues + "</td>"); |
| 140 | + |
| 141 | + out.println("<td class=\"" + (configProperty.isPrivate ? "td_private_true" : "td_private_false") + "\">" + configProperty.isPrivate + "</td>"); |
| 142 | + out.println("<td class=\"" + (configProperty.isEvolving ? "td_evolve_true" : "td_evolve_false") + "\">" + configProperty.isEvolving + "</td>"); |
| 143 | + out.println("<td class=\"" + (configProperty.isUnstable ? "td_unstable_true" : "td_unstable_false") + "\">" + configProperty.isUnstable + "</td>"); |
| 144 | + out.println("</tr>"); |
| 145 | + } |
| 146 | + |
| 147 | + out.println("</table>"); |
| 148 | + |
| 149 | + out.println("</div>"); |
| 150 | + out.println("</div>"); |
| 151 | + out.println("</body>"); |
| 152 | + out.println("</html>"); |
| 153 | + } finally { |
| 154 | + if (out != null) { |
| 155 | + out.close(); |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | +} |
0 commit comments