diff --git a/dspace/etc/database_schema.sql b/dspace/etc/database_schema.sql index d689d793b5..dae92fbe3e 100644 --- a/dspace/etc/database_schema.sql +++ b/dspace/etc/database_schema.sql @@ -202,7 +202,8 @@ CREATE TABLE Bundle ( bundle_id INTEGER PRIMARY KEY, mets_bitstream_id INTEGER REFERENCES Bitstream(bitstream_id), - name VARCHAR(16) -- ORIGINAL | THUMBNAIL | TEXT + name VARCHAR(16) -- ORIGINAL | THUMBNAIL | TEXT, + primary_bitstream_id INTEGER REFERENCES Bitstream(bitstream_id) ); ------------------------------------------------------- diff --git a/dspace/etc/dspace-web.xml b/dspace/etc/dspace-web.xml index f91fa06f4f..2ce2a1a1c8 100644 --- a/dspace/etc/dspace-web.xml +++ b/dspace/etc/dspace-web.xml @@ -260,6 +260,11 @@ + + html + org.dspace.app.webui.servlet.HTMLServlet + + retrieve org.dspace.app.webui.servlet.RetrieveServlet @@ -408,6 +413,11 @@ /register + + html + /html/* + + retrieve /retrieve/* diff --git a/dspace/jsp/submit/upload-file-list.jsp b/dspace/jsp/submit/upload-file-list.jsp index 20ab26665a..85bfe96414 100644 --- a/dspace/jsp/submit/upload-file-list.jsp +++ b/dspace/jsp/submit/upload-file-list.jsp @@ -57,6 +57,7 @@ <%@ page import="org.dspace.app.webui.util.SubmissionInfo" %> <%@ page import="org.dspace.content.Bitstream" %> <%@ page import="org.dspace.content.BitstreamFormat" %> +<%@ page import="org.dspace.content.Bundle" %> <%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %> @@ -69,7 +70,7 @@ boolean showChecksums = ((Boolean) request.getAttribute("show.checksums")).booleanValue(); %> - + @@ -92,6 +93,7 @@ + Primarybitstream File Size Description @@ -120,6 +122,11 @@ String row = "even"; Bitstream[] bitstreams = si.submission.getItem().getNonInternalBitstreams(); + Bundle[] bundles = null; + + if (bitstreams[0] != null) { + bundles = bitstreams[0].getBundles(); + } for (int i = 0; i < bitstreams.length; i++) { @@ -141,6 +148,14 @@ String supportLevelLink = "/help/formats.html#" + supportLevel; %> + + + <% if (bundles[0] != null) { + if (bundles[0].getPrimaryBitstreamID() == bitstreams[i].getID()) { %> + <%="checked" %> + <% } + } %> > + <%= bitstreams[i].getName() %> <%= bitstreams[i].getSize() %> bytes diff --git a/dspace/lib/commons-collections.jar b/dspace/lib/commons-collections.jar index 5cc4f90624..6f2c19103c 100644 Binary files a/dspace/lib/commons-collections.jar and b/dspace/lib/commons-collections.jar differ diff --git a/dspace/lib/commons-dbcp.jar b/dspace/lib/commons-dbcp.jar index c3c4d1f2ab..22ce41a1f5 100644 Binary files a/dspace/lib/commons-dbcp.jar and b/dspace/lib/commons-dbcp.jar differ diff --git a/dspace/lib/commons-pool.jar b/dspace/lib/commons-pool.jar index c61bde6c9b..8374f8c809 100644 Binary files a/dspace/lib/commons-pool.jar and b/dspace/lib/commons-pool.jar differ diff --git a/dspace/lib/handle.jar b/dspace/lib/handle.jar index 165224cb36..c41dce2ad1 100755 Binary files a/dspace/lib/handle.jar and b/dspace/lib/handle.jar differ diff --git a/dspace/lib/log4j.jar b/dspace/lib/log4j.jar index 493a3ccc13..4a792a256e 100644 Binary files a/dspace/lib/log4j.jar and b/dspace/lib/log4j.jar differ diff --git a/dspace/lib/lucene.jar b/dspace/lib/lucene.jar index c3675227a1..ff9b90061b 100644 Binary files a/dspace/lib/lucene.jar and b/dspace/lib/lucene.jar differ diff --git a/dspace/lib/oaicat.jar b/dspace/lib/oaicat.jar index aeb1877114..94eb82392c 100644 Binary files a/dspace/lib/oaicat.jar and b/dspace/lib/oaicat.jar differ diff --git a/dspace/lib/oro.jar b/dspace/lib/oro.jar index 23488d2600..346504c6d4 100644 Binary files a/dspace/lib/oro.jar and b/dspace/lib/oro.jar differ diff --git a/dspace/src/org/dspace/app/webui/jsptag/ItemTag.java b/dspace/src/org/dspace/app/webui/jsptag/ItemTag.java index c83c75aa2c..77a3a0bbdc 100644 --- a/dspace/src/org/dspace/app/webui/jsptag/ItemTag.java +++ b/dspace/src/org/dspace/app/webui/jsptag/ItemTag.java @@ -440,6 +440,23 @@ public class ItemTag extends TagSupport { // if item contains multiple non-license bundles, display bitstream description boolean multiFile = (bundles.length > 2); + boolean html = false; + Bitstream primaryBitstream = null; + + // check if primary bitstream is html + Bundle[] bunds = item.getBundles("ORIGINAL"); + if (bunds[0] != null) + { + Bitstream[] bits = bunds[0].getBitstreams(); + for (int i = 0; i < bits.length && !html; i++) + { + if (bits[i].getID() == bunds[0].getPrimaryBitstreamID()) + { + html = bits[i].getFormat().getMIMEType().equals("text/html"); + primaryBitstream = bits[i]; + } + } + } out.println("File"); if (multiFile) @@ -447,40 +464,66 @@ public class ItemTag extends TagSupport out.println("Description"); } out.println("SizeFormat"); - - for (int i = 0; i < bundles.length; i++) - { - Bitstream[] bitstreams = bundles[i].getBitstreams(); - for (int k = 0; k < bitstreams.length ; k++) - { - // Skip internal types - if (!bitstreams[k].getFormat().isInternal()) - { - out.print(""); - out.print(bitstreams[k].getName()); - if (multiFile) + // if primary bitstream is html, display a link for only that one to HTMLServlet + if (html) + { + out.print(""); + out.print(primaryBitstream.getName()); + if (multiFile) + { + out.print(""); + String desc = primaryBitstream.getDescription(); + out.print(desc != null ? desc : ""); + } + out.print(""); + out.print(primaryBitstream.getSize() / 1024); + out.print("Kb"); + out.print(primaryBitstream.getFormatDescription()); + out.print("View/Open"); + } + else + { + for (int i = 0; i < bundles.length; i++) + { + Bitstream[] bitstreams = bundles[i].getBitstreams(); + + for (int k = 0; k < bitstreams.length ; k++) + { + // Skip internal types + if (!bitstreams[k].getFormat().isInternal()) { + out.print(""); + out.print(bitstreams[k].getName()); + if (multiFile) + { + out.print(""); + String desc = bitstreams[k].getDescription(); + out.print(desc != null ? desc : ""); + } out.print(""); - String desc = bitstreams[k].getDescription(); - out.print(desc != null ? desc : ""); + out.print(bitstreams[k].getSize() / 1024); + out.print("Kb"); + out.print(bitstreams[k].getFormatDescription()); + out.print("View/Open"); } - out.print(""); - out.print(bitstreams[k].getSize() / 1024); - out.print("Kb"); - out.print(bitstreams[k].getFormatDescription()); - out.print("View/Open"); - } - } - } + } + } + } out.println(""); } out.println(""); } } + diff --git a/dspace/src/org/dspace/app/webui/servlet/HTMLServlet.java b/dspace/src/org/dspace/app/webui/servlet/HTMLServlet.java new file mode 100644 index 0000000000..9072f20052 --- /dev/null +++ b/dspace/src/org/dspace/app/webui/servlet/HTMLServlet.java @@ -0,0 +1,196 @@ +/* + * RetrieveServlet.java + * + * Version: $Revision$ + * + * Date: $Date$ + * + * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts + * Institute of Technology. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of the Hewlett-Packard Company nor the name of the + * Massachusetts Institute of Technology nor the names of their + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +package org.dspace.app.webui.servlet; + +import java.io.InputStream; +import java.io.IOException; +import java.net.URLDecoder; +import java.sql.SQLException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import org.dspace.app.webui.util.JSPManager; +import org.dspace.authorize.AuthorizeException; +import org.dspace.authorize.AuthorizeManager; +import org.dspace.content.Bitstream; +import org.dspace.content.Bundle; +import org.dspace.content.Item; +import org.dspace.core.Constants; +import org.dspace.core.Context; +import org.dspace.core.LogManager; +import org.dspace.core.Utils; +import org.dspace.handle.HandleManager; + +/** + * Servlet for HTML bitstream support. + * + * /html/handle/filename + * + * @author Robert Tansley + * @version $Revision$ + */ +public class HTMLServlet extends DSpaceServlet +{ + /** log4j category */ + private static Logger log = Logger.getLogger(HTMLServlet.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 filename = ""; + String handle = ""; + + if (idString != null) + { + + // Remove leading slash + if (idString.startsWith("/")) + { + idString = idString.substring(1); + } + + // Get filename + int slashIndex = idString.lastIndexOf('/'); + if (slashIndex != -1) + { + filename = idString.substring(slashIndex + 1); + filename = URLDecoder.decode(filename); + handle = idString.substring(0, slashIndex); + } + + // If there's still a second slash, remove it and anything after it, + // it might be a relative directory name + slashIndex = handle.indexOf('/'); + slashIndex = handle.indexOf('/', slashIndex + 1); + if (slashIndex != -1) + { + handle = handle.substring(0, slashIndex); + } + + + // Find the corresponding bitstream + try + { + boolean found = false; + + 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; + } + + Bundle[] bundles = item.getBundles(); + for (int i = 0; i < bundles.length; i++) { + Bitstream[] bitstreams = bundles[i].getBitstreams(); + if (!found) { + for (int k = 0; k < bitstreams.length; k++) { + if (filename.equals(bitstreams[k].getName())) { + bitstream = bitstreams[k]; + found = true; + } + } + } + } + + //bitstream = Bitstream.find(context, id); + } + 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/SubmitServlet.java b/dspace/src/org/dspace/app/webui/servlet/SubmitServlet.java index 71ce1edfe4..f0e40e1345 100644 --- a/dspace/src/org/dspace/app/webui/servlet/SubmitServlet.java +++ b/dspace/src/org/dspace/app/webui/servlet/SubmitServlet.java @@ -81,7 +81,6 @@ import org.dspace.eperson.EPerson; import org.dspace.workflow.WorkflowItem; import org.dspace.workflow.WorkflowManager; - /** * Submission servlet for DSpace. Handles the initial submission of items, as * well as the editing of items further down the line. @@ -1257,12 +1256,30 @@ public class SubmitServlet extends DSpaceServlet { // Finished the uploading of files // FIXME Validation check here + + // set primary bitstream + if (request.getParameter("primary_bitstream_id") != null) + { + Bundle[] bundles = item.getBundles(); + bundles[0].setPrimaryBitstreamID(new Integer(request.getParameter("primary_bitstream_id")).intValue()); + bundles[0].update(); + } + userHasReached(subInfo, REVIEW_SUBMISSION); doStep(context, request, response, subInfo, REVIEW_SUBMISSION); context.complete(); } else if (buttonPressed.equals("submit_more")) { + // set primary bitstream + if (request.getParameter("primary_bitstream_id") != null) + { + Bundle[] bundles = item.getBundles(); + bundles[0].setPrimaryBitstreamID(new Integer(request.getParameter("primary_bitstream_id")).intValue()); + bundles[0].update(); + context.commit(); + } + // Upload another file request.setAttribute("submission.info", subInfo); JSPManager.showJSP(request, response, "/submit/choose-file.jsp"); diff --git a/dspace/src/org/dspace/content/Bundle.java b/dspace/src/org/dspace/content/Bundle.java index 7e86915f5d..bf30d31715 100644 --- a/dspace/src/org/dspace/content/Bundle.java +++ b/dspace/src/org/dspace/content/Bundle.java @@ -85,7 +85,6 @@ public class Bundle extends DSpaceObject /** The bitstreams in this bundle */ private List bitstreams; - /** * Construct a bundle object with the given table row * @@ -238,6 +237,30 @@ public class Bundle extends DSpaceObject } + /** + * Get the primary bitstream ID of the bundle + * + * @return primary bitstream ID + * or -1 if not set + */ + public int getPrimaryBitstreamID() + { + return bundleRow.getIntColumn("primary_bitstream_id"); + } + + + /** + * Set the primary bitstream ID of the bundle + * + * @param bitstreamID int ID of primary bitstream + * (e.g. index html file) + */ + public void setPrimaryBitstreamID(int bitstreamID) + { + bundleRow.setColumn("primary_bitstream_id", bitstreamID); + } + + public String getHandle() { // No Handles for bundles diff --git a/dspace/src/org/dspace/storage/rdbms/TableRow.java b/dspace/src/org/dspace/storage/rdbms/TableRow.java index 21233329fb..ad53a62775 100644 --- a/dspace/src/org/dspace/storage/rdbms/TableRow.java +++ b/dspace/src/org/dspace/storage/rdbms/TableRow.java @@ -331,7 +331,7 @@ public class TableRow if (! hasColumn(column)) throw new IllegalArgumentException("No such column " + column); - data.put(canonicalize(column), new Integer(i)); + data.put(canonicalize(column), new Integer(i)); } /**
+ * /html/handle/filename + * + * @author Robert Tansley + * @version $Revision$ + */ +public class HTMLServlet extends DSpaceServlet +{ + /** log4j category */ + private static Logger log = Logger.getLogger(HTMLServlet.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 filename = ""; + String handle = ""; + + if (idString != null) + { + + // Remove leading slash + if (idString.startsWith("/")) + { + idString = idString.substring(1); + } + + // Get filename + int slashIndex = idString.lastIndexOf('/'); + if (slashIndex != -1) + { + filename = idString.substring(slashIndex + 1); + filename = URLDecoder.decode(filename); + handle = idString.substring(0, slashIndex); + } + + // If there's still a second slash, remove it and anything after it, + // it might be a relative directory name + slashIndex = handle.indexOf('/'); + slashIndex = handle.indexOf('/', slashIndex + 1); + if (slashIndex != -1) + { + handle = handle.substring(0, slashIndex); + } + + + // Find the corresponding bitstream + try + { + boolean found = false; + + 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; + } + + Bundle[] bundles = item.getBundles(); + for (int i = 0; i < bundles.length; i++) { + Bitstream[] bitstreams = bundles[i].getBitstreams(); + if (!found) { + for (int k = 0; k < bitstreams.length; k++) { + if (filename.equals(bitstreams[k].getName())) { + bitstream = bitstreams[k]; + found = true; + } + } + } + } + + //bitstream = Bitstream.find(context, id); + } + 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/SubmitServlet.java b/dspace/src/org/dspace/app/webui/servlet/SubmitServlet.java index 71ce1edfe4..f0e40e1345 100644 --- a/dspace/src/org/dspace/app/webui/servlet/SubmitServlet.java +++ b/dspace/src/org/dspace/app/webui/servlet/SubmitServlet.java @@ -81,7 +81,6 @@ import org.dspace.eperson.EPerson; import org.dspace.workflow.WorkflowItem; import org.dspace.workflow.WorkflowManager; - /** * Submission servlet for DSpace. Handles the initial submission of items, as * well as the editing of items further down the line. @@ -1257,12 +1256,30 @@ public class SubmitServlet extends DSpaceServlet { // Finished the uploading of files // FIXME Validation check here + + // set primary bitstream + if (request.getParameter("primary_bitstream_id") != null) + { + Bundle[] bundles = item.getBundles(); + bundles[0].setPrimaryBitstreamID(new Integer(request.getParameter("primary_bitstream_id")).intValue()); + bundles[0].update(); + } + userHasReached(subInfo, REVIEW_SUBMISSION); doStep(context, request, response, subInfo, REVIEW_SUBMISSION); context.complete(); } else if (buttonPressed.equals("submit_more")) { + // set primary bitstream + if (request.getParameter("primary_bitstream_id") != null) + { + Bundle[] bundles = item.getBundles(); + bundles[0].setPrimaryBitstreamID(new Integer(request.getParameter("primary_bitstream_id")).intValue()); + bundles[0].update(); + context.commit(); + } + // Upload another file request.setAttribute("submission.info", subInfo); JSPManager.showJSP(request, response, "/submit/choose-file.jsp"); diff --git a/dspace/src/org/dspace/content/Bundle.java b/dspace/src/org/dspace/content/Bundle.java index 7e86915f5d..bf30d31715 100644 --- a/dspace/src/org/dspace/content/Bundle.java +++ b/dspace/src/org/dspace/content/Bundle.java @@ -85,7 +85,6 @@ public class Bundle extends DSpaceObject /** The bitstreams in this bundle */ private List bitstreams; - /** * Construct a bundle object with the given table row * @@ -238,6 +237,30 @@ public class Bundle extends DSpaceObject } + /** + * Get the primary bitstream ID of the bundle + * + * @return primary bitstream ID + * or -1 if not set + */ + public int getPrimaryBitstreamID() + { + return bundleRow.getIntColumn("primary_bitstream_id"); + } + + + /** + * Set the primary bitstream ID of the bundle + * + * @param bitstreamID int ID of primary bitstream + * (e.g. index html file) + */ + public void setPrimaryBitstreamID(int bitstreamID) + { + bundleRow.setColumn("primary_bitstream_id", bitstreamID); + } + + public String getHandle() { // No Handles for bundles diff --git a/dspace/src/org/dspace/storage/rdbms/TableRow.java b/dspace/src/org/dspace/storage/rdbms/TableRow.java index 21233329fb..ad53a62775 100644 --- a/dspace/src/org/dspace/storage/rdbms/TableRow.java +++ b/dspace/src/org/dspace/storage/rdbms/TableRow.java @@ -331,7 +331,7 @@ public class TableRow if (! hasColumn(column)) throw new IllegalArgumentException("No such column " + column); - data.put(canonicalize(column), new Integer(i)); + data.put(canonicalize(column), new Integer(i)); } /**
/html/handle/filename