forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTML.java
More file actions
130 lines (125 loc) · 3.57 KB
/
Copy pathHTML.java
File metadata and controls
130 lines (125 loc) · 3.57 KB
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
package javaforce;
/** HTML.
*
* Helper functions for generating HTML.
*
* @author pquiring
*/
public class HTML {
/** Generate html.form.input
* @param name = element name (optional)
* @param id = element id (optional)
* @param value = default value (optional)
*/
public static String input_field(String name, String id, String value) {
StringBuilder sb = new StringBuilder();
sb.append("<input");
if (name != null) {
sb.append(" name='");
sb.append(name);
sb.append("'");
}
if (id != null) {
sb.append(" id='");
sb.append(id);
sb.append("'");
}
if (value != null) {
sb.append(" value='");
sb.append(value);
sb.append("'");
}
sb.append(">");
return sb.toString();
}
/** Generate html.form.input[type=checkbox]
* @param name = element name (optional)
* @param id = element id (optional)
* @param checked = checkbox is initial checked
*/
public static String input_checkbox(String name, String id, boolean checked) {
StringBuilder sb = new StringBuilder();
sb.append("<input type=checkbox");
if (name != null) {
sb.append(" name='");
sb.append(name);
sb.append("'");
}
if (id != null) {
sb.append(" id='");
sb.append(id);
sb.append("'");
}
if (checked) sb.append(" checked");
sb.append(">");
return sb.toString();
}
/** Generate html.form.select.
* @param name = element name (optional)
* @param id = element id (optional)
* @param options = array[value, text]
* @param selected_value = selected value (optional)
* @param selected_text = selected text (optional)
* @param show_default = include a null 'Select...' option
*/
public static String select(String name, String id, String[][] options, String selected_value, String selected_text, boolean show_default) {
StringBuilder sb = new StringBuilder();
sb.append("<select");
if (name != null) {
sb.append(" name='");
sb.append(name);
sb.append("'");
}
if (id != null) {
sb.append(" id='");
sb.append(id);
sb.append("'");
}
sb.append(">");
if (show_default) {
sb.append("<option value='null'>Select...</option>");
}
boolean found = false;
for(int a=0;a<options.length;a++) {
sb.append("<option value='");
sb.append(options[a][0]);
sb.append("'");
if (selected_value != null && selected_value.equals(options[a][0])) {
sb.append(" selected");
found = true;
}
sb.append(">");
sb.append(options[a][1]);
sb.append("</option>");
}
if (!found && selected_value != null && selected_text != null) {
sb.append("<option value='");
sb.append(selected_value);
sb.append("' selected>");
sb.append(selected_text);
sb.append("</option>");
}
sb.append("</select>");
return sb.toString();
}
/** Generate html.form.select.
* Invokes select() with show_default = true
*/
public static String select(String name, String id, String[][] options, String selected_value, String selected_text) {
return select(name, id, options, selected_value, selected_text, true);
}
/** Generate HTML stack trace of exception.
*/
public static String toString(Exception ex) {
StringBuilder sb = new StringBuilder();
sb.append("Exception:");
sb.append(ex.toString());
sb.append("<br>");
StackTraceElement[] stes = ex.getStackTrace();
for(StackTraceElement ste : stes) {
sb.append(ste.toString());
sb.append("<br>");
}
return sb.toString();
}
}