From 1b9f4bbdce3a4506bd736e50d4408c53c7321c15 Mon Sep 17 00:00:00 2001 From: ryounes Date: Fri, 22 Apr 2011 22:16:28 +0000 Subject: [PATCH] NIHVIVO-1562 Show class of template directive/model in dump. Use LinkedHashMap in help data structure to ensure ordering of the entries. --- .../vitro/webapp/web/directives/UrlDirective.java | 4 ++-- .../vitro/webapp/web/directives/WidgetDirective.java | 3 ++- .../webapp/web/methods/IndividualLocalNameMethod.java | 4 ++-- .../web/methods/IndividualProfileUrlMethod.java | 5 ++--- webapp/src/freemarker/ext/dump/BaseDumpDirective.java | 3 +++ webapp/src/freemarker/ext/dump/DumpAllDirective.java | 8 +++----- webapp/src/freemarker/ext/dump/DumpDirective.java | 7 +++---- webapp/src/freemarker/ext/dump/HelpDirective.java | 8 +++----- .../test/freemarker/ext/dump/DumpDirectiveTest.java | 11 +++++++++-- .../test/freemarker/ext/dump/HelpDirectiveTest.java | 7 +++++++ .../templates/freemarker/body/partials/dump/dump.ftl | 2 +- 11 files changed, 37 insertions(+), 25 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/UrlDirective.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/UrlDirective.java index 5ad4bad22..85a59a7cd 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/UrlDirective.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/UrlDirective.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -14,7 +15,6 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import freemarker.core.Environment; -import freemarker.template.Configuration; import freemarker.template.TemplateDirectiveBody; import freemarker.template.TemplateException; import freemarker.template.TemplateModel; @@ -61,7 +61,7 @@ public class UrlDirective extends BaseTemplateDirectiveModel { } public Map help(String name) { - Map map = new HashMap(); + Map map = new LinkedHashMap(); map.put("effect", "Generate a full url from a path by prepending the servlet context path. Use for generating src attribute of image tags, href attribute of anchor tags, etc."); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/WidgetDirective.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/WidgetDirective.java index 1a84c3282..654f5cecc 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/WidgetDirective.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/directives/WidgetDirective.java @@ -7,6 +7,7 @@ import java.io.Writer; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -94,7 +95,7 @@ public class WidgetDirective extends BaseTemplateDirectiveModel { } public Map help(String name) { - Map map = new HashMap(); + Map map = new LinkedHashMap(); map.put("effect", "Add a reuseable block of markup and functionality to the template, with associated scripts and stylesheets injected into the page <head> element."); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualLocalNameMethod.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualLocalNameMethod.java index 833fff918..9eee36cc9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualLocalNameMethod.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualLocalNameMethod.java @@ -3,7 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.web.methods; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -37,7 +37,7 @@ public class IndividualLocalNameMethod extends BaseTemplateMethodModel { @Override public Map help(String name) { - Map map = new HashMap(); + Map map = new LinkedHashMap(); map.put("return value", "The local name of the individual"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualProfileUrlMethod.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualProfileUrlMethod.java index b031779c0..0d95b387d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualProfileUrlMethod.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualProfileUrlMethod.java @@ -3,7 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.web.methods; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -12,7 +12,6 @@ import javax.servlet.http.HttpServletRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import freemarker.core.Environment; -import freemarker.template.TemplateMethodModel; import freemarker.template.TemplateModelException; public class IndividualProfileUrlMethod extends BaseTemplateMethodModel { @@ -34,7 +33,7 @@ public class IndividualProfileUrlMethod extends BaseTemplateMethodModel { @Override public Map help(String name) { - Map map = new HashMap(); + Map map = new LinkedHashMap(); map.put("return value", "The profile url of the individual"); diff --git a/webapp/src/freemarker/ext/dump/BaseDumpDirective.java b/webapp/src/freemarker/ext/dump/BaseDumpDirective.java index 95a7ac72f..d694d3f65 100644 --- a/webapp/src/freemarker/ext/dump/BaseDumpDirective.java +++ b/webapp/src/freemarker/ext/dump/BaseDumpDirective.java @@ -54,6 +54,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel { private static final Pattern PROPERTY_NAME_PATTERN = Pattern.compile("^(get|is)\\w"); enum Key { + CLASS("class"), DATE_TYPE("dateType"), HELP("help"), METHODS("methods"), @@ -430,6 +431,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel { private Map getTemplateModelDump(TemplateMethodModel model, String varName) throws TemplateModelException { Map map = new HashMap(); map.put(Key.TYPE.toString(), Type.METHOD); + map.put(Key.CLASS.toString(), model.getClass().getName()); map.put(Key.HELP.toString(), getHelp(model, varName)); return map; } @@ -437,6 +439,7 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel { private Map getTemplateModelDump(TemplateDirectiveModel model, String varName) throws TemplateModelException { Map map = new HashMap(); map.put(Key.TYPE.toString(), Type.DIRECTIVE); + map.put(Key.CLASS.toString(), model.getClass().getName()); map.put(Key.HELP.toString(), getHelp(model, varName)); return map; } diff --git a/webapp/src/freemarker/ext/dump/DumpAllDirective.java b/webapp/src/freemarker/ext/dump/DumpAllDirective.java index 4a8b52da7..ce2fbd536 100644 --- a/webapp/src/freemarker/ext/dump/DumpAllDirective.java +++ b/webapp/src/freemarker/ext/dump/DumpAllDirective.java @@ -4,7 +4,7 @@ package freemarker.ext.dump; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.SortedMap; @@ -69,12 +69,10 @@ public class DumpAllDirective extends BaseDumpDirective { @Override public Map help(String name) { - Map map = new HashMap(); + Map map = new LinkedHashMap(); map.put("effect", "Dumps the contents of the template data model."); - - //map.put("comments", ""); - + List examples = new ArrayList(); examples.add("<@" + name + " />"); map.put("examples", examples); diff --git a/webapp/src/freemarker/ext/dump/DumpDirective.java b/webapp/src/freemarker/ext/dump/DumpDirective.java index f966a3040..6d270c89c 100644 --- a/webapp/src/freemarker/ext/dump/DumpDirective.java +++ b/webapp/src/freemarker/ext/dump/DumpDirective.java @@ -5,6 +5,7 @@ package freemarker.ext.dump; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -57,12 +58,10 @@ public class DumpDirective extends BaseDumpDirective { @Override public Map help(String name) { - Map map = new HashMap(); + Map map = new LinkedHashMap(); map.put("effect", "Dumps the contents of a template variable."); - - //map.put("comments", ""); - + Map params = new HashMap(); params.put("var", "name of variable to dump"); map.put("parameters", params); diff --git a/webapp/src/freemarker/ext/dump/HelpDirective.java b/webapp/src/freemarker/ext/dump/HelpDirective.java index 550a117ef..1f513414a 100644 --- a/webapp/src/freemarker/ext/dump/HelpDirective.java +++ b/webapp/src/freemarker/ext/dump/HelpDirective.java @@ -5,6 +5,7 @@ package freemarker.ext.dump; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -17,7 +18,6 @@ import freemarker.template.TemplateHashModel; import freemarker.template.TemplateMethodModel; import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; -import freemarker.template.utility.DeepUnwrap; public class HelpDirective extends BaseDumpDirective { @@ -64,12 +64,10 @@ public class HelpDirective extends BaseDumpDirective { @Override public Map help(String name) { - Map map = new HashMap(); + Map map = new LinkedHashMap(); map.put("effect", "Outputs help for a directive or method."); - - //map.put("comments", ""); - + Map params = new HashMap(); params.put("for", "name of directive or method"); map.put("parameters", params); diff --git a/webapp/test/freemarker/ext/dump/DumpDirectiveTest.java b/webapp/test/freemarker/ext/dump/DumpDirectiveTest.java index ed7375476..607d5e987 100644 --- a/webapp/test/freemarker/ext/dump/DumpDirectiveTest.java +++ b/webapp/test/freemarker/ext/dump/DumpDirectiveTest.java @@ -256,6 +256,7 @@ public class DumpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD); + expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), null); Map expectedDump = new HashMap(); @@ -275,6 +276,7 @@ public class DumpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD); + expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), getMethodHelp(varName)); Map expectedDump = new HashMap(); @@ -294,6 +296,7 @@ public class DumpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD); + expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), null); Map expectedDump = new HashMap(); @@ -313,6 +316,7 @@ public class DumpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE); + expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), null); Map expectedDump = new HashMap(); @@ -332,6 +336,7 @@ public class DumpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE); + expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), getDirectiveHelp(varName)); Map expectedDump = new HashMap(); @@ -351,6 +356,7 @@ public class DumpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE); + expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), null); Map expectedDump = new HashMap(); @@ -735,14 +741,15 @@ public class DumpDirectiveTest { Map dataModel = new HashMap(); BeansWrapper wrapper = new BeansWrapper(); wrapper.setExposureLevel(exposureLevel); + Employee employee = getEmployee(); try { - dataModel.put("employee", wrapper.wrap(getEmployee())); + dataModel.put("employee", wrapper.wrap(employee)); } catch (TemplateModelException e) { // logging is suppressed, so what do we do here? } Map expectedDumpValue = new HashMap(); - expectedDumpValue.put(Key.TYPE.toString(), "freemarker.ext.dump.DumpDirectiveTest$Employee"); + expectedDumpValue.put(Key.TYPE.toString(), employee.getClass().getName()); expectedDumpValue.put(Key.VALUE.toString(), getJohnDoeExpectedDump(exposureLevel)); Map expectedDump = new HashMap(); diff --git a/webapp/test/freemarker/ext/dump/HelpDirectiveTest.java b/webapp/test/freemarker/ext/dump/HelpDirectiveTest.java index 78c6bde4e..050e14d42 100644 --- a/webapp/test/freemarker/ext/dump/HelpDirectiveTest.java +++ b/webapp/test/freemarker/ext/dump/HelpDirectiveTest.java @@ -57,7 +57,9 @@ public class HelpDirectiveTest { dataModel.put(varName, methodModel); Map expectedDumpValue = new HashMap(); + expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD); + expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), null); Map expectedDump = new HashMap(); @@ -77,6 +79,7 @@ public class HelpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD); + expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), getMethodHelp(varName)); Map expectedDump = new HashMap(); @@ -96,6 +99,7 @@ public class HelpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD); + expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), null); Map expectedDump = new HashMap(); @@ -115,6 +119,7 @@ public class HelpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE); + expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), null); Map expectedDump = new HashMap(); @@ -134,6 +139,7 @@ public class HelpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE); + expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), getDirectiveHelp(varName)); Map expectedDump = new HashMap(); @@ -153,6 +159,7 @@ public class HelpDirectiveTest { Map expectedDumpValue = new HashMap(); expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE); + expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName()); expectedDumpValue.put(Key.HELP.toString(), null); Map expectedDump = new HashMap(); diff --git a/webapp/web/templates/freemarker/body/partials/dump/dump.ftl b/webapp/web/templates/freemarker/body/partials/dump/dump.ftl index 80ac8470b..bff99fa73 100644 --- a/webapp/web/templates/freemarker/body/partials/dump/dump.ftl +++ b/webapp/web/templates/freemarker/body/partials/dump/dump.ftl @@ -157,7 +157,7 @@ div.dump { <#macro doMethod method> -

Type: ${method.type}

+

Type: ${method.type} (${method.class})

<#local help = method.help!> <#if help?has_content>

Help: