NIHVIVO-1562 Show class of template directive/model in dump. Use LinkedHashMap in help data structure to ensure ordering of the entries.

This commit is contained in:
ryounes 2011-04-22 22:16:28 +00:00
parent b6ea045503
commit 1b9f4bbdce
11 changed files with 37 additions and 25 deletions

View file

@ -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<String, Object> help(String name) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<String, Object>();
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.");

View file

@ -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<String, Object> help(String name) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("effect", "Add a reuseable block of markup and functionality to the template, with associated scripts and stylesheets injected into the page &lt;head&gt; element.");

View file

@ -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<String, Object> help(String name) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("return value", "The local name of the individual");

View file

@ -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<String, Object> help(String name) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("return value", "The profile url of the individual");

View file

@ -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<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(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<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(Key.CLASS.toString(), model.getClass().getName());
map.put(Key.HELP.toString(), getHelp(model, varName));
return map;
}

View file

@ -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<String, Object> help(String name) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("effect", "Dumps the contents of the template data model.");
//map.put("comments", "");
List<String> examples = new ArrayList<String>();
examples.add("<@" + name + " />");
map.put("examples", examples);

View file

@ -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<String, Object> help(String name) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<String, Object>();
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("parameters", params);

View file

@ -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<String, Object> help(String name) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<String, Object>();
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("parameters", params);

View file

@ -256,6 +256,7 @@ public class DumpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), null);
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -275,6 +276,7 @@ public class DumpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), getMethodHelp(varName));
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -294,6 +296,7 @@ public class DumpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), null);
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -313,6 +316,7 @@ public class DumpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), null);
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -332,6 +336,7 @@ public class DumpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), getDirectiveHelp(varName));
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -351,6 +356,7 @@ public class DumpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), null);
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -735,14 +741,15 @@ public class DumpDirectiveTest {
Map<String, Object> dataModel = new HashMap<String, Object>();
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<String, Object> expectedDumpValue = new HashMap<String, Object>();
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<String, Object> expectedDump = new HashMap<String, Object>();

View file

@ -57,7 +57,9 @@ public class HelpDirectiveTest {
dataModel.put(varName, methodModel);
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), null);
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -77,6 +79,7 @@ public class HelpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), getMethodHelp(varName));
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -96,6 +99,7 @@ public class HelpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
expectedDumpValue.put(Key.CLASS.toString(), methodModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), null);
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -115,6 +119,7 @@ public class HelpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), null);
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -134,6 +139,7 @@ public class HelpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), getDirectiveHelp(varName));
Map<String, Object> expectedDump = new HashMap<String, Object>();
@ -153,6 +159,7 @@ public class HelpDirectiveTest {
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
expectedDumpValue.put(Key.CLASS.toString(), directiveModel.getClass().getName());
expectedDumpValue.put(Key.HELP.toString(), null);
Map<String, Object> expectedDump = new HashMap<String, Object>();

View file

@ -157,7 +157,7 @@ div.dump {
</#macro>
<#macro doMethod method>
<p><strong>Type:</strong> ${method.type}</p>
<p><strong>Type:</strong> ${method.type} (${method.class})</p>
<#local help = method.help!>
<#if help?has_content>
<p><strong>Help:</strong><p>