From ed63286789bea7f996895518a59a372591b49bca Mon Sep 17 00:00:00 2001 From: Bruno Nocera Zanette <brunonzanette@gmail.com> Date: Fri, 30 May 2014 23:00:40 -0300 Subject: [PATCH] Add Item's thumbnail to Item's desc on RSS Feed Add Item's thumbnail to Item's description on RSS Feed. --- .../org/dspace/app/util/SyndicationFeed.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/dspace/modules/additions/src/main/java/org/dspace/app/util/SyndicationFeed.java b/dspace/modules/additions/src/main/java/org/dspace/app/util/SyndicationFeed.java index eb88ff7..cf22fcb 100644 --- a/dspace/modules/additions/src/main/java/org/dspace/app/util/SyndicationFeed.java +++ b/dspace/modules/additions/src/main/java/org/dspace/app/util/SyndicationFeed.java @@ -8,6 +8,7 @@ package org.dspace.app.util; import java.io.IOException; +import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -28,6 +29,7 @@ import org.dspace.content.DSpaceObject; import org.dspace.content.Item; import org.dspace.core.ConfigurationManager; import org.dspace.core.Constants; +import org.dspace.core.Context; import org.dspace.handle.HandleManager; import com.sun.syndication.feed.synd.SyndFeed; @@ -53,6 +55,9 @@ import com.sun.syndication.io.FeedException; import org.apache.log4j.Logger; import org.dspace.content.Bundle; +import org.dspace.content.Thumbnail; +import org.dspace.content.service.ItemService; + /** * Invoke ROME library to assemble a generic model of a syndication * for the given list of Items and scope. Consults configuration for the @@ -158,6 +163,7 @@ public class SyndicationFeed { String logoURL = null; String objectURL = null; + String thumbnailURL = null; String defaultTitle = null; boolean podcastFeed = false; this.request = request; @@ -254,8 +260,18 @@ public class SyndicationFeed } // date of last change to Item entry.setUpdatedDate(item.getLastModified()); - + + //create StringBuffer to store item's description StringBuffer db = new StringBuffer(); + + //add item's thumbnail at begin of description + thumbnailURL = urlOfItemThumbnail(request, item); + if (thumbnailURL != null) + { + db.append("<img src=\""+thumbnailURL+"\" >"); + } + + //populate item's description for (String df : descriptionFields) { // Special Case: "(date)" in field name means render as date @@ -510,6 +526,20 @@ public class SyndicationFeed (uiType.equalsIgnoreCase(UITYPE_XMLUI) ?"/bitstream/id/":"/retrieve/") + logo.getID()+"/"+(name == null?"":name); } + + //returns absolute URL of Item's Thumbnail + private String urlOfItemThumbnail(HttpServletRequest request, Item item){ + try + { + Thumbnail thumbnail = ItemService.getThumbnail(new Context(), item.getID(), false); + return urlOfBitstream(request, thumbnail.getThumb()); + } + catch (SQLException e) + { + log.error("caught exception: ", e); + return null; + } + } /** * Return a url to the DSpace object, either use the official -- GitLab