1 |
3320
|
barteau
|
/*
|
2 |
|
|
* ClientHtmlHelper.java
|
3 |
|
|
*
|
4 |
|
|
* Created on June 25, 2007, 9:58 AM
|
5 |
|
|
*
|
6 |
|
|
* To change this template, choose Tools | Template Manager
|
7 |
|
|
* and open the template in the editor.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
package edu.ucsb.nceas.metacat.clientview;
|
11 |
|
|
|
12 |
|
|
import java.util.Iterator;
|
13 |
|
|
import java.util.Map;
|
14 |
|
|
import java.util.Vector;
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
|
|
*
|
18 |
|
|
* @author barteau
|
19 |
|
|
*/
|
20 |
|
|
public abstract class ClientHtmlHelper {
|
21 |
3367
|
barteau
|
private static final String SELECT_TEMPLATE = "<select name='%1s' style='%2s' size='%3s'>\n%4s</select>\n";
|
22 |
|
|
private static final String OPTION_TEMPLATE = "<option value='%1s'>%2s</option>\n";
|
23 |
|
|
private static final String OPTGRP_TEMPLATE = "<optgroup label='%1s'>%2s</optgroup>";
|
24 |
|
|
private static final String INPUT_TEMPLATE = "<input name='%1s' value='%2s' type='%4s' class='%3s' size='%5s'/>\n";
|
25 |
3320
|
barteau
|
|
26 |
|
|
/**
|
27 |
|
|
* JSP API: A static helper method which takes a map (key, value pairs) and returns
|
28 |
|
|
* an XHTML SELECT String.
|
29 |
|
|
* @param map The map contianing the key, value pairs to convert into an HTML SELECT
|
30 |
|
|
* statement.
|
31 |
|
|
* @param name The name to assign the HTML SELECT, which will become the parameter name.
|
32 |
|
|
* @param style Any HTML styling text.
|
33 |
|
|
* @param size HTML field width.
|
34 |
|
|
* @return String, XHTML for a SELECT statement.
|
35 |
|
|
*/
|
36 |
|
|
public static String mapToHtmlSelect(Map map, String name, String style, int size) {
|
37 |
3363
|
barteau
|
String result = "", item, key, optGrp, tmp;
|
38 |
3361
|
barteau
|
Iterator iterIt;
|
39 |
3320
|
barteau
|
Object obj;
|
40 |
|
|
Vector vector;
|
41 |
|
|
Iterator completeIterIt;
|
42 |
|
|
|
43 |
|
|
iterIt = map.keySet().iterator();
|
44 |
|
|
while(iterIt.hasNext()) {
|
45 |
3361
|
barteau
|
key = (String) iterIt.next();
|
46 |
3320
|
barteau
|
obj = map.get(key);
|
47 |
|
|
if (obj instanceof String) {
|
48 |
|
|
item = (String) obj;
|
49 |
3367
|
barteau
|
tmp = OPTION_TEMPLATE.replaceFirst("%1s", key);
|
50 |
|
|
item = tmp.replaceFirst("%2s", item);
|
51 |
3320
|
barteau
|
result += item;
|
52 |
|
|
} else if (obj instanceof Vector) {
|
53 |
|
|
vector = (Vector) obj;
|
54 |
|
|
optGrp = "";
|
55 |
|
|
completeIterIt = vector.iterator();
|
56 |
|
|
while (completeIterIt.hasNext()) {
|
57 |
|
|
item = (String) completeIterIt.next();
|
58 |
3367
|
barteau
|
tmp = OPTION_TEMPLATE.replaceFirst("%1s", item);
|
59 |
|
|
item = tmp.replaceFirst("%2s", item);
|
60 |
3320
|
barteau
|
optGrp += item;
|
61 |
|
|
}
|
62 |
3367
|
barteau
|
tmp = OPTGRP_TEMPLATE.replaceFirst("%1s", key);
|
63 |
|
|
item = tmp.replaceFirst("%2s", optGrp);
|
64 |
3320
|
barteau
|
result += item;
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
3367
|
barteau
|
tmp = SELECT_TEMPLATE.replaceFirst("%1s", name);
|
68 |
|
|
tmp = tmp.replaceFirst("%2s", style);
|
69 |
|
|
tmp = tmp.replaceFirst("%3s", String.valueOf(size));
|
70 |
|
|
result = tmp.replaceFirst("%4s", result);
|
71 |
3320
|
barteau
|
return(result);
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
}
|