NIHVIVO-564 Dump directive displays a message rather than throwing an error if the variable is undefined in the data model.
This commit is contained in:
parent
fd53202f21
commit
3dbbf13cd7
5 changed files with 52 additions and 79 deletions
|
@ -48,50 +48,54 @@ public class DumpHelper {
|
|||
log.error("Error getting value of template model " + varName + " from data model.");
|
||||
}
|
||||
|
||||
// Just use toString() method for now. Handles nested collections. Could make more sophisticated later.
|
||||
String value = tm.toString();
|
||||
String type = null;
|
||||
Object unwrappedModel = null;
|
||||
try {
|
||||
unwrappedModel = DeepUnwrap.permissiveUnwrap(tm);
|
||||
} catch (TemplateModelException e) {
|
||||
log.error("Cannot unwrap template model " + varName + ".");
|
||||
}
|
||||
|
||||
// This case must precede the TemplateScalarModel case, because
|
||||
// tm is an instance of StringModel and thus a TemplateScalarModel.
|
||||
if (unwrappedModel instanceof BaseTemplateModel) {
|
||||
type = unwrappedModel.getClass().getName();
|
||||
value = ((BaseTemplateModel)unwrappedModel).dump();
|
||||
} else if (tm instanceof TemplateScalarModel) {
|
||||
type = "string";
|
||||
} else if (tm instanceof TemplateDateModel) {
|
||||
type = "date";
|
||||
} else if (tm instanceof TemplateNumberModel) {
|
||||
type = "number";
|
||||
} else if (tm instanceof TemplateBooleanModel) {
|
||||
type = "boolean";
|
||||
try {
|
||||
value = ((TemplateBooleanModel) tm).getAsBoolean() ? "true" : "false";
|
||||
} catch (TemplateModelException e) {
|
||||
log.error("Error getting boolean value for " + varName + ".");
|
||||
}
|
||||
} else if (tm instanceof TemplateSequenceModel){
|
||||
type = "sequence";
|
||||
} else if (tm instanceof TemplateHashModel) {
|
||||
type = "hash";
|
||||
// In recursive dump, we've gotten down to a raw string. Just output it.
|
||||
// } else if (val == null) {
|
||||
// out.write(var);
|
||||
// return;
|
||||
} else {
|
||||
type = "object";
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("var", varName);
|
||||
map.put("value", value);
|
||||
map.put("type", type);
|
||||
|
||||
if (tm != null) {
|
||||
|
||||
// Just use toString() method for now. Handles nested collections. Could make more sophisticated later.
|
||||
String type = null;
|
||||
String value = tm.toString();
|
||||
Object unwrappedModel = null;
|
||||
|
||||
try {
|
||||
unwrappedModel = DeepUnwrap.permissiveUnwrap(tm);
|
||||
} catch (TemplateModelException e) {
|
||||
log.error("Cannot unwrap template model " + varName + ".");
|
||||
}
|
||||
|
||||
// This case must precede the TemplateScalarModel case, because
|
||||
// tm is an instance of StringModel and thus a TemplateScalarModel.
|
||||
if (unwrappedModel instanceof BaseTemplateModel) {
|
||||
type = unwrappedModel.getClass().getName();
|
||||
value = ((BaseTemplateModel)unwrappedModel).dump();
|
||||
} else if (tm instanceof TemplateScalarModel) {
|
||||
type = "string";
|
||||
} else if (tm instanceof TemplateDateModel) {
|
||||
type = "date";
|
||||
} else if (tm instanceof TemplateNumberModel) {
|
||||
type = "number";
|
||||
} else if (tm instanceof TemplateBooleanModel) {
|
||||
type = "boolean";
|
||||
try {
|
||||
value = ((TemplateBooleanModel) tm).getAsBoolean() ? "true" : "false";
|
||||
} catch (TemplateModelException e) {
|
||||
log.error("Error getting boolean value for " + varName + ".");
|
||||
}
|
||||
} else if (tm instanceof TemplateSequenceModel){
|
||||
type = "sequence";
|
||||
} else if (tm instanceof TemplateHashModel) {
|
||||
type = "hash";
|
||||
// In recursive dump, we've gotten down to a raw string. Just output it.
|
||||
// } else if (val == null) {
|
||||
// out.write(var);
|
||||
// return;
|
||||
} else {
|
||||
type = "object";
|
||||
}
|
||||
map.put("value", value);
|
||||
map.put("type", type);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- Template for dumping hash values -->
|
||||
|
||||
<strong>Type:</strong> hash<br />
|
||||
<strong>Values:</strong><br />
|
||||
|
||||
<ul>
|
||||
<#list value?keys as key>
|
||||
<#-- Shallow (non-recursive) dump -->
|
||||
<li>${key} = ${value[key]}</li>
|
||||
<#-- Deep (recursive) dump
|
||||
<li>${key} = <@dump var="${value[key]}" /></li> -->
|
||||
</#list>
|
||||
</ul>
|
|
@ -1,14 +0,0 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- Template for dumping sequence (list and array) values -->
|
||||
|
||||
<strong>Type:</strong> sequence (array/list)<br />
|
||||
<strong>Values:</strong><br />
|
||||
<ul>
|
||||
<#list value as item>
|
||||
<#-- Shallow (non-recursive) dump -->
|
||||
<li>${item_index}: ${item}</li>
|
||||
<#-- Deep (recursive) dump
|
||||
<li>${item_index}: <@dump var="${item}" /></li> -->
|
||||
</#list>
|
||||
</ul>
|
|
@ -1,6 +0,0 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<#-- Template for dumping string values -->
|
||||
|
||||
<strong>Type:</strong> ${type}<br />
|
||||
<strong>Value:</strong> ${value}<br />
|
|
@ -5,8 +5,12 @@
|
|||
<div class="var">
|
||||
|
||||
<h6>Variable name: <em>${var}</em></h6>
|
||||
<strong>Type:</strong> ${type}<br />
|
||||
<strong>Value:</strong> ${value}<br />
|
||||
<#if value??>
|
||||
<strong>Type:</strong> ${type}<br />
|
||||
<strong>Value:</strong> ${value}<br />
|
||||
<#else>
|
||||
Variable is undefined in the data model
|
||||
</#if>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue