NIHVIVO-564 Fixes for hash dump

This commit is contained in:
rjy7 2010-09-09 16:18:13 +00:00
parent 3269252aaa
commit ca6d805771
2 changed files with 8 additions and 6 deletions

View file

@ -47,7 +47,7 @@ public class DumpDirective extends BaseTemplateDirectiveModel {
String var = ((SimpleScalar)o).getAsString(); String var = ((SimpleScalar)o).getAsString();
DumpHelper helper = new DumpHelper(env); DumpHelper helper = new DumpHelper(env);
Map<String, Object> map = helper.getVariableDumpData(var); Map<String, Object> map = new HashMap<String, Object>();
map.put("var", helper.getVariableDump(var)); map.put("var", helper.getVariableDump(var));
TemplateHashModel dataModel = env.getDataModel(); TemplateHashModel dataModel = env.getDataModel();

View file

@ -51,11 +51,8 @@ public class DumpHelper {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("var", varName); map.put("var", varName);
if (tm != null) { if (tm != null) {
// Just use toString() method for now. Handles nested collections. Could make more sophisticated later.
String type = null; String type = null;
String value = tm.toString();
Object unwrappedModel = null; Object unwrappedModel = null;
try { try {
@ -63,7 +60,12 @@ public class DumpHelper {
} catch (TemplateModelException e) { } catch (TemplateModelException e) {
log.error("Cannot unwrap template model " + varName + "."); log.error("Cannot unwrap template model " + varName + ".");
} }
// Just use toString() method for now. Handles nested collections. Could make more sophisticated later.
// tm.toString() gives wrong results in the case of, e.g., a boolean value in a hash. tm.toString() may
// return a TemplateBooleanModel object, while unwrappedModel.toString() returns "true" or "false."
String value = unwrappedModel.toString(); // tm.toString();
// This case must precede the TemplateScalarModel case, because // This case must precede the TemplateScalarModel case, because
// tm is an instance of StringModel and thus a TemplateScalarModel. // tm is an instance of StringModel and thus a TemplateScalarModel.
if (unwrappedModel instanceof BaseTemplateModel) { if (unwrappedModel instanceof BaseTemplateModel) {