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\" />");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue