Moved method for property group display name out of ftl and into the template model class
This commit is contained in:
parent
55584d6be5
commit
796f6e0965
8 changed files with 32 additions and 49 deletions
|
@ -56,9 +56,10 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper;
|
|||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualUrlMethod;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualProfileUrlMethod;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||
import freemarker.ext.beans.BeansWrapper;
|
||||
|
||||
/**
|
||||
* Handles requests for entity information.
|
||||
|
@ -123,12 +124,11 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
/* We need to expose non-getters in displaying the individual's property list,
|
||||
* since it requires calls to methods with parameters.
|
||||
* This is still safe, because we are only putting BaseTemplateModel objects
|
||||
* into the data model. No real data can be modified.
|
||||
* RY Not sure this will be needed; postpone.
|
||||
* into the data model: no real data can be modified.
|
||||
*/
|
||||
body.put("individual", ind); //getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(ind));
|
||||
body.put("individual", getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(ind));
|
||||
|
||||
body.put("url", new IndividualUrlMethod());
|
||||
body.put("url", new IndividualProfileUrlMethod());
|
||||
|
||||
String template = getIndividualTemplate(individual);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import freemarker.core.Environment;
|
|||
import freemarker.template.TemplateMethodModel;
|
||||
import freemarker.template.TemplateModelException;
|
||||
|
||||
public class IndividualUrlMethod implements TemplateMethodModel {
|
||||
public class IndividualProfileUrlMethod implements TemplateMethodModel {
|
||||
|
||||
@Override
|
||||
public String exec(List args) throws TemplateModelException {
|
|
@ -24,31 +24,21 @@ public class BaseObjectPropertyDataPreprocessor implements
|
|||
public void process(List<Map<String, String>> data) {
|
||||
for (Map<String, String> map : data) {
|
||||
applyStandardPreprocessing(map);
|
||||
applySpecificPreprocessing(map);
|
||||
applyPropertySpecificPreprocessing(map);
|
||||
}
|
||||
}
|
||||
|
||||
/* Standard preprocessing that applies to all views. */
|
||||
protected void applyStandardPreprocessing(Map<String, String> map) {
|
||||
addLinkForTarget(map);
|
||||
/* none identified yet */
|
||||
}
|
||||
|
||||
protected void applySpecificPreprocessing(Map<String, String> map) {
|
||||
protected void applyPropertySpecificPreprocessing(Map<String, String> map) {
|
||||
/* Base class method is empty because this method is defined
|
||||
* to apply subclass preprocessing.
|
||||
*/
|
||||
}
|
||||
|
||||
private void addLinkForTarget(Map<String, String> map) {
|
||||
String linkTarget = objectPropertyTemplateModel.getLinkTarget();
|
||||
String targetUri = map.get(linkTarget);
|
||||
if (targetUri != null) {
|
||||
String targetUrl = getLink(targetUri);
|
||||
map.put(linkTarget + "Url", targetUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Preprocessor helper methods callable from any preprocessor */
|
||||
|
||||
protected String getLink(String uri) {
|
||||
|
|
|
@ -15,7 +15,7 @@ public class DefaultObjectPropertyDataPreprocessor extends
|
|||
|
||||
@Override
|
||||
/* Apply preprocessing specific to this preprocessor */
|
||||
protected void applySpecificPreprocessing(Map<String, String> map) {
|
||||
protected void applyPropertySpecificPreprocessing(Map<String, String> map) {
|
||||
addName(map);
|
||||
addMoniker(map);
|
||||
}
|
||||
|
@ -26,7 +26,12 @@ public class DefaultObjectPropertyDataPreprocessor extends
|
|||
map.put("name", getName(map.get("object")));
|
||||
}
|
||||
}
|
||||
|
||||
/* This is a temporary measure to handle the fact that the current Individual.getMoniker()
|
||||
* method returns the individual's VClass if moniker is null. We want to replicate that
|
||||
* behavior here, but in future the moniker property (along with other Vitro namespace
|
||||
* properties) will be removed. In addition, this type of logic (display x if it exists, otherwise y)
|
||||
* will be moved into the display modules (Editing and Display Configuration Improvements).
|
||||
*/
|
||||
private void addMoniker(Map<String, String> map) {
|
||||
String moniker = map.get("moniker");
|
||||
if (moniker == null) {
|
||||
|
|
|
@ -54,11 +54,6 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
return config.collationTarget;
|
||||
}
|
||||
|
||||
protected String getLinkTarget() {
|
||||
return config.linkTarget;
|
||||
}
|
||||
|
||||
|
||||
protected static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op, Individual subject, WebappDaoFactory wdf) {
|
||||
if (op.getCollateBySubclass()) {
|
||||
try {
|
||||
|
@ -96,13 +91,11 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
private static final String NODE_NAME_QUERY = "query";
|
||||
private static final String NODE_NAME_TEMPLATE = "template";
|
||||
private static final String NODE_NAME_COLLATION_TARGET = "collation-target";
|
||||
private static final String NODE_NAME_LINK_TARGET = "link-target";
|
||||
private static final String NODE_NAME_PREPROCESSOR = "preprocessor";
|
||||
|
||||
private String queryString;
|
||||
private String templateName;
|
||||
private String collationTarget;
|
||||
private String linkTarget; // we could easily make this a list if we ever want multiple links
|
||||
private String preprocessor;
|
||||
|
||||
PropertyListConfig(ObjectProperty op, WebappDaoFactory wdf) throws Exception {
|
||||
|
@ -133,7 +126,6 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
|||
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE);
|
||||
// Optional values
|
||||
collationTarget = getConfigValue(doc, NODE_NAME_COLLATION_TARGET);
|
||||
linkTarget = getConfigValue(doc, NODE_NAME_LINK_TARGET); // if this is null, no link will be generated
|
||||
preprocessor = getConfigValue(doc, NODE_NAME_PREPROCESSOR);
|
||||
} catch (Exception e) {
|
||||
log.error("Error processing config file " + configFilePath + " for object property " + op.getURI(), e);
|
||||
|
|
|
@ -38,8 +38,17 @@ public class PropertyGroupTemplateModel extends BaseTemplateModel {
|
|||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
/* Freemarker doesn't consider this a getter, because it takes a parameter, so to call it as group.name
|
||||
* in the templates the method name must be simply "name" and not "getName."
|
||||
*/
|
||||
public String name(String otherGroupName) {
|
||||
String displayName = name;
|
||||
if (displayName == null) {
|
||||
displayName = "";
|
||||
} else if (displayName.isEmpty()) {
|
||||
displayName = otherGroupName;
|
||||
}
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public List<PropertyTemplateModel> getProperties() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue