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 org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHelper;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHelper;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.SimpleScalar;
|
import freemarker.template.SimpleScalar;
|
||||||
|
@ -26,6 +27,7 @@ import freemarker.template.TemplateModelException;
|
||||||
import freemarker.template.TemplateNumberModel;
|
import freemarker.template.TemplateNumberModel;
|
||||||
import freemarker.template.TemplateScalarModel;
|
import freemarker.template.TemplateScalarModel;
|
||||||
import freemarker.template.TemplateSequenceModel;
|
import freemarker.template.TemplateSequenceModel;
|
||||||
|
import freemarker.template.utility.DeepUnwrap;
|
||||||
|
|
||||||
public class DumpDirective extends BaseTemplateDirectiveModel {
|
public class DumpDirective extends BaseTemplateDirectiveModel {
|
||||||
|
|
||||||
|
@ -77,8 +79,14 @@ public class DumpDirective extends BaseTemplateDirectiveModel {
|
||||||
// Just use this for now. Handles nested collections.
|
// Just use this for now. Handles nested collections.
|
||||||
String value = val.toString();
|
String value = val.toString();
|
||||||
String type = null;
|
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";
|
type = "string";
|
||||||
} else if (val instanceof TemplateDateModel) {
|
} else if (val instanceof TemplateDateModel) {
|
||||||
type = "date";
|
type = "date";
|
||||||
|
|
|
@ -33,6 +33,10 @@ public abstract class BaseTemplateModel {
|
||||||
public static void setServletContext(ServletContext context) {
|
public static void setServletContext(ServletContext context) {
|
||||||
BaseTemplateModel.servletContext = context;
|
BaseTemplateModel.servletContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String dump() {
|
||||||
|
return "I'm a BaseTemplateModel object";
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* public static List<?> wrapList(List<?> list, Class cl)
|
* public static List<?> wrapList(List<?> list, Class cl)
|
||||||
|
|
|
@ -54,6 +54,10 @@ public abstract class Files extends BaseTemplateModel {
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String dump() {
|
||||||
|
return list.toString();
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract String getThemeSubDir();
|
protected abstract String getThemeSubDir();
|
||||||
protected abstract String getTag(String url);
|
protected abstract String getTag(String url);
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,12 @@
|
||||||
<@dump var="urls" />
|
<@dump var="urls" />
|
||||||
<@dump var="fruit" />
|
<@dump var="fruit" />
|
||||||
<@dump var="trueStatement" />
|
<@dump var="trueStatement" />
|
||||||
<@dump var="falseStatement" /> -->
|
<@dump var="falseStatement" />
|
||||||
|
<@dump var="zoo1" /> -->
|
||||||
|
|
||||||
<@dump var="zoo1" />
|
|
||||||
<@dumpDataModel />
|
|
||||||
|
|
||||||
${stylesheets.addFromTheme("/sstest.css", "/sstest2.css")}
|
${stylesheets.addFromTheme("/sstest.css", "/sstest2.css")}
|
||||||
${scripts.addFromTheme("/jstest.js")}
|
${scripts.addFromTheme("/jstest.js")}
|
||||||
${scripts.add("/js/script1.js", "/js/script2.js", "/js/script3.js")}
|
${scripts.add("/js/script1.js", "/js/script2.js", "/js/script3.js")}
|
||||||
|
|
||||||
|
<@dumpDataModel />
|
||||||
|
|
Loading…
Add table
Reference in a new issue