NIHVIVO-1564 Improvements to dump methods
This commit is contained in:
parent
7efe660427
commit
733a70faf4
5 changed files with 20 additions and 14 deletions
|
@ -104,10 +104,8 @@ public class FreemarkerConfigurationLoader {
|
|||
// The Freemarker default wrapper exposes set methods and get methods that take
|
||||
// arguments. We block exposure to these methods by default.
|
||||
BeansWrapper wrapper = new DefaultObjectWrapper();
|
||||
int defaultExposureLevel = BeansWrapper.EXPOSE_PROPERTIES_ONLY;
|
||||
wrapper.setExposureLevel(defaultExposureLevel);
|
||||
wrapper.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY);
|
||||
config.setObjectWrapper(wrapper);
|
||||
config.setCustomAttribute("defaultExposureLevel", defaultExposureLevel);
|
||||
|
||||
// Set some formatting defaults. These can be overridden at the template
|
||||
// or environment (template-processing) level, or for an individual
|
||||
|
|
|
@ -286,8 +286,6 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
|
||||
protected BeansWrapper getNonDefaultBeansWrapper(int exposureLevel) {
|
||||
BeansWrapper wrapper = new DefaultObjectWrapper();
|
||||
// Too bad exposure levels are ints instead of enum values; what happens if
|
||||
// we send an int that's not a defined exposure level?
|
||||
wrapper.setExposureLevel(exposureLevel);
|
||||
return wrapper;
|
||||
}
|
||||
|
|
|
@ -146,14 +146,15 @@ public class DumpHelper {
|
|||
// Get the exposure level of the BeansWrapper that wrapped this object.
|
||||
if (model instanceof BeanModel) {
|
||||
exposureLevel = WrapperExtractor.getWrapperExposureLevel((BeanModel) model);
|
||||
log.debug("Exposure level for class " + cls.getCanonicalName() + " of type " + model.getClass() + " = " + exposureLevel);
|
||||
log.debug("Exposure level for class " + cls.getCanonicalName() + " wrapped as " + model.getClass() + " = " + exposureLevel);
|
||||
// We don't expect to get here, since we are dealing only with BaseTemplateModel objects, which get wrapped into BeanModel objects,
|
||||
// but it's here as a safety net.
|
||||
} else {
|
||||
HttpServletRequest request = (HttpServletRequest) env.getCustomAttribute("request");
|
||||
Configuration config = (Configuration) request.getAttribute("freemarkerConfig");
|
||||
exposureLevel = (Integer) config.getCustomAttribute("defaultExposureLevel");
|
||||
log.debug("Class " + cls.getCanonicalName() + " of type " + model.getClass() + " uses default exposure level " + exposureLevel);
|
||||
BeansWrapper wrapper = (BeansWrapper) config.getObjectWrapper();
|
||||
exposureLevel = WrapperExtractor.getWrapperExposureLevel(wrapper);
|
||||
log.debug("Class " + cls.getCanonicalName() + " wrapped as " + model.getClass() + " uses default exposure level " + exposureLevel);
|
||||
}
|
||||
|
||||
return exposureLevel;
|
||||
|
@ -263,5 +264,5 @@ public class DumpHelper {
|
|||
Map<String, Object> map = getTemplateModelValues(model, exposureLevel);
|
||||
return BaseTemplateDirectiveModel.processTemplateToString("dump-var.ftl", map, env);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -24,11 +24,13 @@ public abstract class PropertyStatementTemplateModel extends BaseTemplateModel {
|
|||
private List<EditAccess> editAccessList = null;
|
||||
|
||||
PropertyStatementTemplateModel(String subjectUri, String propertyUri, EditingPolicyHelper policyHelper) {
|
||||
// Instantiate the list even if not editing, so calls to getEditUrl() and getDeleteUrl() from
|
||||
// dump methods don't generate an error when they call isEditable() and isDeletable().
|
||||
editAccessList = new ArrayList<EditAccess>();
|
||||
|
||||
if (policyHelper != null) { // we're editing
|
||||
this.subjectUri = subjectUri;
|
||||
this.propertyUri = propertyUri;
|
||||
editAccessList = new ArrayList<EditAccess>();
|
||||
this.propertyUri = propertyUri;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
package freemarker.ext.beans;
|
||||
|
||||
import freemarker.template.TemplateModel;
|
||||
|
||||
/**
|
||||
* Class to extract information about the wrapper used to wrap an object in
|
||||
* the template model.
|
||||
* the template model. This is something of a hack: the class belongs to
|
||||
* package freemarker.ext.beans so we can get at protected members of
|
||||
* BeanModel and BeansWrapper. The Freemarker API unfortunately provides
|
||||
* no way to get the wrapper that is used to wrap an object in the
|
||||
* template data model.
|
||||
*/
|
||||
public class WrapperExtractor {
|
||||
|
||||
|
@ -17,4 +19,9 @@ public class WrapperExtractor {
|
|||
public static int getWrapperExposureLevel(BeanModel model) {
|
||||
return model.wrapper.getExposureLevel();
|
||||
}
|
||||
|
||||
public static int getWrapperExposureLevel(BeansWrapper wrapper) {
|
||||
return wrapper.getExposureLevel();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue