From 19f47459e09087f7377f1d074f3a7f65c6d4227d Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 22 Mar 2012 20:10:13 +0000 Subject: [PATCH] NIHVIVO-3300 Placeholder images are configured by a properties file, which is loaded at startup. --- .../WEB-INF/resources/startup_listeners.txt | 2 + .../placeholders/placeholders.properties | 19 +++++ .../mannlib/vitro/webapp/utils/ImageUtil.java | 69 ------------------- 3 files changed, 21 insertions(+), 69 deletions(-) create mode 100644 productMods/images/placeholders/placeholders.properties delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/utils/ImageUtil.java diff --git a/productMods/WEB-INF/resources/startup_listeners.txt b/productMods/WEB-INF/resources/startup_listeners.txt index bf670009..8c0fcd9a 100644 --- a/productMods/WEB-INF/resources/startup_listeners.txt +++ b/productMods/WEB-INF/resources/startup_listeners.txt @@ -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 diff --git a/productMods/images/placeholders/placeholders.properties b/productMods/images/placeholders/placeholders.properties new file mode 100644 index 00000000..32168afd --- /dev/null +++ b/productMods/images/placeholders/placeholders.properties @@ -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 diff --git a/src/edu/cornell/mannlib/vitro/webapp/utils/ImageUtil.java b/src/edu/cornell/mannlib/vitro/webapp/utils/ImageUtil.java deleted file mode 100644 index a17e96c8..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/utils/ImageUtil.java +++ /dev/null @@ -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 DEFAULT_IMAGE_PATHS_BY_TYPE = initImagePaths(); - - private static Map initImagePaths() { - Map map = new HashMap(); - 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 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 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 - } -}