1 /*
2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * A helper that is used for creating HTML elements.
26  */
27 public class HtmlHelper {
28 
29     private static final String STYLE
30             = "style=\"font-family: Courier New; "
31             + "font-size: 12px; "
32             + "white-space: pre-wrap\"";
33 
htmlRow(String... values)34     public static String htmlRow(String... values) {
35         StringBuilder row = new StringBuilder();
36         row.append(startTr());
37         for (String value : values) {
38             row.append(startTd());
39             row.append(value);
40             row.append(endTd());
41         }
42         row.append(endTr());
43         return row.toString();
44     }
45 
startHtml()46     public static String startHtml() {
47         return startTag("html");
48     }
49 
endHtml()50     public static String endHtml() {
51         return endTag("html");
52     }
53 
startPre()54     public static String startPre() {
55         return startTag("pre " + STYLE);
56     }
57 
endPre()58     public static String endPre() {
59         return endTag("pre");
60     }
61 
startTable()62     public static String startTable() {
63         return startTag("table border=\"1\" padding=\"1\" cellspacing=\"0\" " + STYLE);
64     }
65 
endTable()66     public static String endTable() {
67         return endTag("table");
68     }
69 
startTr()70     public static String startTr() {
71         return "\t" + startTag("tr") + "\n";
72     }
73 
endTr()74     public static String endTr() {
75         return "\t" + endTag("tr") + "\n";
76     }
77 
startTd()78     public static String startTd() {
79         return "\t\t" + startTag("td");
80     }
81 
endTd()82     public static String endTd() {
83         return endTag("td") + "\n";
84     }
85 
startTag(String tag)86     public static String startTag(String tag) {
87         return "<" + tag + ">";
88     }
89 
endTag(String tag)90     public static String endTag(String tag) {
91         return "</" + tag + ">";
92     }
93 
anchorName(String name, String text)94     public static String anchorName(String name, String text) {
95         return "<a name=" + name + "><hr/>" + text + "</a>";
96     }
97 
anchorLink(String file, String anchorName, String text)98     public static String anchorLink(String file, String anchorName,
99             String text) {
100         return "<a href=" + file + "#" + anchorName + ">" + text + "</a>";
101     }
102 }
103