/*
* ClientHtmlHelper.java
*
* Created on June 25, 2007, 9:58 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package edu.ucsb.nceas.metacat.clientview;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
/**
*
* @author barteau
*/
public abstract class ClientHtmlHelper {
private static final String SELECT_TEMPLATE = "\n";
private static final String OPTION_TEMPLATE = "\n";
private static final String OPTGRP_TEMPLATE = "";
private static final String INPUT_TEMPLATE = "\n";
/**
* JSP API: A static helper method which takes a map (key, value pairs) and returns
* an XHTML SELECT String.
* @param map The map contianing the key, value pairs to convert into an HTML SELECT
* statement.
* @param name The name to assign the HTML SELECT, which will become the parameter name.
* @param style Any HTML styling text.
* @param size HTML field width.
* @return String, XHTML for a SELECT statement.
*/
public static String mapToHtmlSelect(Map map, String name, String style, int size) {
String result = "", item, key, optGrp, tmp;
Iterator iterIt;
Object obj;
Vector vector;
Iterator completeIterIt;
iterIt = map.keySet().iterator();
while(iterIt.hasNext()) {
key = (String) iterIt.next();
obj = map.get(key);
if (obj instanceof String) {
item = (String) obj;
tmp = OPTION_TEMPLATE.replaceFirst("%1s", key);
item = tmp.replaceFirst("%2s", item);
result += item;
} else if (obj instanceof Vector) {
vector = (Vector) obj;
optGrp = "";
completeIterIt = vector.iterator();
while (completeIterIt.hasNext()) {
item = (String) completeIterIt.next();
tmp = OPTION_TEMPLATE.replaceFirst("%1s", item);
item = tmp.replaceFirst("%2s", item);
optGrp += item;
}
tmp = OPTGRP_TEMPLATE.replaceFirst("%1s", key);
item = tmp.replaceFirst("%2s", optGrp);
result += item;
}
}
tmp = SELECT_TEMPLATE.replaceFirst("%1s", name);
tmp = tmp.replaceFirst("%2s", style);
tmp = tmp.replaceFirst("%3s", String.valueOf(size));
result = tmp.replaceFirst("%4s", result);
return(result);
}
}