+ * /bitstream/handle/sequence_id/filename
+ *
+ * @author Robert Tansley
+ * @version $Revision$
+ */
+public class BitstreamServlet extends DSpaceServlet
+{
+ /** log4j category */
+ private static Logger log = Logger.getLogger(RetrieveServlet.class);
+
+
+ protected void doDSGet(Context context,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws ServletException, IOException, SQLException, AuthorizeException
+ {
+ Bitstream bitstream = null;
+
+ // Get the ID from the URL
+ String idString = request.getPathInfo();
+ String handle = "";
+ String sequence = "";
+
+ if (idString != null)
+ {
+ // Remove leading slash
+ if (idString.startsWith("/"))
+ {
+ idString = idString.substring(1);
+ }
+
+ // Remove last slash and filename after it
+ int slashIndex = idString.lastIndexOf('/');
+ if (slashIndex != -1)
+ {
+ idString = idString.substring(0, slashIndex);
+ }
+
+ // Get bitstream sequence ID
+ slashIndex = idString.lastIndexOf('/');
+ if (slashIndex != -1)
+ {
+ sequence = idString.substring(slashIndex + 1);
+ handle = idString.substring(0, slashIndex);
+ }
+
+
+ // Find the corresponding bitstream
+ try
+ {
+
+ Item item = (Item) HandleManager.resolveToObject(context, handle);
+
+ if (item == null)
+ {
+ log.info(LogManager.getHeader(context,
+ "invalid_id",
+ "path=" + handle));
+ JSPManager.showInvalidIDError(request, response, handle, -1);
+ return;
+ }
+
+ int sid = Integer.parseInt(sequence);
+ boolean found = false;
+
+ Bundle[] bundles = item.getBundles();
+ for (int i = 0; i < bundles.length && !found; i++)
+ {
+ Bitstream[] bitstreams = bundles[i].getBitstreams();
+ for (int k = 0; k < bitstreams.length && !found; k++)
+ {
+ if (sid == bitstreams[k].getSequenceID())
+ {
+ bitstream = bitstreams[k];
+ found = true;
+ }
+ }
+ }
+ }
+ catch (NumberFormatException nfe)
+ {
+ // Invalid ID - this will be dealt with below
+ }
+ }
+
+ // Did we get a bitstream?
+ if (bitstream != null)
+ {
+ log.info(LogManager.getHeader(context,
+ "view_bitstream",
+ "bitstream_id=" + bitstream.getID()));
+
+ // Set the response MIME type
+ response.setContentType(bitstream.getFormat().getMIMEType());
+
+ // Response length
+ response.setHeader("Content-Length",
+ String.valueOf(bitstream.getSize()));
+
+ // Pipe the bits
+ InputStream is = bitstream.retrieve();
+
+ Utils.bufferedCopy(is, response.getOutputStream());
+ is.close();
+ response.getOutputStream().flush();
+ }
+ else
+ {
+ // No bitstream - we got an invalid ID
+ log.info(LogManager.getHeader(context,
+ "view_bitstream",
+ "invalid_bitstream_id=" + idString));
+
+ JSPManager.showInvalidIDError(request,
+ response,
+ idString,
+ Constants.BITSTREAM);
+ }
+ }
+}
diff --git a/dspace/src/org/dspace/app/webui/servlet/HTMLServlet.java b/dspace/src/org/dspace/app/webui/servlet/HTMLServlet.java
index 9072f20052..e958f65e72 100644
--- a/dspace/src/org/dspace/app/webui/servlet/HTMLServlet.java
+++ b/dspace/src/org/dspace/app/webui/servlet/HTMLServlet.java
@@ -1,5 +1,5 @@
/*
- * RetrieveServlet.java
+ * HTMLServlet.java
*
* Version: $Revision$
*
@@ -146,7 +146,6 @@ public class HTMLServlet extends DSpaceServlet
}
}
- //bitstream = Bitstream.find(context, id);
}
catch (NumberFormatException nfe)
{
diff --git a/dspace/src/org/dspace/content/Bitstream.java b/dspace/src/org/dspace/content/Bitstream.java
index 44ca527ff1..9e21030d57 100644
--- a/dspace/src/org/dspace/content/Bitstream.java
+++ b/dspace/src/org/dspace/content/Bitstream.java
@@ -214,6 +214,28 @@ public class Bitstream extends DSpaceObject
}
+ /**
+ * Get the sequence ID of this bitstream
+ *
+ * @return the sequence ID
+ */
+ public int getSequenceID()
+ {
+ return bRow.getIntColumn("sequence_id");
+ }
+
+
+ /**
+ * Set the sequence ID of this bitstream
+ *
+ * @param sid the ID
+ */
+ public void setSequenceID(int sid)
+ {
+ bRow.setColumn("sequence_id", sid);
+ }
+
+
/**
* Get the name of this bitstream - typically the filename, without
* any path information
diff --git a/dspace/src/org/dspace/content/Item.java b/dspace/src/org/dspace/content/Item.java
index a6f8613a87..e3ff0b6d51 100644
--- a/dspace/src/org/dspace/content/Item.java
+++ b/dspace/src/org/dspace/content/Item.java
@@ -1107,6 +1107,39 @@ public class Item extends DSpaceObject
// Set the last modified date
itemRow.setColumn("last_modified", new Date());
+ // Set sequence IDs for bitstreams in item
+ int sequence = 0;
+ Bundle[] bunds = getBundles();
+
+ // find the highest current sequence number
+ for (int i = 0; i < bunds.length; i++)
+ {
+ Bitstream[] streams = bunds[i].getBitstreams();
+ for (int k = 0; k < streams.length; k++)
+ {
+ if (streams[k].getSequenceID() > sequence)
+ {
+ sequence = streams[k].getSequenceID();
+ }
+ }
+ }
+
+ // start sequencing bitstreams without sequence IDs
+ sequence++;
+ for (int i = 0; i < bunds.length; i++)
+ {
+ Bitstream[] streams = bunds[i].getBitstreams();
+ for (int k = 0; k < streams.length; k++)
+ {
+ if (streams[k].getSequenceID() < 0)
+ {
+ streams[k].setSequenceID(sequence);
+ sequence++;
+ streams[k].update();
+ }
+ }
+ }
+
// Make sure that withdrawn and in_archive are non-null
if (itemRow.isColumnNull("in_archive"))
{