NIHVIVO-2479 Continue work on dump templates for values of different types
This commit is contained in:
parent
930ee45f52
commit
530c7a70f8
7 changed files with 74 additions and 58 deletions
|
@ -57,6 +57,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
|
||||
enum Key {
|
||||
DATE_TYPE("dateType"),
|
||||
HELP("help"),
|
||||
METHODS("methods"),
|
||||
PROPERTIES("properties"),
|
||||
TYPE("type"),
|
||||
|
@ -416,36 +417,39 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
private Map<String, Object> getTemplateModelDump(TemplateMethodModel model, String varName) throws TemplateModelException {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(Key.TYPE.toString(), Type.METHOD);
|
||||
map.put("help", getHelp(model, varName));
|
||||
map.put(Key.HELP.toString(), getHelp(model, varName));
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, Object> getTemplateModelDump(TemplateDirectiveModel model, String varName) throws TemplateModelException {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
||||
map.put("help", getHelp(model, varName));
|
||||
map.put(Key.HELP.toString(), getHelp(model, varName));
|
||||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> getHelp(TemplateModel model, String varName) {
|
||||
Map<String, Object> map = null;
|
||||
if ( model instanceof TemplateMethodModel || model instanceof TemplateDirectiveModel ) {
|
||||
String modelClass = model instanceof TemplateMethodModel ? "TemplateMethodModel" : "TemplateDirectiveModel";
|
||||
Class<?> cls = model.getClass();
|
||||
Method[] methods = cls.getMethods();
|
||||
for (Method method : methods) {
|
||||
if ( method.getName().equals("help") ) {
|
||||
try {
|
||||
map = (Map<String, Object>) method.invoke(model, varName);
|
||||
} catch (Exception e) {
|
||||
String modelClass = model instanceof TemplateMethodModel ? "TemplateMethodModel" : "TemplateDirectiveModel";
|
||||
log.error("Error invoking method help() on " + modelClass + " of class " + cls.getName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Method help = cls.getMethod("help", String.class);
|
||||
try {
|
||||
return (Map<String, Object>) help.invoke(model, varName);
|
||||
} catch (Exception e) {
|
||||
log.error("Error invoking method help() on " + modelClass + " of class " + cls.getName());
|
||||
return null;
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
log.info("No help() method defined for " + modelClass + " of class " + cls.getName());
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
log.error("Error getting method help() for " + modelClass + " " + cls.getName());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return map;
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, Object> getTemplateModelDump(TemplateModel model) throws TemplateModelException {
|
||||
|
@ -483,7 +487,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
|
|||
out.write(sw.toString());
|
||||
}
|
||||
|
||||
protected Map<String, Object> help(String name) {
|
||||
public Map<String, Object> help(String name) {
|
||||
return new HashMap<String, Object>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,12 +68,10 @@ public class DumpAllDirective extends BaseDumpDirective {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> help(String name) {
|
||||
public Map<String, Object> help(String name) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
//map.put("name", name);
|
||||
|
||||
map.put("effect", "Dump the contents of the template data model.");
|
||||
|
||||
map.put("effect", "Dumps the contents of the template data model.");
|
||||
|
||||
//map.put("comments", "");
|
||||
|
||||
|
|
|
@ -56,18 +56,16 @@ public class DumpDirective extends BaseDumpDirective {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> help(String name) {
|
||||
public Map<String, Object> help(String name) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
//map.put("name", name);
|
||||
|
||||
map.put("effect", "Dump the contents of a template variable.");
|
||||
map.put("effect", "Dumps the contents of a template variable.");
|
||||
|
||||
//map.put("comments", "");
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("var", "name of variable to dump");
|
||||
map.put("params", params);
|
||||
map.put("parameters", params);
|
||||
|
||||
List<String> examples = new ArrayList<String>();
|
||||
examples.add("<@" + name + " var=\"urls\" />");
|
||||
|
|
|
@ -58,23 +58,21 @@ public class HelpDirective extends BaseDumpDirective {
|
|||
Map<String, Object> map = getTemplateVariableDump(varName, env);
|
||||
|
||||
String type = templateModel instanceof TemplateMethodModel ? "method" : "directive";
|
||||
String title = "Help for " + type;
|
||||
String title = "Template " + type + " help";
|
||||
dump(map, env, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> help(String name) {
|
||||
public Map<String, Object> help(String name) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
//map.put("name", name);
|
||||
|
||||
map.put("effect", "Output help for a directive or method.");
|
||||
map.put("effect", "Outputs help for a directive or method.");
|
||||
|
||||
//map.put("comments", "");
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("for", "name of directive or method");
|
||||
map.put("params", params);
|
||||
map.put("parameters", params);
|
||||
|
||||
List<String> examples = new ArrayList<String>();
|
||||
examples.add("<@" + name + " for=\"dump\" />");
|
||||
|
|
|
@ -255,7 +255,7 @@ public class DumpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
||||
expectedDumpValue.put("help", null);
|
||||
expectedDumpValue.put(Key.HELP.toString(), null);
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -274,7 +274,7 @@ public class DumpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
||||
expectedDumpValue.put("help", getMethodHelp(varName));
|
||||
expectedDumpValue.put(Key.HELP.toString(), getMethodHelp(varName));
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -293,7 +293,7 @@ public class DumpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
||||
expectedDumpValue.put("help", null);
|
||||
expectedDumpValue.put(Key.HELP.toString(), null);
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -312,7 +312,7 @@ public class DumpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
||||
expectedDumpValue.put("help", null);
|
||||
expectedDumpValue.put(Key.HELP.toString(), null);
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -331,7 +331,7 @@ public class DumpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
||||
expectedDumpValue.put("help", getDirectiveHelp(varName));
|
||||
expectedDumpValue.put(Key.HELP.toString(), getDirectiveHelp(varName));
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -350,7 +350,7 @@ public class DumpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
||||
expectedDumpValue.put("help", null);
|
||||
expectedDumpValue.put(Key.HELP.toString(), null);
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -862,7 +862,7 @@ public class DumpDirectiveTest {
|
|||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("var", "name of variable to dump");
|
||||
map.put("params", params);
|
||||
map.put("parameters", params);
|
||||
|
||||
List<String> examples = new ArrayList<String>();
|
||||
examples.add("<@" + name + " var=\"urls\" />");
|
||||
|
@ -878,7 +878,7 @@ public class DumpDirectiveTest {
|
|||
|
||||
List<String>params = new ArrayList<String>();
|
||||
params.add("Integer to square");
|
||||
map.put("params", params);
|
||||
map.put("parameters", params);
|
||||
|
||||
List<String> examples = new ArrayList<String>();
|
||||
examples.add(name + "(4)");
|
||||
|
|
|
@ -58,7 +58,7 @@ public class HelpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
||||
expectedDumpValue.put("help", null);
|
||||
expectedDumpValue.put(Key.HELP.toString(), null);
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -77,7 +77,7 @@ public class HelpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
||||
expectedDumpValue.put("help", getMethodHelp(varName));
|
||||
expectedDumpValue.put(Key.HELP.toString(), getMethodHelp(varName));
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -96,7 +96,7 @@ public class HelpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
||||
expectedDumpValue.put("help", null);
|
||||
expectedDumpValue.put(Key.HELP.toString(), null);
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -115,7 +115,7 @@ public class HelpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
||||
expectedDumpValue.put("help", null);
|
||||
expectedDumpValue.put(Key.HELP.toString(), null);
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -134,7 +134,7 @@ public class HelpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
||||
expectedDumpValue.put("help", getDirectiveHelp(varName));
|
||||
expectedDumpValue.put(Key.HELP.toString(), getDirectiveHelp(varName));
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -153,7 +153,7 @@ public class HelpDirectiveTest {
|
|||
|
||||
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
||||
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
||||
expectedDumpValue.put("help", null);
|
||||
expectedDumpValue.put(Key.HELP.toString(), null);
|
||||
|
||||
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
||||
expectedDump.put(varName, expectedDumpValue);
|
||||
|
@ -237,9 +237,9 @@ public class HelpDirectiveTest {
|
|||
|
||||
map.put("comments", "Sequences (lists and arrays) are enclosed in square brackets. Hashes are enclosed in curly braces.");
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("var", "name of variable to dump");
|
||||
map.put("params", params);
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
parameters.put("var", "name of variable to dump");
|
||||
map.put("parameters", parameters);
|
||||
|
||||
List<String> examples = new ArrayList<String>();
|
||||
examples.add("<@" + name + " var=\"urls\" />");
|
||||
|
@ -253,9 +253,9 @@ public class HelpDirectiveTest {
|
|||
|
||||
map.put("returns", "The square of the argument");
|
||||
|
||||
List<String>params = new ArrayList<String>();
|
||||
List<String> params = new ArrayList<String>();
|
||||
params.add("Integer to square");
|
||||
map.put("params", params);
|
||||
map.put("parameters", params);
|
||||
|
||||
List<String> examples = new ArrayList<String>();
|
||||
examples.add(name + "(4)");
|
||||
|
|
|
@ -88,7 +88,7 @@ div.dump {
|
|||
<li class="item">
|
||||
<#if type == "Sequence">
|
||||
Item ${item_index}:
|
||||
<@valueDiv item />
|
||||
<@valueDiv><@doMap item /></@valueDiv>
|
||||
<#else><@doMap item />
|
||||
</#if>
|
||||
|
||||
|
@ -105,7 +105,7 @@ div.dump {
|
|||
<ul class="map">
|
||||
<#list map?keys as key>
|
||||
<li class="item">
|
||||
${key} => <@valueDiv map[key] />
|
||||
${key} => <@valueDiv><@doMap map[key] /></@valueDiv>
|
||||
</li>
|
||||
</#list>
|
||||
</ul>
|
||||
|
@ -125,21 +125,39 @@ div.dump {
|
|||
|
||||
<#macro doHelp help="">
|
||||
<#if help?has_content>
|
||||
<p><strong>Help:</strong><p>
|
||||
<ul class="help">
|
||||
<#list help?keys as key>
|
||||
<li>
|
||||
<p><strong>${key}</strong></p>
|
||||
<#--<@valueDiv help[key] />-->
|
||||
<#local value = help[key]>
|
||||
<@valueDiv>
|
||||
<#if value?is_string><p><strong>${key?capitalize}:</strong> ${value}</p>
|
||||
<#else>
|
||||
<p><strong>${key?capitalize}:</strong></p>
|
||||
<ul>
|
||||
<#if value?is_sequence>
|
||||
<#list value as item>
|
||||
<li>${item}</li>
|
||||
</#list>
|
||||
<#elseif value?is_hash_ex>
|
||||
<#list value?keys as key>
|
||||
<li><strong>${key}:</strong> ${value[key]}</li>
|
||||
</#list>
|
||||
</#if>
|
||||
</ul>
|
||||
</#if>
|
||||
</@valueDiv>
|
||||
</li>
|
||||
</#list>
|
||||
</ul>
|
||||
</#if>
|
||||
</#macro>
|
||||
|
||||
<#macro valueDiv value>
|
||||
<div class="value"><@doMap value /></div>
|
||||
<#macro valueDiv>
|
||||
<div class="value"><#nested></div>
|
||||
</#macro>
|
||||
|
||||
|
||||
<#-- This will work after we move stylesheets to Configuration sharedVariables
|
||||
${stylesheets.add('<link rel="stylesheet" href="/css/fmdump.css">')}
|
||||
-->
|
||||
|
|
Loading…
Add table
Reference in a new issue