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.NamespaceMapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
|
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
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.jsptags.StringProcessorTag;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||||
|
import freemarker.ext.beans.BeansWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles requests for entity information.
|
* 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,
|
/* We need to expose non-getters in displaying the individual's property list,
|
||||||
* since it requires calls to methods with parameters.
|
* since it requires calls to methods with parameters.
|
||||||
* This is still safe, because we are only putting BaseTemplateModel objects
|
* This is still safe, because we are only putting BaseTemplateModel objects
|
||||||
* into the data model. No real data can be modified.
|
* into the data model: no real data can be modified.
|
||||||
* RY Not sure this will be needed; postpone.
|
|
||||||
*/
|
*/
|
||||||
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);
|
String template = getIndividualTemplate(individual);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import freemarker.core.Environment;
|
||||||
import freemarker.template.TemplateMethodModel;
|
import freemarker.template.TemplateMethodModel;
|
||||||
import freemarker.template.TemplateModelException;
|
import freemarker.template.TemplateModelException;
|
||||||
|
|
||||||
public class IndividualUrlMethod implements TemplateMethodModel {
|
public class IndividualProfileUrlMethod implements TemplateMethodModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String exec(List args) throws TemplateModelException {
|
public String exec(List args) throws TemplateModelException {
|
|
@ -24,31 +24,21 @@ public class BaseObjectPropertyDataPreprocessor implements
|
||||||
public void process(List<Map<String, String>> data) {
|
public void process(List<Map<String, String>> data) {
|
||||||
for (Map<String, String> map : data) {
|
for (Map<String, String> map : data) {
|
||||||
applyStandardPreprocessing(map);
|
applyStandardPreprocessing(map);
|
||||||
applySpecificPreprocessing(map);
|
applyPropertySpecificPreprocessing(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Standard preprocessing that applies to all views. */
|
/* Standard preprocessing that applies to all views. */
|
||||||
protected void applyStandardPreprocessing(Map<String, String> map) {
|
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
|
/* Base class method is empty because this method is defined
|
||||||
* to apply subclass preprocessing.
|
* 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 */
|
/* Preprocessor helper methods callable from any preprocessor */
|
||||||
|
|
||||||
protected String getLink(String uri) {
|
protected String getLink(String uri) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class DefaultObjectPropertyDataPreprocessor extends
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/* Apply preprocessing specific to this preprocessor */
|
/* Apply preprocessing specific to this preprocessor */
|
||||||
protected void applySpecificPreprocessing(Map<String, String> map) {
|
protected void applyPropertySpecificPreprocessing(Map<String, String> map) {
|
||||||
addName(map);
|
addName(map);
|
||||||
addMoniker(map);
|
addMoniker(map);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,12 @@ public class DefaultObjectPropertyDataPreprocessor extends
|
||||||
map.put("name", getName(map.get("object")));
|
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) {
|
private void addMoniker(Map<String, String> map) {
|
||||||
String moniker = map.get("moniker");
|
String moniker = map.get("moniker");
|
||||||
if (moniker == null) {
|
if (moniker == null) {
|
||||||
|
|
|
@ -54,11 +54,6 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
return config.collationTarget;
|
return config.collationTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getLinkTarget() {
|
|
||||||
return config.linkTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op, Individual subject, WebappDaoFactory wdf) {
|
protected static ObjectPropertyTemplateModel getObjectPropertyTemplateModel(ObjectProperty op, Individual subject, WebappDaoFactory wdf) {
|
||||||
if (op.getCollateBySubclass()) {
|
if (op.getCollateBySubclass()) {
|
||||||
try {
|
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_QUERY = "query";
|
||||||
private static final String NODE_NAME_TEMPLATE = "template";
|
private static final String NODE_NAME_TEMPLATE = "template";
|
||||||
private static final String NODE_NAME_COLLATION_TARGET = "collation-target";
|
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 static final String NODE_NAME_PREPROCESSOR = "preprocessor";
|
||||||
|
|
||||||
private String queryString;
|
private String queryString;
|
||||||
private String templateName;
|
private String templateName;
|
||||||
private String collationTarget;
|
private String collationTarget;
|
||||||
private String linkTarget; // we could easily make this a list if we ever want multiple links
|
|
||||||
private String preprocessor;
|
private String preprocessor;
|
||||||
|
|
||||||
PropertyListConfig(ObjectProperty op, WebappDaoFactory wdf) throws Exception {
|
PropertyListConfig(ObjectProperty op, WebappDaoFactory wdf) throws Exception {
|
||||||
|
@ -133,7 +126,6 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE);
|
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE);
|
||||||
// Optional values
|
// Optional values
|
||||||
collationTarget = getConfigValue(doc, NODE_NAME_COLLATION_TARGET);
|
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);
|
preprocessor = getConfigValue(doc, NODE_NAME_PREPROCESSOR);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error processing config file " + configFilePath + " for object property " + op.getURI(), 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() {
|
/* Freemarker doesn't consider this a getter, because it takes a parameter, so to call it as group.name
|
||||||
return 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() {
|
public List<PropertyTemplateModel> getProperties() {
|
||||||
|
|
|
@ -114,10 +114,11 @@
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<#assign nameForOtherGroup = "other">
|
||||||
<nav id="property-group-menus" role="navigation">
|
<nav id="property-group-menus" role="navigation">
|
||||||
<ul role="list">
|
<ul role="list">
|
||||||
<#list propertyGroups as group>
|
<#list propertyGroups as group>
|
||||||
<#assign groupname = groupName(group)>
|
<#assign groupname = group.name(nameForOtherGroup)>
|
||||||
<#if groupname?has_content>
|
<#if groupname?has_content>
|
||||||
<#-- capitalize will capitalize each word in the name; cap_first only the first. We may need a custom
|
<#-- 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. -->
|
function to capitalize all except function words. -->
|
||||||
|
@ -149,18 +150,4 @@ ${headScripts.add("/js/jquery_plugins/getUrlParam.js",
|
||||||
|
|
||||||
${scripts.add("/js/imageUpload/imageUploadUtils.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>
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<#list propertyGroups as group>
|
<#list propertyGroups as group>
|
||||||
|
|
||||||
<#assign groupname = groupName(group)>
|
<#assign groupname = group.name(nameForOtherGroup)>
|
||||||
|
|
||||||
<section class="property-group" role="region">
|
<section class="property-group" role="region">
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue