Moved method for property group display name out of ftl and into the template model class

This commit is contained in:
rjy7 2010-12-17 17:20:48 +00:00
parent 55584d6be5
commit 796f6e0965
8 changed files with 32 additions and 49 deletions

View file

@ -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);

View file

@ -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 {

View file

@ -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) {

View file

@ -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) {

View file

@ -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);

View file

@ -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() {

View file

@ -114,10 +114,11 @@
</section>
</section>
<#assign nameForOtherGroup = "other">
<nav id="property-group-menus" role="navigation">
<ul role="list">
<#list propertyGroups as group>
<#assign groupname = groupName(group)>
<#assign groupname = group.name(nameForOtherGroup)>
<#if groupname?has_content>
<#-- capitalize will capitalize each word in the name; cap_first only the first. We may need a custom
function to capitalize all except function words. -->
@ -149,18 +150,4 @@ ${headScripts.add("/js/jquery_plugins/getUrlParam.js",
${scripts.add("/js/imageUpload/imageUploadUtils.js")}
<#-- RY TEMPORARY Replace with Java method on group - pass "other" as a parameter -->
<#function groupName group>
<#if group.name??>
<#if group.name?has_content>
<#assign name = group.name>
<#else>
<#-- This is the group for properties not assigned to any group. It has an empty name. -->
<#assign name = "other">
</#if>
<#else>
<#-- If there are no groups, a dummy group has been created with a null (as opposed to empty) name. -->
<#assign name = "">
</#if>
<#return name>
</#function>

View file

@ -4,7 +4,7 @@
<#list propertyGroups as group>
<#assign groupname = groupName(group)>
<#assign groupname = group.name(nameForOtherGroup)>
<section class="property-group" role="region">