use of net.sourceforge.processdash.data.ListData in project processdash by dtuma.
the class RollupDatasetSelectElem method getFragment.
protected String getFragment(DataRepository data, String rollupID) {
// check in the cache to see if there is a cached value for
// this ID. if so, return it.
String cachedResult = CACHE.get(rollupID);
if (cachedResult != null)
return cachedResult;
// lookup the data element [/ROLLUP_ID/Rollup Instance
// List]. If it is missing or if it contains less than two
// items, return an empty fragment (and save the empty
// fragment to the cache).
String instanceListName = rollupInstanceList(rollupID);
ListData instanceList = getList(data, instanceListName);
if (instanceList == null || instanceList.size() < 2)
return CACHE.put(rollupID, "");
// Construct an HTML fragment
String prompt = resources.format("Rollup_Select_Prompt_FMT", rollupID);
StringBuffer result = new StringBuffer();
result.append("<tr><td>").append(HTMLUtils.escapeEntities(prompt)).append(" </td>\n <td colspan=10><select name='[").append(rollupPrefix(rollupID)).append("]s'>");
for (int i = 0; i < instanceList.size(); i++) {
String opt = HTMLUtils.escapeEntities((String) instanceList.get(i));
result.append("\n<option value=\"").append(opt).append("\">").append(opt);
}
result.append("\n</select></td></tr>\n");
return CACHE.put(rollupID, result.toString());
}
use of net.sourceforge.processdash.data.ListData in project processdash by dtuma.
the class PDashDataImpl method getList.
public List<String> getList(String dataName) {
SimpleData sd = getSimpleValue(dataName);
ListData ld = ListData.asListData(sd);
if (ld == null)
return null;
List result = new ArrayList(ld.asList());
for (int i = result.size(); i-- > 0; ) {
Object item = result.get(i);
if (item instanceof SimpleData)
result.set(i, convert((SimpleData) item));
}
return result;
}
use of net.sourceforge.processdash.data.ListData in project processdash by dtuma.
the class ResultSet method get.
/** Perform a query and return a result set. */
public static ResultSet get(DataRepository data, String forParam, String[] conditions, String orderBy, String[] dataNames, String basePrefix) {
// get the list of prefixes
ListData prefixList = getFilteredList(data, forParam, conditions, orderBy, basePrefix);
// Create a result set to return
ResultSet result = new ResultSet(prefixList.size(), dataNames.length);
// write the column headers into the result set.
result.setColName(0, null);
for (int i = 0; i < dataNames.length; i++) result.setColName(i + 1, dataNames[i]);
// get the data and fill the result set.
String prefix, dataName;
if (basePrefix == null)
basePrefix = "";
int baseLen = basePrefix.length();
// remove / as well
if (baseLen > 0)
baseLen++;
for (int p = 0; p < prefixList.size(); p++) {
// get the next prefix
Object pfx = prefixList.get(p);
if (pfx instanceof String)
prefix = (String) pfx;
else if (pfx instanceof SimpleData)
prefix = ((SimpleData) pfx).format();
else
continue;
// write the row headers into the result set.
if (prefix.length() > baseLen && prefix.startsWith(basePrefix))
result.setRowName(p + 1, prefix.substring(baseLen));
else {
result.setRowName(p + 1, prefix);
if (!prefix.startsWith("/"))
prefix = DataRepository.createDataName(basePrefix, prefix);
}
// look up the data for this row.
for (int d = 0; d < dataNames.length; d++) if (dataNames[d].startsWith("\"")) {
try {
result.setData(p + 1, d + 1, new StringData(dataNames[d]));
} catch (MalformedValueException mve) {
}
} else if (dataNames[d].indexOf('[') != -1) {
try {
result.setData(p + 1, d + 1, data.evaluate(dataNames[d], prefix));
} catch (Exception e) {
}
} else {
dataName = DataRepository.createDataName(prefix, dataNames[d]);
result.setData(p + 1, d + 1, data.getSimpleValue(dataName));
}
}
return result;
}
use of net.sourceforge.processdash.data.ListData in project processdash by dtuma.
the class ResultSet method getResultSetFromRepository.
private static ResultSet getResultSetFromRepository(DataRepository data, String prefix, String useParam) {
String dataName = DataRepository.createDataName(prefix, useParam);
ListData l = ListData.asListData(data.getSimpleValue(dataName));
if (l != null && l.size() == 1)
return (ResultSet) l.get(0);
else
return null;
}
use of net.sourceforge.processdash.data.ListData in project processdash by dtuma.
the class ResultSet method getFilteredList.
private static ListData getFilteredList(DataRepository data, String forParam, String[] conditions, String orderBy, String basePrefix) {
ListData result;
// return a list containing only one element - the base prefix.
if (forParam == null || forParam.length() == 0 || forParam.equals(".")) {
result = new ListData();
result.add(basePrefix);
// if the for parameter specifies a data list rather than
// a tag name, or if the base prefix is empty, return all the
// items in the list in question.
} else if (basePrefix == null || basePrefix.length() == 0 || !forParamIsTagName(forParam)) {
result = getList(data, forParam, conditions, orderBy, basePrefix);
// otherwise, get the appropriate prefix list, and create
// a filtered copy containing only those prefixes that
// start with the base prefix.
} else {
ListData fullPrefixList = getList(data, forParam, conditions, orderBy, basePrefix);
result = new ListData();
String item;
for (int i = 0; i < fullPrefixList.size(); i++) {
item = (String) fullPrefixList.get(i);
if (item.equals(basePrefix) || item.startsWith(basePrefix + "/"))
result.add(item);
}
}
return result;
}
Aggregations