NIHVIVO-564 Added infrastructure for dumping template model objects.
This commit is contained in:
parent
5e8eb80732
commit
b90efc74fb
4 changed files with 22 additions and 5 deletions
|
@ -13,6 +13,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHelper;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.SimpleScalar;
|
||||
|
@ -26,6 +27,7 @@ import freemarker.template.TemplateModelException;
|
|||
import freemarker.template.TemplateNumberModel;
|
||||
import freemarker.template.TemplateScalarModel;
|
||||
import freemarker.template.TemplateSequenceModel;
|
||||
import freemarker.template.utility.DeepUnwrap;
|
||||
|
||||
public class DumpDirective extends BaseTemplateDirectiveModel {
|
||||
|
||||
|
@ -77,8 +79,14 @@ public class DumpDirective extends BaseTemplateDirectiveModel {
|
|||
// Just use this for now. Handles nested collections.
|
||||
String value = val.toString();
|
||||
String type = null;
|
||||
Object unwrappedModel = DeepUnwrap.permissiveUnwrap(val);
|
||||
|
||||
if (val instanceof TemplateScalarModel) {
|
||||
// This case must precede the TemplateScalarModel case, because
|
||||
// val is an instance of StringModel.
|
||||
if (unwrappedModel instanceof BaseTemplateModel) {
|
||||
type = unwrappedModel.getClass().getName();
|
||||
value = ((BaseTemplateModel)unwrappedModel).dump();
|
||||
} else if (val instanceof TemplateScalarModel) {
|
||||
type = "string";
|
||||
} else if (val instanceof TemplateDateModel) {
|
||||
type = "date";
|
||||
|
|
|
@ -34,6 +34,10 @@ public abstract class BaseTemplateModel {
|
|||
BaseTemplateModel.servletContext = context;
|
||||
}
|
||||
|
||||
public String dump() {
|
||||
return "I'm a BaseTemplateModel object";
|
||||
}
|
||||
|
||||
/*
|
||||
* public static List<?> wrapList(List<?> list, Class cl)
|
||||
* throw error if cl not a child of ViewObject
|
||||
|
|
|
@ -54,6 +54,10 @@ public abstract class Files extends BaseTemplateModel {
|
|||
return tags;
|
||||
}
|
||||
|
||||
public String dump() {
|
||||
return list.toString();
|
||||
}
|
||||
|
||||
protected abstract String getThemeSubDir();
|
||||
protected abstract String getTag(String url);
|
||||
|
||||
|
|
|
@ -51,11 +51,12 @@
|
|||
<@dump var="urls" />
|
||||
<@dump var="fruit" />
|
||||
<@dump var="trueStatement" />
|
||||
<@dump var="falseStatement" /> -->
|
||||
<@dump var="falseStatement" />
|
||||
<@dump var="zoo1" /> -->
|
||||
|
||||
<@dump var="zoo1" />
|
||||
<@dumpDataModel />
|
||||
|
||||
${stylesheets.addFromTheme("/sstest.css", "/sstest2.css")}
|
||||
${scripts.addFromTheme("/jstest.js")}
|
||||
${scripts.add("/js/script1.js", "/js/script2.js", "/js/script3.js")}
|
||||
|
||||
<@dumpDataModel />
|
||||
|
|
Loading…
Add table
Reference in a new issue