NIHVIVO-3300 Placeholder images are configured by a properties file, which is loaded at startup.
This commit is contained in:
parent
a83b27a340
commit
19f47459e0
3 changed files with 21 additions and 69 deletions
|
@ -22,6 +22,8 @@ edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup
|
|||
|
||||
edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup
|
||||
|
||||
edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil$Setup
|
||||
|
||||
# Update the URIs on Permission Sets on UserAccounts from model (1.4) to 1.5.
|
||||
edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdatePermissionSetUris
|
||||
|
||||
|
|
19
productMods/images/placeholders/placeholders.properties
Normal file
19
productMods/images/placeholders/placeholders.properties
Normal file
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
# Assign placeholder images to classes of individuals.
|
||||
#
|
||||
# If showing an individual that has no image, a placeholder image may be shown.
|
||||
# By default, the placeholder is /images/placeholders/thumbnail.jpg. However,
|
||||
# this file allows you to associate classes with special placeholder images, and
|
||||
# if the individual belongs to such a class, the special placeholder is shown
|
||||
# instead of the default.
|
||||
#
|
||||
# EXAMPLE:
|
||||
# http\://xmlns.com/foaf/0.1/Person = /images/placeholders/person.thumbnail.jpg
|
||||
# means that any individual of type foaf:Person will be represented by
|
||||
# person.thumbnail.jpg
|
||||
#
|
||||
# NOTE: a colon is a special character in a properties file, and must be escaped
|
||||
# by a backslash.
|
||||
|
||||
http\://xmlns.com/foaf/0.1/Person = /images/placeholders/person.thumbnail.jpg
|
||||
http\://vitro.mannlib.cornell.edu/ns/vitro/authorization#UserAccount = /images/placeholders/person.thumbnail.jpg
|
|
@ -1,69 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
|
||||
/**
|
||||
* Some static methods that help in dealing with image files.
|
||||
*
|
||||
* So far, we only have methods that obtain the placeholder image for an
|
||||
* Individual that has no image of its own.
|
||||
*
|
||||
*/
|
||||
public class ImageUtil {
|
||||
private static final String DEFAULT_IMAGE_PATH = "/images/placeholders/thumbnail.jpg";
|
||||
|
||||
private static final Map<String, String> DEFAULT_IMAGE_PATHS_BY_TYPE = initImagePaths();
|
||||
|
||||
private static Map<String, String> initImagePaths() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("http://xmlns.com/foaf/0.1/Person",
|
||||
"/images/placeholders/person.thumbnail.jpg");
|
||||
map.put(VitroVocabulary.USERACCOUNT,
|
||||
"/images/placeholders/person.thumbnail.jpg");
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* If we have a placeholder image for this exact type, return it. Otherwise,
|
||||
* return the default.
|
||||
*/
|
||||
public static String getPlaceholderImagePathForType(String typeUri) {
|
||||
for (Entry<String, String> entry : DEFAULT_IMAGE_PATHS_BY_TYPE
|
||||
.entrySet()) {
|
||||
if (typeUri.equals(entry.getKey())) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return DEFAULT_IMAGE_PATH;
|
||||
}
|
||||
|
||||
/**
|
||||
* If there is a placeholder image for any type that this Individual
|
||||
* instantiates, return that image. Otherwise, return the default.
|
||||
*/
|
||||
public static String getPlaceholderImagePathForIndividual(
|
||||
VitroRequest vreq, String individualUri) {
|
||||
IndividualDao indDao = vreq.getWebappDaoFactory().getIndividualDao();
|
||||
for (Entry<String, String> entry : DEFAULT_IMAGE_PATHS_BY_TYPE
|
||||
.entrySet()) {
|
||||
if (indDao.isIndividualOfClass(entry.getKey(), individualUri)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return DEFAULT_IMAGE_PATH;
|
||||
}
|
||||
|
||||
/** Never need to instantiate this -- all methods are static. */
|
||||
private ImageUtil() {
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue