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,10 +48,16 @@ public class DumpHelper {
|
||||||
log.error("Error getting value of template model " + varName + " from data model.");
|
log.error("Error getting value of template model " + varName + " from data model.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
map.put("var", varName);
|
||||||
|
|
||||||
|
if (tm != null) {
|
||||||
|
|
||||||
// Just use toString() method for now. Handles nested collections. Could make more sophisticated later.
|
// Just use toString() method for now. Handles nested collections. Could make more sophisticated later.
|
||||||
String value = tm.toString();
|
|
||||||
String type = null;
|
String type = null;
|
||||||
|
String value = tm.toString();
|
||||||
Object unwrappedModel = null;
|
Object unwrappedModel = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
unwrappedModel = DeepUnwrap.permissiveUnwrap(tm);
|
unwrappedModel = DeepUnwrap.permissiveUnwrap(tm);
|
||||||
} catch (TemplateModelException e) {
|
} catch (TemplateModelException e) {
|
||||||
|
@ -81,17 +87,15 @@ public class DumpHelper {
|
||||||
} else if (tm instanceof TemplateHashModel) {
|
} else if (tm instanceof TemplateHashModel) {
|
||||||
type = "hash";
|
type = "hash";
|
||||||
// In recursive dump, we've gotten down to a raw string. Just output it.
|
// In recursive dump, we've gotten down to a raw string. Just output it.
|
||||||
// } else if (val == null) {
|
// } else if (val == null) {
|
||||||
// out.write(var);
|
// out.write(var);
|
||||||
// return;
|
// return;
|
||||||
} else {
|
} else {
|
||||||
type = "object";
|
type = "object";
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
|
||||||
map.put("var", varName);
|
|
||||||
map.put("value", value);
|
map.put("value", value);
|
||||||
map.put("type", type);
|
map.put("type", type);
|
||||||
|
}
|
||||||
|
|
||||||
return map;
|
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">
|
<div class="var">
|
||||||
|
|
||||||
<h6>Variable name: <em>${var}</em></h6>
|
<h6>Variable name: <em>${var}</em></h6>
|
||||||
|
<#if value??>
|
||||||
<strong>Type:</strong> ${type}<br />
|
<strong>Type:</strong> ${type}<br />
|
||||||
<strong>Value:</strong> ${value}<br />
|
<strong>Value:</strong> ${value}<br />
|
||||||
|
<#else>
|
||||||
|
Variable is undefined in the data model
|
||||||
|
</#if>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue