use of net.sourceforge.processdash.data.StringData in project processdash by dtuma.
the class DataRepository method dumpRepository.
/** Print textual information about the data elements in the repostory.
*
* @param out a stream to write the information to
* @param filt a collection of prefixes that should be exported
* @param style the style of information to print, should be one of
* DUMP_STYLE_TEXT, DUMP_STYLE_DATA, or DUMP_STYLE_CALC.
*/
public void dumpRepository(PrintWriter out, Collection filt, int style) {
gc(null);
Iterator k = getKeys(filt, null);
// print out all element values.
while (k.hasNext()) {
String name = (String) k.next();
if (Filter.matchesFilter(filt, name)) {
try {
DataElement de = getOrCreateDefaultDataElement(name);
if (de == null || de.datafile == null)
continue;
SaveableData sd;
if (style == DUMP_STYLE_CALC)
sd = de.getValue();
else
sd = de.getSimpleValue();
if (sd == null)
continue;
String value = null;
if (style != DUMP_STYLE_TEXT) {
value = sd.saveString();
} else if (sd instanceof DateData) {
value = ((DateData) sd).formatDate();
} else if (sd instanceof StringData) {
value = StringData.escapeString(((StringData) sd).getString());
} else
value = sd.toString();
if (style == DUMP_STYLE_TEXT) {
if (name.indexOf(',') != -1)
name = EscapeString.escape(name, '\\', ",", "c");
out.println(name + "," + value);
} else {
out.println(name.substring(1) + "==" + value);
}
} catch (Exception e) {
// System.err.println("Data error:"+e.toString()+"
// for:"+name);
}
}
Thread.yield();
}
}
use of net.sourceforge.processdash.data.StringData in project processdash by dtuma.
the class HTMLPreprocessor method getList.
/** Lookup the named list and return it.
*
* if the name is enclosed in braces [] it refers to a data
* element - otherwise it refers to a cgi environment variable or
* a query/post parameter.
*
* If no list is found by that name, will return an empty list.
*/
private ListData getList(String listName) {
if (listName.startsWith("[")) {
// listName names a data element
listName = trimDelim(listName);
SimpleData d = getSimpleValue(listName);
if (d instanceof ListData)
return (ListData) d;
if (d instanceof StringData)
return ((StringData) d).asList();
if (d instanceof SimpleData) {
ListData result = new ListData();
result.add(d.format());
}
return EMPTY_LIST;
} else {
// listName names an environment variable or parameter
ListData result = new ListData();
// try for an environment variable first.
Object envVal = env.get(listName);
if (envVal instanceof String) {
result.add((String) envVal);
return result;
}
// look for a parameter value.
Object allParam = params.get(listName + "_ALL");
if (allParam instanceof String[]) {
String[] param = (String[]) allParam;
for (int i = 0; i < param.length; i++) result.add(param[i]);
} else {
Object p = params.get(listName);
if (p == null)
p = getResource(listName);
if (p instanceof String) {
String paramVal = (String) p;
if (paramVal.startsWith("LIST="))
return new ListData(paramVal.substring(5));
else
result.add(paramVal);
}
}
return result;
}
}
use of net.sourceforge.processdash.data.StringData in project processdash by dtuma.
the class TaskScheduleChartSettings method getSettingsForTaskList.
/**
* Find a list of chart setting objects that apply to a particular task list.
*
* @param taskListID the ID of the task list.
* @param data the data repository
* @return a list of
*/
public static Map<String, TaskScheduleChartSettings> getSettingsForTaskList(String taskListID, DataRepository data) {
Map<String, TaskScheduleChartSettings> globalSettings = new HashMap();
Map<String, TaskScheduleChartSettings> taskListSettings = new HashMap();
String taskListPrefix = getTaskListPrefix(taskListID);
Iterator i = data.getKeys(SETTINGS_PREFIX, DataNameFilter.EXPLICIT_ONLY);
while (i.hasNext()) {
String dataName = (String) i.next();
Map dest;
if (dataName.startsWith(GLOBAL_SETTINGS_PREFIX))
dest = globalSettings;
else if (dataName.startsWith(taskListPrefix))
dest = taskListSettings;
else
continue;
SimpleData sd = data.getSimpleValue(dataName);
if (!(sd instanceof StringData))
continue;
try {
StringData str = (StringData) sd;
TaskScheduleChartSettings s = new TaskScheduleChartSettings(dataName, str.format());
dest.put(s.getSettingsIdentifier(), s);
} catch (Exception e) {
TaskScheduleChart.logger.warning("Could not load chart settings for " + dataName);
}
}
Map result = globalSettings;
result.putAll(taskListSettings);
return result;
}
use of net.sourceforge.processdash.data.StringData in project processdash by dtuma.
the class ResultSet method get.
/** Perform a query and return a result set, using the old-style
mechanism. */
public static ResultSet get(DataRepository data, String[] conditions, String orderBy, String[] dataNames, String basePrefix, Comparator nodeComparator) {
// Construct a regular expression for searching the repository.
StringBuffer re = new StringBuffer("~(.*/)?");
if (conditions != null)
for (int c = 0; c < conditions.length; c++) re.append("{").append(conditions[c]).append("}");
if (orderBy == null)
orderBy = dataNames[0];
re.append(orderBy);
// Find data elements that match the regular expression.
if (basePrefix == null)
basePrefix = "";
SortedList list = SortedList.getInstance(data, re.toString(), basePrefix, FAKE_DATA_NAME, nodeComparator);
String[] prefixes = list.getNames();
// Create a result set to return
ResultSet result = new ResultSet(prefixes.length, 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;
int baseLen = basePrefix.length(), tailLen = orderBy.length() + 1;
// remove / as well
if (baseLen > 0)
baseLen++;
String[] fixedUpNames = new String[dataNames.length];
for (int i = dataNames.length; i > 0; ) if (dataNames[--i].charAt(0) == '!')
fixedUpNames[i] = fixupName(dataNames[i]);
SaveableData value;
for (int p = 0; p < prefixes.length; p++) {
// get the next prefix
prefix = prefixes[p];
// remove the name of the orderBy data element, & the preceeding /
prefix = prefix.substring(0, prefix.length() - tailLen);
if (baseLen > prefix.length())
result.setRowName(p + 1, "");
else
result.setRowName(p + 1, prefix.substring(baseLen));
// look up the data for this row.
for (int d = 0; d < dataNames.length; d++) if (dataNames[d].startsWith("![(")) {
dataName = DataRepository.anonymousPrefix + "/" + prefix + "/" + fixedUpNames[d];
value = data.getSimpleValue(dataName);
if (value == null)
try {
value = ValueFactory.create(dataName, dataNames[d], data, prefix);
data.putValue(dataName, value);
} catch (MalformedValueException mve) {
}
result.setData(p + 1, d + 1, value == null ? null : value.getSimpleValue());
} else if (dataNames[d].startsWith("\"")) {
try {
result.setData(p + 1, d + 1, new StringData(dataNames[d]));
} catch (MalformedValueException mve) {
result.setData(p + 1, d + 1, null);
}
} else {
dataName = DataRepository.createDataName(prefix, dataNames[d]);
result.setData(p + 1, d + 1, data.getSimpleValue(dataName));
}
}
return result;
}
use of net.sourceforge.processdash.data.StringData in project processdash by dtuma.
the class Genericsizeunits method call.
/** Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*/
public Object call(List arguments, ExpressionContext context) {
String variable = asStringVal(getArg(arguments, 0));
if (variable == null)
return null;
String defaultValue = asStringVal(getArg(arguments, 1));
StringData result = null;
String units = asString(context.get(variable));
if (StringUtils.hasValue(units) && !units.equals(defaultValue)) {
int semicolonPos = units.lastIndexOf(';');
if (semicolonPos != -1)
units = units.substring(semicolonPos + 1);
if (units.length() > 0)
result = StringData.create(units);
}
return new DescribedValue(result, context.resolveName(variable));
}
Aggregations