diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfiguration.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfiguration.java index de6fd454c..7093b5962 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfiguration.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreemarkerConfiguration.java @@ -19,6 +19,10 @@ import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.RevisionInfoBean; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants; +import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualLocalNameMethod; +import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualPlaceholderImageUrlMethod; +import edu.cornell.mannlib.vitro.webapp.web.methods.IndividualProfileUrlMethod; import freemarker.cache.ClassTemplateLoader; import freemarker.cache.FileTemplateLoader; import freemarker.cache.MultiTemplateLoader; @@ -28,7 +32,6 @@ import freemarker.template.Configuration; import freemarker.template.DefaultObjectWrapper; import freemarker.template.TemplateException; import freemarker.template.TemplateModelException; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants; public class FreemarkerConfiguration extends Configuration { @@ -160,8 +163,9 @@ public class FreemarkerConfiguration extends Configuration { public static Map getMethods() { Map map = new HashMap(); - map.put("profileUrl", new edu.cornell.mannlib.vitro.webapp.web.methods.IndividualProfileUrlMethod()); - map.put("localName", new edu.cornell.mannlib.vitro.webapp.web.methods.IndividualLocalNameMethod()); + map.put("profileUrl", new IndividualProfileUrlMethod()); + map.put("localName", new IndividualLocalNameMethod()); + map.put("placeholderImageUrl", new IndividualPlaceholderImageUrlMethod()); return map; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java index 3438e0a9e..e28b4c942 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java @@ -36,6 +36,7 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup; import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest; +import edu.cornell.mannlib.vitro.webapp.utils.ImageUtil; /** * Handle adding, replacing or deleting the main image on an Individual. @@ -63,12 +64,6 @@ public class ImageUploadController extends FreemarkerHttpServlet { /** The form field of the uploaded file; use as a key to the FileItem map. */ public static final String PARAMETER_UPLOADED_FILE = "datafile"; - /** - * The image to use as a placeholder when the individual has no image. - * Determined by the template. - */ - public static final String PARAMETER_PLACEHOLDER_URL = "placeholder"; - /** Here is the main image file. Hold on to it. */ public static final String ACTION_UPLOAD = "upload"; @@ -141,7 +136,8 @@ public class ImageUploadController extends FreemarkerHttpServlet { String imageUri = entity.getMainImageUri(); RequestedAction ra; - if (ACTION_DELETE.equals(action) || ACTION_DELETE_EDIT.equals(action)) { + if (ACTION_DELETE.equals(action) + || ACTION_DELETE_EDIT.equals(action)) { ra = new DropObjectPropStmt(entity.getURI(), VitroVocabulary.IND_MAIN_IMAGE, imageUri); } else if (imageUri != null) { @@ -157,7 +153,7 @@ public class ImageUploadController extends FreemarkerHttpServlet { return Actions.UNAUTHORIZED; } } - + /** *

* Parse the multi-part request, process the request, and produce the @@ -405,12 +401,12 @@ public class ImageUploadController extends FreemarkerHttpServlet { private TemplateResponseValues showAddImagePage(VitroRequest vreq, Individual entity) { - String placeholderUrl = vreq.getParameter(PARAMETER_PLACEHOLDER_URL); - String formAction = (entity == null) ? "" : formAction(entity.getURI(), - ACTION_UPLOAD, placeholderUrl); + ACTION_UPLOAD); String cancelUrl = (entity == null) ? "" : exitPageUrl(vreq, entity.getURI()); + String placeholderUrl = (entity == null) ? "" : UrlBuilder.getUrl(ImageUtil + .getPlaceholderImagePathForIndividual(vreq, entity.getURI())); TemplateResponseValues rv = new TemplateResponseValues(TEMPLATE_NEW); @@ -437,12 +433,11 @@ public class ImageUploadController extends FreemarkerHttpServlet { */ private TemplateResponseValues showReplaceImagePage(VitroRequest vreq, Individual entity, ImageInfo imageInfo) { - String placeholderUrl = vreq.getParameter(PARAMETER_PLACEHOLDER_URL); TemplateResponseValues rv = new TemplateResponseValues(TEMPLATE_REPLACE); rv.put(BODY_THUMBNAIL_URL, UrlBuilder.getUrl(imageInfo.getThumbnail() .getBytestreamAliasUrl())); - rv.put(BODY_DELETE_URL, formAction(entity.getURI(), ACTION_DELETE_EDIT, placeholderUrl)); - rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_UPLOAD, placeholderUrl)); + rv.put(BODY_DELETE_URL, formAction(entity.getURI(), ACTION_DELETE_EDIT)); + rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_UPLOAD)); rv.put(BODY_CANCEL_URL, exitPageUrl(vreq, entity.getURI())); rv.put(BODY_TITLE, "Replace image" + forName(entity)); rv.put(BODY_MAX_FILE_SIZE, MAXIMUM_FILE_SIZE / (1024 * 1024)); @@ -468,12 +463,11 @@ public class ImageUploadController extends FreemarkerHttpServlet { */ private TemplateResponseValues showCropImagePage(VitroRequest vreq, Individual entity, String imageUrl, Dimensions dimensions) { - String placeholderUrl = vreq.getParameter(PARAMETER_PLACEHOLDER_URL); TemplateResponseValues rv = new TemplateResponseValues(TEMPLATE_CROP); rv.put(BODY_MAIN_IMAGE_URL, UrlBuilder.getUrl(imageUrl)); rv.put(BODY_MAIN_IMAGE_HEIGHT, dimensions.height); rv.put(BODY_MAIN_IMAGE_WIDTH, dimensions.width); - rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_SAVE, placeholderUrl)); + rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_SAVE)); rv.put(BODY_CANCEL_URL, exitPageUrl(vreq, entity.getURI())); rv.put(BODY_TITLE, "Crop Photo" + forName(entity)); return rv; @@ -518,11 +512,9 @@ public class ImageUploadController extends FreemarkerHttpServlet { * back to this controller, along with the desired action and the Entity * URI. */ - private String formAction(String entityUri, String action, - String placeholderUrl) { - ParamMap params = new ParamMap( - PARAMETER_ENTITY_URI, entityUri, PARAMETER_ACTION, action, - PARAMETER_PLACEHOLDER_URL, placeholderUrl); + private String formAction(String entityUri, String action) { + ParamMap params = new ParamMap(PARAMETER_ENTITY_URI, entityUri, + PARAMETER_ACTION, action); return UrlBuilder.getPath(URL_HERE, params); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualPlaceholderImageUrlMethod.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualPlaceholderImageUrlMethod.java new file mode 100644 index 000000000..1be234797 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/methods/IndividualPlaceholderImageUrlMethod.java @@ -0,0 +1,57 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.web.methods; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; +import edu.cornell.mannlib.vitro.webapp.utils.ImageUtil; +import freemarker.core.Environment; +import freemarker.template.TemplateModelException; + +/** + * Get a URL for the placeholder image for this Individual, based on the VClass + * that the Individual belongs to. + */ +public class IndividualPlaceholderImageUrlMethod extends BaseTemplateMethodModel { + + @SuppressWarnings("rawtypes") + @Override + public String exec(List args) throws TemplateModelException { + if (args.size() != 1) { + throw new TemplateModelException("Wrong number of arguments"); + } + + String uri = (String) args.get(0); + Environment env = Environment.getCurrentEnvironment(); + HttpServletRequest request = (HttpServletRequest) env.getCustomAttribute("request"); + VitroRequest vreq = new VitroRequest(request); + String imageUrl = ImageUtil.getPlaceholderImagePathForIndividual(vreq, uri); + return UrlBuilder.getUrl(imageUrl); + } + + @Override + public Map help(String name) { + Map map = new LinkedHashMap(); + + map.put("return value", "The URL of the placeholder image for this individual, " + + "based on the VClasses that the individual belongs to."); + + Listparams = new ArrayList(); + params.add("Uri of individual"); + map.put("parameters", params); + + List examples = new ArrayList(); + examples.add(name + "(individual.uri)"); + map.put("examples", examples); + + return map; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java index de7e00178..b01efe97c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/BaseIndividualTemplateModel.java @@ -76,15 +76,11 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel { return UrlBuilder.getIndividualProfileUrl(individual, vreq); } - // For image, we use the default list view and Individual methods to reconstruct the image - // url from various triples. A custom list view would require that logic to be duplicated here. public String getImageUrl() { String imageUrl = individual.getImageUrl(); return imageUrl == null ? null : getUrl(imageUrl); } - // For image, we use the default list view and Individual methods to reconstruct the image - // url from various triples. A custom list view would require that logic to be duplicated here. public String getThumbUrl() { String thumbUrl = individual.getThumbUrl(); return thumbUrl == null ? null : getUrl(thumbUrl); diff --git a/webapp/web/templates/freemarker/body/individual/individual-vitro.ftl b/webapp/web/templates/freemarker/body/individual/individual-vitro.ftl index fced9a10d..007acbf6e 100644 --- a/webapp/web/templates/freemarker/body/individual/individual-vitro.ftl +++ b/webapp/web/templates/freemarker/body/individual/individual-vitro.ftl @@ -9,8 +9,7 @@ propertyGroups=propertyGroups namespaces=namespaces editable=editable - showPlaceholder="with_add_link" - placeholder="${urls.images}/placeholders/thumbnail.jpg" /> + showPlaceholder="with_add_link" /> <#if ( individualImage?contains(' diff --git a/webapp/web/templates/freemarker/lib/lib-properties.ftl b/webapp/web/templates/freemarker/lib/lib-properties.ftl index e6b0643d2..271473ff8 100644 --- a/webapp/web/templates/freemarker/lib/lib-properties.ftl +++ b/webapp/web/templates/freemarker/lib/lib-properties.ftl @@ -89,8 +89,8 @@ Assumes property is non-null. --> <#-- Some properties usually display without a label. But if there's an add link, we need to also show the property label. If no label is specified, the property name will be used as the label. --> -<#macro addLinkWithLabel property editable label="${property.name?capitalize}" extraParams=""> - <#local addLink><@addLink property editable label extraParams /> +<#macro addLinkWithLabel property editable label="${property.name?capitalize}"> + <#local addLink><@addLink property editable label /> <#local verboseDisplay><@verboseDisplay property /> <#-- Changed to display the label when user is in edit mode, even if there's no add link (due to displayLimitAnnot, for example). Otherwise the display looks odd, since neighboring @@ -104,24 +104,15 @@ name will be used as the label. --> -<#macro addLink property editable label="${property.name}" extraParams=""> +<#macro addLink property editable label="${property.name}"> <#if editable> <#local url = property.addUrl> <#if url?has_content> - <@showAddLink property.localName label addParamsToEditUrl(url, extraParams) /> + <@showAddLink property.localName label url /> -<#function addParamsToEditUrl url extraParams=""> - <#if extraParams?is_hash_ex> - <#list extraParams?keys as key> - <#local url = "${url}&${key}=${extraParams[key]?url}"> - - - <#return url> - - <#macro showAddLink propertyLocalName label url> add @@ -138,18 +129,18 @@ name will be used as the label. --> -<#macro editingLinks propertyLocalName statement editable extraParams=""> +<#macro editingLinks propertyLocalName statement editable> <#if editable> - <@editLink propertyLocalName statement extraParams /> - <@deleteLink propertyLocalName statement extraParams /> + <@editLink propertyLocalName statement /> + <@deleteLink propertyLocalName statement /> -<#macro editLink propertyLocalName statement extraParams=""> +<#macro editLink propertyLocalName statement> <#local url = statement.editUrl> <#if url?has_content> - <@showEditLink propertyLocalName addParamsToEditUrl(url, extraParams) /> + <@showEditLink propertyLocalName url /> @@ -157,10 +148,10 @@ name will be used as the label. --> edit -<#macro deleteLink propertyLocalName statement extraParams=""> +<#macro deleteLink propertyLocalName statement> <#local url = statement.deleteUrl> <#if url?has_content> - <@showDeleteLink propertyLocalName addParamsToEditUrl(url, extraParams) /> + <@showDeleteLink propertyLocalName url /> @@ -191,25 +182,21 @@ name will be used as the label. --> Note that this macro has a side-effect in the call to propertyGroups.pullProperty(). --> -<#macro image individual propertyGroups namespaces editable showPlaceholder="never" placeholder=""> +<#macro image individual propertyGroups namespaces editable showPlaceholder="never"> <#local mainImage = propertyGroups.pullProperty("${namespaces.vitroPublic}mainImage")!> - <#local extraParams = ""> - <#if placeholder?has_content> - <#local extraParams = { "placeholder" : placeholder } > - <#local thumbUrl = individual.thumbUrl!> <#-- Don't assume that if the mainImage property is populated, there is a thumbnail image (though that is the general case). If there's a mainImage statement but no thumbnail image, treat it as if there is no image. --> <#if (mainImage.statements)?has_content && thumbUrl?has_content> - ${individual.name} - <@editingLinks "${mainImage.localName}" mainImage.first() editable extraParams /> + + ${individual.name} + + <@editingLinks "${mainImage.localName}" mainImage.first() editable /> <#else> - <#local imageLabel><@addLinkWithLabel mainImage editable "Photo" extraParams /> + <#local imageLabel><@addLinkWithLabel mainImage editable "Photo" /> ${imageLabel} - <#if placeholder?has_content> - <#if showPlaceholder == "always" || (showPlaceholder="with_add_link" && imageLabel?has_content)> - placeholder image - + <#if showPlaceholder == "always" || (showPlaceholder="with_add_link" && imageLabel?has_content)> + placeholder image