NIHVIVO-3114 Fix problems with dump of IndividualTemplateModel.qrData()
This commit is contained in:
parent
d438bca997
commit
1f9bcac9b1
4 changed files with 41 additions and 14 deletions
|
@ -58,9 +58,9 @@ import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
|||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.ExtendedLinkedDataUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
|
||||
import freemarker.ext.beans.ReadOnlyBeansWrapper;
|
||||
|
||||
/**
|
||||
* Handles requests for entity information.
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.beanswrappers;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import freemarker.ext.beans.BeansWrapper;
|
||||
import freemarker.ext.beans.BeansWrapper.MethodAppearanceDecision;
|
||||
|
||||
/** A BeansWrapper that is more restrictive than EXPOSE_SAFE, by
|
||||
* exposing getters but not setters. A setter is defined for this
|
||||
* purpose as a method that returns void, or whose name
|
||||
* starts with "set". It also hides built-in methods of Java
|
||||
* utility classes like Map.put(), etc.
|
||||
*
|
||||
* @author rjy7
|
||||
*
|
||||
*/
|
||||
public class ReadOnlyBeansWrapper extends BeansWrapper {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ReadOnlyBeansWrapper.class);
|
||||
|
||||
public ReadOnlyBeansWrapper() {
|
||||
// Start by exposing all safe methods.
|
||||
setExposureLevel(EXPOSE_SAFE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finetuneMethodAppearance(Class cls, Method method, MethodAppearanceDecision decision) {
|
||||
|
||||
// How to define a setter? This is a weak approximation: a method whose name
|
||||
// starts with "set" or returns void.
|
||||
if ( method.getName().startsWith("set") ) {
|
||||
decision.setExposeMethodAs(null);
|
||||
|
||||
} else if ( method.getReturnType().getName().equals("void") ) {
|
||||
decision.setExposeMethodAs(null);
|
||||
|
||||
} else {
|
||||
|
||||
Class<?> declaringClass = method.getDeclaringClass();
|
||||
if (declaringClass.equals(java.lang.Object.class)) {
|
||||
decision.setExposeMethodAs(null);
|
||||
|
||||
} else {
|
||||
Package pkg = declaringClass.getPackage();
|
||||
if (pkg.getName().equals("java.util")) {
|
||||
decision.setExposeMethodAs(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For exposing a method as a property (when it's not named getX or isX). Note that this is not
|
||||
// just a syntactic change in the template from X() to X, but also makes the value get precomputed.
|
||||
// private void exposeAsProperty(Method method, MethodAppearanceDecision decision) {
|
||||
// try {
|
||||
// PropertyDescriptor pd = new PropertyDescriptor(method.getName(), method, null);
|
||||
// decision.setExposeAsProperty(pd);
|
||||
// decision.setMethodShadowsProperty(false);
|
||||
// } catch (IntrospectionException e) {
|
||||
// log.error(e, e);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue