diff --git a/dspace-api/src/main/java/org/dspace/browse/Thumbnail.java b/dspace-api/src/main/java/org/dspace/content/Thumbnail.java
similarity index 98%
rename from dspace-api/src/main/java/org/dspace/browse/Thumbnail.java
rename to dspace-api/src/main/java/org/dspace/content/Thumbnail.java
index c6e4ed139b..8c842ad6c5 100644
--- a/dspace-api/src/main/java/org/dspace/browse/Thumbnail.java
+++ b/dspace-api/src/main/java/org/dspace/content/Thumbnail.java
@@ -33,7 +33,7 @@
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
-package org.dspace.browse;
+package org.dspace.content;
import org.dspace.content.Bitstream;
@@ -96,5 +96,5 @@ public class Thumbnail
this.thumb = thumb;
}
-
+
}
diff --git a/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java
new file mode 100644
index 0000000000..6c05eb71e5
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java
@@ -0,0 +1,22 @@
+package org.dspace.content.dao;
+
+import org.dspace.core.Context;
+import org.dspace.content.Bitstream;
+
+import java.sql.SQLException;
+
+public abstract class ItemDAO
+{
+ protected Context context;
+
+ protected ItemDAO(Context ctx)
+ {
+ context = ctx;
+ }
+
+ public abstract Bitstream getPrimaryBitstream(int itemId, String bundleName) throws SQLException;
+
+ public abstract Bitstream getFirstBitstream(int itemId, String bundleName) throws SQLException;
+
+ public abstract Bitstream getNamedBitstream(int itemId, String bundleName, String fileName) throws SQLException;
+}
diff --git a/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOFactory.java b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOFactory.java
new file mode 100644
index 0000000000..0a68900129
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOFactory.java
@@ -0,0 +1,24 @@
+package org.dspace.content.dao;
+
+import org.dspace.core.Context;
+import org.dspace.core.ConfigurationManager;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Graham
+ * Date: 19-Dec-2007
+ * Time: 13:13:51
+ * To change this template use File | Settings | File Templates.
+ */
+public class ItemDAOFactory
+{
+ public static ItemDAO getInstance(Context context)
+ {
+ if (ConfigurationManager.getProperty("db.name").equalsIgnoreCase("oracle"))
+ {
+ return new ItemDAOOracle(context);
+ }
+
+ return new ItemDAOPostgres(context);
+ }
+}
diff --git a/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOOracle.java b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOOracle.java
new file mode 100644
index 0000000000..e560f5ca25
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOOracle.java
@@ -0,0 +1,26 @@
+package org.dspace.content.dao;
+
+import org.dspace.core.Context;
+import org.dspace.content.Bitstream;
+
+import java.sql.SQLException;
+
+public class ItemDAOOracle extends ItemDAO
+{
+ ItemDAOOracle(Context ctx)
+ {
+ super(ctx);
+ }
+
+ public Bitstream getPrimaryBitstream(int itemId, String bundleName) throws SQLException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Bitstream getFirstBitstream(int itemId, String bundleName) throws SQLException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Bitstream getNamedBitstream(int itemId, String bundleName, String fileName) throws SQLException {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
diff --git a/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOPostgres.java b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOPostgres.java
new file mode 100644
index 0000000000..659b6b613d
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/content/dao/ItemDAOPostgres.java
@@ -0,0 +1,116 @@
+package org.dspace.content.dao;
+
+import org.dspace.core.Context;
+import org.dspace.content.Bitstream;
+import org.dspace.storage.rdbms.DatabaseManager;
+import org.dspace.storage.rdbms.TableRowIterator;
+import org.dspace.storage.rdbms.TableRow;
+
+import java.sql.SQLException;
+
+public class ItemDAOPostgres extends ItemDAO
+{
+ private final String selectPrimaryBitstreamID =
+ "SELECT bundle.primary_bitstream_id FROM item2bundle, bundle " +
+ "WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? LIMIT 1";
+
+ private final String selectFirstBitstreamID =
+ "SELECT bundle2bitstream.bitstream_id FROM item2bundle, bundle, bundle2bitstream " +
+ "WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? " +
+ "AND bundle.bundle_id=bundle2bitstream.bundle_id LIMIT 1";
+
+// private final String selectFirstBitstreamID =
+// "SELECT bitstream.bitstream_id FROM item2bundle, bundle, bundle2bitstream, bitstream " +
+// "WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? " +
+// "AND bundle.bundle_id=bundle2bitstream.bundle_id AND bundle2bitstream.bitstream_id=bitstream.bitstream_id " +
+// " LIMIT 1";
+
+// private final String selectFirstBitstreamID =
+// "SELECT bitstream_id FROM (" +
+// "SELECT bitstream.bitstream_id FROM item2bundle, bundle, bundle2bitstream, bitstream " +
+// "WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? " +
+// "AND bundle.bundle_id=bundle2bitstream.bundle_id AND bundle2bitstream.bitstream_id=bitstream.bitstream_id " +
+// "ORDER BY bitstream.sequence_id" +
+// ") allstreams LIMIT 1";
+
+ private final String selectNamedBitstreamID =
+ "SELECT bitstream.bitstream_id FROM item2bundle, bundle, bundle2bitstream, bitstream " +
+ "WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? " +
+ "AND bundle.bundle_id=bundle2bitstream.bundle_id AND bundle2bitstream.bitstream_id=bitstream.bitstream_id " +
+ "AND bitstream.name=?";
+
+ ItemDAOPostgres(Context ctx)
+ {
+ super(ctx);
+ }
+
+ public Bitstream getPrimaryBitstream(int itemId, String bundleName) throws SQLException
+ {
+ TableRowIterator tri = null;
+
+ try
+ {
+ tri = DatabaseManager.query(context, selectPrimaryBitstreamID, itemId, bundleName);
+
+ if (tri.hasNext())
+ {
+ TableRow row = tri.next();
+ int bid = row.getIntColumn("primary_bitstream_id");
+ return Bitstream.find(context, bid);
+ }
+ }
+ finally
+ {
+ if (tri != null)
+ tri.close();
+ }
+
+ return null;
+ }
+
+ public Bitstream getFirstBitstream(int itemId, String bundleName) throws SQLException
+ {
+ TableRowIterator tri = null;
+
+ try
+ {
+ tri = DatabaseManager.query(context, selectFirstBitstreamID, itemId, bundleName);
+ if (tri.hasNext())
+ {
+ TableRow row = tri.next();
+ int bid = row.getIntColumn("bitstream_id");
+ return Bitstream.find(context, bid);
+ }
+ }
+ finally
+ {
+ if (tri != null)
+ tri.close();
+ }
+
+ return null;
+ }
+
+ public Bitstream getNamedBitstream(int itemId, String bundleName, String fileName) throws SQLException
+ {
+ TableRowIterator tri = null;
+
+ try
+ {
+ tri = DatabaseManager.query(context, selectNamedBitstreamID, itemId, bundleName, fileName);
+ if (tri.hasNext())
+ {
+ TableRow row = tri.next();
+ int bid = row.getIntColumn("bitstream_id");
+ return Bitstream.find(context, bid);
+ }
+ }
+ finally
+ {
+ if (tri != null)
+ tri.close();
+ }
+
+ return null;
+ }
+}
diff --git a/dspace-api/src/main/java/org/dspace/content/service/ItemService.java b/dspace-api/src/main/java/org/dspace/content/service/ItemService.java
new file mode 100644
index 0000000000..cd39637209
--- /dev/null
+++ b/dspace-api/src/main/java/org/dspace/content/service/ItemService.java
@@ -0,0 +1,39 @@
+package org.dspace.content.service;
+
+import org.dspace.content.dao.ItemDAO;
+import org.dspace.content.dao.ItemDAOFactory;
+import org.dspace.content.Bitstream;
+import org.dspace.content.Thumbnail;
+import org.dspace.core.Context;
+
+import java.sql.SQLException;
+
+public class ItemService
+{
+ public static Thumbnail getThumbnail(Context context, int itemId, boolean requireOriginal) throws SQLException
+ {
+ ItemDAO dao = ItemDAOFactory.getInstance(context);
+
+ Bitstream thumbBitstream = null;
+ Bitstream primaryBitstream = dao.getPrimaryBitstream(itemId, "ORIGINAL");
+ if (primaryBitstream != null)
+ {
+ if (primaryBitstream.getFormat().getMIMEType().equals("text/html"))
+ return null;
+
+ thumbBitstream = dao.getNamedBitstream(itemId, "THUMBNAIL", primaryBitstream.getName() + ".jpg");
+ }
+ else
+ {
+ if (requireOriginal)
+ primaryBitstream = dao.getFirstBitstream(itemId, "ORIGINAL");
+
+ thumbBitstream = dao.getFirstBitstream(itemId, "THUMBNAIL");
+ }
+
+ if (thumbBitstream != null)
+ return new Thumbnail(thumbBitstream, primaryBitstream);
+
+ return null;
+ }
+}
diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java b/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java
index e480717571..1b53cb2815 100644
--- a/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java
+++ b/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/BrowseListTag.java
@@ -46,6 +46,8 @@ import org.dspace.content.Bitstream;
import org.dspace.content.DCDate;
import org.dspace.content.DCValue;
import org.dspace.content.Item;
+import org.dspace.content.Thumbnail;
+import org.dspace.content.service.ItemService;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
@@ -743,9 +745,10 @@ public class BrowseListTag extends TagSupport
{
try
{
- Thumbnail thumbnail = item.getThumbnail();
-
- if (thumbnail == null)
+ Context c = UIUtil.obtainContext(hrq);
+ Thumbnail thumbnail = ItemService.getThumbnail(c, item.getID(), linkToBitstream);
+
+ if (thumbnail == null)
{
return "";
}
@@ -768,7 +771,13 @@ public class BrowseListTag extends TagSupport
String img = hrq.getContextPath() + "/retrieve/" + thumb.getID() + "/" +
UIUtil.encodeBitstreamName(thumb.getName(), Constants.DEFAULT_ENCODING);
String alt = thumb.getName();
- thumbFrag.append("
");
+ String scAttr = getScalingAttr(hrq, thumb);
+ thumbFrag.append("
");
return thumbFrag.toString();
}
diff --git a/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/ItemListTag.java b/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/ItemListTag.java
index e070f9de3e..e848d24b40 100644
--- a/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/ItemListTag.java
+++ b/dspace-jspui/src/main/java/org/dspace/app/webui/jsptag/ItemListTag.java
@@ -48,6 +48,8 @@ import org.dspace.content.Bundle;
import org.dspace.content.DCDate;
import org.dspace.content.DCValue;
import org.dspace.content.Item;
+import org.dspace.content.Thumbnail;
+import org.dspace.content.service.ItemService;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
@@ -524,118 +526,51 @@ public class ItemListTag extends TagSupport
private String getThumbMarkup(HttpServletRequest hrq, Item item)
throws JspException
{
- Bundle[] original = null;
-
try
{
- original = item.getBundles("ORIGINAL");
- }
- catch(SQLException sqle)
- {
- throw new JspException(sqle.getMessage());
- }
+ Context c = UIUtil.obtainContext(hrq);
+ Thumbnail thumbnail = ItemService.getThumbnail(c, item.getID(), linkToBitstream);
- if (original.length == 0)
- {
- return "";
- }
-
- boolean html = false;
-
- // if multiple bitstreams, check if the primary one is HTML
- if (original[0].getBitstreams().length > 1)
- {
- Bitstream[] bitstreams = original[0].getBitstreams();
-
- for (int i = 0; (i < bitstreams.length) && !html; i++)
+ if (thumbnail == null)
{
- if (bitstreams[i].getID() == original[0]
- .getPrimaryBitstreamID())
- {
- html = bitstreams[i].getFormat().getMIMEType().equals(
- "text/html");
- }
+ return "";
}
- }
+ StringBuffer thumbFrag = new StringBuffer();
- try
- {
- Bundle[] thumbs = item.getBundles("THUMBNAIL");
-
- // if there are thumbs and we're not dealing with an HTML item
- // then show the thumbnail
- if ((thumbs.length > 0) && !html)
- {
- Context c = UIUtil.obtainContext(hrq);
-
- Bitstream thumbnailBitstream;
- Bitstream originalBitstream;
-
- if ((original[0].getBitstreams().length > 1)
- && (original[0].getPrimaryBitstreamID() > -1))
- {
- originalBitstream = Bitstream.find(c, original[0]
- .getPrimaryBitstreamID());
- thumbnailBitstream = thumbs[0]
- .getBitstreamByName(originalBitstream.getName()
- + ".jpg");
- }
- else
- {
- originalBitstream = original[0].getBitstreams()[0];
- thumbnailBitstream = thumbs[0].getBitstreams()[0];
- }
-
- if ((thumbnailBitstream != null)
- && (AuthorizeManager.authorizeActionBoolean(c,
- thumbnailBitstream, Constants.READ)))
- {
- StringBuffer thumbLink;
-
- if (linkToBitstream)
- {
- thumbLink = new StringBuffer(
- "
");
-
- return thumbLink.toString();
- }
+ if (linkToBitstream)
+ {
+ Bitstream original = thumbnail.getOriginal();
+ String link = hrq.getContextPath() + "/bitstream/" + item.getHandle() + "/" + original.getSequenceID() + "/" +
+ UIUtil.encodeBitstreamName(original.getName(), Constants.DEFAULT_ENCODING);
+ thumbFrag.append("");
}
+ else
+ {
+ String link = hrq.getContextPath() + "/handle/" + item.getHandle();
+ thumbFrag.append("");
+ }
+
+ Bitstream thumb = thumbnail.getThumb();
+ String img = hrq.getContextPath() + "/retrieve/" + thumb.getID() + "/" +
+ UIUtil.encodeBitstreamName(thumb.getName(), Constants.DEFAULT_ENCODING);
+ String alt = thumb.getName();
+ String scAttr = getScalingAttr(hrq, thumb);
+ thumbFrag.append("
");
+
+ return thumbFrag.toString();
}
catch (SQLException sqle)
{
- throw new JspException(sqle.getMessage());
+ throw new JspException(sqle.getMessage());
}
catch (UnsupportedEncodingException e)
{
- throw new JspException(
- "Server does not support DSpace's default encoding. ",
- e);
+ throw new JspException("Server does not support DSpace's default encoding. ", e);
}
-
- return "";
}
}