diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java index 782f69b0a..30f7f3825 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/accounts/manageproxies/ManageProxiesListPage.java @@ -20,6 +20,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ProxyR import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.utils.ImageUtil; /** * TODO @@ -99,7 +101,7 @@ public class ManageProxiesListPage extends AbstractPageHandler { body.put("profileTypes", buildProfileTypesString()); body.put("formUrls", buildUrlsMap()); - + applyMessage(vreq, body); log.debug("body map is: " + body); @@ -115,28 +117,48 @@ public class ManageProxiesListPage extends AbstractPageHandler { ProxyRelationshipSelection selection) { List wrapped = new ArrayList(); for (ProxyRelationship r : selection.getProxyRelationships()) { - wrapped.add(new ProxyRelationship(wrapItemList(r.getProxyInfos()), - wrapItemList(r.getProfileInfos()))); + wrapped.add(new ProxyRelationship(wrapProxyItemList(r + .getProxyInfos()), wrapProfileItemList(r.getProfileInfos()))); } return wrapped; } - private List wrapItemList(List items) { + private List wrapProxyItemList(List items) { List wrapped = new ArrayList(); for (ProxyItemInfo item : items) { - wrapped.add(wrapItem(item)); + wrapped.add(wrapProxyItem(item)); } return wrapped; } - private ProxyItemInfo wrapItem(ProxyItemInfo item) { - if (item.getImageUrl().isEmpty()) { - return new ProxyItemInfo(item.getUri(), item.getLabel(), - item.getClassLabel(), DEFAULT_IMAGE_URL); - } else { - return new ProxyItemInfo(item.getUri(), item.getLabel(), - item.getClassLabel(), UrlBuilder.getUrl(item.getImageUrl())); + private List wrapProfileItemList(List items) { + List wrapped = new ArrayList(); + for (ProxyItemInfo item : items) { + wrapped.add(wrapProfileItem(item)); } + return wrapped; + } + + private ProxyItemInfo wrapProxyItem(ProxyItemInfo item) { + String imagePath = item.getImageUrl(); + if (imagePath.isEmpty()) { + imagePath = ImageUtil + .getPlaceholderImagePathForType(VitroVocabulary.USERACCOUNT); + } + + return new ProxyItemWrapper(item.getUri(), item.getLabel(), + item.getClassLabel(), UrlBuilder.getUrl(imagePath)); + } + + private ProxyItemInfo wrapProfileItem(ProxyItemInfo item) { + String imagePath = item.getImageUrl(); + if (imagePath.isEmpty()) { + imagePath = ImageUtil + .getPlaceholderImagePathForIndividual(vreq, item.getUri()); + } + + return new ProfileItemWrapper(item.getUri(), item.getLabel(), + item.getClassLabel(), UrlBuilder.getUrl(imagePath)); } private Map buildPageMap( @@ -175,4 +197,17 @@ public class ManageProxiesListPage extends AbstractPageHandler { return map; } + private static class ProxyItemWrapper extends ProxyItemInfo { + public ProxyItemWrapper(String uri, String label, String classLabel, + String imageUrl) { + super(uri, label, classLabel, imageUrl); + } + } + + private static class ProfileItemWrapper extends ProxyItemInfo { + public ProfileItemWrapper(String uri, String label, String classLabel, + String imageUrl) { + super(uri, label, classLabel, imageUrl); + } + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ImageUtil.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ImageUtil.java new file mode 100644 index 000000000..54ee2d4da --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/ImageUtil.java @@ -0,0 +1,61 @@ +/* $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; + +/** + * Some static methods that help in dealing with image files. + */ +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(); + // No images other than the default. + 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 + } +}