diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SamplesController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SamplesController.java index 2e60dfaf5..973457ee8 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SamplesController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/SamplesController.java @@ -14,9 +14,7 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.beans.Portal; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.ResponseValues; -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.TemplateResponseValues; -import freemarker.template.Configuration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; /** * Freemarker controller and template samples. @@ -82,6 +80,8 @@ public class SamplesController extends FreemarkerHttpServlet { body.put("trueStatement", true); body.put("falseStatement", false); + body.put("pojo", new EditConfiguration()); + getBerries(body); body.put("bookTitle", "Pride and Prejudice"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DumpHelper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DumpHelper.java index 0cc856092..24525f83c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DumpHelper.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/dump/DumpHelper.java @@ -20,7 +20,6 @@ import freemarker.template.TemplateHashModel; import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; import freemarker.template.TemplateNumberModel; -import freemarker.template.TemplateScalarModel; import freemarker.template.TemplateSequenceModel; import freemarker.template.utility.DeepUnwrap; @@ -54,9 +53,7 @@ public class DumpHelper { map.put("var", varName); if (tm != null) { - String type = null; Object unwrappedModel = null; - try { unwrappedModel = DeepUnwrap.permissiveUnwrap(tm); } catch (TemplateModelException e) { @@ -66,39 +63,52 @@ public class DumpHelper { // Just use toString() method for now. Handles nested collections. Could make more sophisticated later. // tm.toString() gives wrong results in the case of, e.g., a boolean value in a hash. tm.toString() may // return a TemplateBooleanModel object, while unwrappedModel.toString() returns "true" or "false." - String value = unwrappedModel.toString(); // tm.toString(); + String value = unwrappedModel.toString(); // tm.toString(); + String className = unwrappedModel.getClass().getName(); + String type = null; - // This case must precede the TemplateScalarModel case, because - // tm is an instance of StringModel and thus a TemplateScalarModel. + // For basic Java types such as string, date, boolean, it's most helpful for the dump to + // show the shorthand type assigned below, rather than the Java class name. But for our + // BaseTemplateModel objects, show the actual class, since that provides additional + // information about the object (available methods, for example) that it is helpful to + // view in the dump. Not sure if we should handle our application-specific, non-template + // model objects in the same way. For now, these get assigned a shorthand type below. if (unwrappedModel instanceof BaseTemplateModel) { - type = unwrappedModel.getClass().getName(); - value = ((BaseTemplateModel)unwrappedModel).dump(); - } else if (tm instanceof TemplateScalarModel) { - type = "string"; + value = ((BaseTemplateModel)unwrappedModel).dump(); + type = className; + } + // Can't use this, because tm of (at least some) POJOs are + // StringModels, which are both TemplateScalarModels and TemplateHashModels + // if (tm instanceof TemplateScalarModel) + else if (unwrappedModel instanceof String) { + type = "String"; } else if (tm instanceof TemplateDateModel) { - type = "date"; + type = "Date"; } else if (tm instanceof TemplateNumberModel) { - type = "number"; + type = "Number"; } else if (tm instanceof TemplateBooleanModel) { - type = "boolean"; + type = "Boolean"; try { - value = ((TemplateBooleanModel) tm).getAsBoolean() ? "true" : "false"; + value = ((TemplateBooleanModel) tm).getAsBoolean() ? "true" : "false"; } catch (TemplateModelException e) { log.error("Error getting boolean value for " + varName + "."); } } else if (tm instanceof TemplateSequenceModel){ - type = "sequence"; + type = "Sequence"; } else if (tm instanceof TemplateHashModel) { - type = "hash"; + type = "Hash"; // In recursive dump, we've gotten down to a raw string. Just output it. // } else if (val == null) { // out.write(var); // return; } else { - type = "object"; + // One of the above cases should have applied. Just in case not, show the Java class name. + type = className; } + map.put("value", value); map.put("type", type); + } return map; diff --git a/webapp/web/css/dump.css b/webapp/web/css/dump.css index 8e3308e25..fa1b5ba5d 100644 --- a/webapp/web/css/dump.css +++ b/webapp/web/css/dump.css @@ -22,3 +22,7 @@ padding: 1em 0; margin: 1em 0; } + +.dump .var p { + margin-bottom: .3em; +} diff --git a/webapp/web/templates/freemarker/body/partials/dump/dump-var.ftl b/webapp/web/templates/freemarker/body/partials/dump/dump-var.ftl index 2306fbd0f..33c74add4 100644 --- a/webapp/web/templates/freemarker/body/partials/dump/dump-var.ftl +++ b/webapp/web/templates/freemarker/body/partials/dump/dump-var.ftl @@ -3,14 +3,12 @@ <#-- Template for dumping a template variable -->
- -
Variable name: ${var}
+

Variable name: ${var}

<#if value??> - Type: ${type}
- Value: ${value}
+

Value: ${value}

+

Type: ${type}

<#else> - Variable is undefined in the data model - - +

Variable is undefined in the data model

+
diff --git a/webapp/web/templates/freemarker/body/samples.ftl b/webapp/web/templates/freemarker/body/samples.ftl index f44dfddc5..9049d2ad9 100644 --- a/webapp/web/templates/freemarker/body/samples.ftl +++ b/webapp/web/templates/freemarker/body/samples.ftl @@ -51,6 +51,7 @@ <@dump var="fruit" /> <@dump var="trueStatement" /> <@dump var="zoo1" /> +<@dump var="pojo" /> ${stylesheets.addFromTheme("/css/sstest.css", "/css/sstest2.css")} ${scripts.addFromTheme("/js/jstest.js")}