(Scott Yeadon)

- Now uses Jakarta Commons FileUpload instead of com.oreilly.servlet.
  Patch SF #1380118.


git-svn-id: http://scm.dspace.org/svn/repo/trunk@1387 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Robert Tansley
2005-12-14 18:56:20 +00:00
parent fcf5164f19
commit 9c36b12214
7 changed files with 135 additions and 23 deletions

View File

@@ -1,5 +1,9 @@
1.4 beta 1 1.4 beta 1
========== ==========
(Scott Yeadon)
- Now uses Jakarta Commons FileUpload instead of com.oreilly.servlet.
Patch SF #1380118.
(Robert Tansley) (Robert Tansley)
- Drop unique community name constraint. Also fixes SF bug #1284055. - Drop unique community name constraint. Also fixes SF bug #1284055.

View File

@@ -165,7 +165,7 @@ log.dir = /dspace/log
# Where to temporarily store uploaded files # Where to temporarily store uploaded files
upload.temp.dir = /dspace/upload upload.temp.dir = /dspace/upload
# Maximum size of uploaded files in bytes, must be positive # Maximum size of uploaded files in bytes, negative setting will result in no limit being set
# 512Mb # 512Mb
upload.max = 536870912 upload.max = 536870912

View File

@@ -3,9 +3,9 @@ Libraries used by DSpace:
activation.jar: The Java Activation Framework, used by JavaMail (v1.0.2) activation.jar: The Java Activation Framework, used by JavaMail (v1.0.2)
commons-cli.jar: Jakarta Commons command line processing (v1.0) commons-cli.jar: Jakarta Commons command line processing (v1.0)
commons-collections.jar: Jakarta Commons collections API (v3.0) commons-collections.jar: Jakarta Commons collections API (v3.0)
commons-fileupload.jar: Jakarta Commons file upload package (v1.0)
commons-dbcp.jar: Jakarta Commons database connection pool (v1.2.1) commons-dbcp.jar: Jakarta Commons database connection pool (v1.2.1)
commons-pool.jar: Jakarta Commons object pooling API (v1.2) commons-pool.jar: Jakarta Commons object pooling API (v1.2)
cos.jar: com.oreilly.servlet - multipart HTTP requests. 05Nov2002
handle.jar: CNRI Handle Server (version 5.3.3) handle.jar: CNRI Handle Server (version 5.3.3)
jakarta-poi.jar: MS file reader, used by text extraction v2.0 jakarta-poi.jar: MS file reader, used by text extraction v2.0
jdom.jar Java DOM API library (version 1.0) jdom.jar Java DOM API library (version 1.0)

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,53 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/

View File

@@ -44,13 +44,21 @@ import java.io.IOException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.Set;
import java.util.Collection;
import java.util.Collections;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletRequestWrapper;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
import com.oreilly.servlet.MultipartRequest; import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.FileItem;
/** /**
* Based on the com.oreilly.servlet.MultipartWrapper object, this is an HTTP * Based on the com.oreilly.servlet.MultipartWrapper object, this is an HTTP
@@ -64,13 +72,16 @@ import com.oreilly.servlet.MultipartRequest;
public class FileUploadRequest extends HttpServletRequestWrapper public class FileUploadRequest extends HttpServletRequestWrapper
{ {
/** Multipart request */ /** Multipart request */
private MultipartRequest mreq = null; private List items = null;
private HashMap parameters = new HashMap();
private HashMap fileitems = new HashMap();
private Vector filenames = new Vector();
private String tempDir = null;
/** Original request */ /** Original request */
private HttpServletRequest original = null; private HttpServletRequest original = null;
/** /**
* Wraps a multipart request and extracts the files * Parse a multipart request and extracts the files
* *
* @param req * @param req
* the original request * the original request
@@ -81,26 +92,55 @@ public class FileUploadRequest extends HttpServletRequestWrapper
original = req; original = req;
String tempDir = ConfigurationManager.getProperty("upload.temp.dir"); tempDir = ConfigurationManager.getProperty("upload.temp.dir");
int maxSize = ConfigurationManager.getIntProperty("upload.max"); int maxSize = ConfigurationManager.getIntProperty("upload.max");
mreq = new MultipartRequest(req, tempDir, maxSize, "UTF-8"); DiskFileUpload upload = new DiskFileUpload();
try
{
upload.setRepositoryPath(tempDir);
upload.setSizeMax(maxSize);
items = upload.parseRequest(req);
for (Iterator i = items.iterator(); i.hasNext();)
{
FileItem item = (FileItem)i.next();
if (item.isFormField())
{
parameters.put(item.getFieldName(), item.getString("UTF-8"));
}
else
{
parameters.put(item.getFieldName(), item.getName());
fileitems.put(item.getFieldName(), item);
filenames.add(item.getName());
String filename = getFilename(item.getName());
item.write(new File(tempDir + File.separator + filename));
}
}
}
catch (Exception e)
{
throw new IOException(e.getMessage());
}
} }
// Methods to replace HSR methods // Methods to replace HSR methods
public Enumeration getParameterNames() public Enumeration getParameterNames()
{ {
return mreq.getParameterNames(); Collection c = parameters.keySet();
return Collections.enumeration(c);
} }
public String getParameter(String name) public String getParameter(String name)
{ {
return mreq.getParameter(name); return (String)parameters.get(name);
} }
public String[] getParameterValues(String name) public String[] getParameterValues(String name)
{ {
return mreq.getParameterValues(name); return (String[])parameters.values().toArray();
} }
public Map getParameterMap() public Map getParameterMap()
@@ -111,31 +151,32 @@ public class FileUploadRequest extends HttpServletRequestWrapper
while (eNum.hasMoreElements()) while (eNum.hasMoreElements())
{ {
String name = (String) eNum.nextElement(); String name = (String) eNum.nextElement();
map.put(name, mreq.getParameterValues(name)); map.put(name, getParameterValues(name));
} }
return map; return map;
} }
// Methods only in MultipartRequest
public Enumeration getFileNames()
{
return mreq.getFileNames();
}
public String getFilesystemName(String name) public String getFilesystemName(String name)
{ {
return mreq.getFilesystemName(name); String filename = getFilename(((FileItem)fileitems.get(name)).getName());
return tempDir + File.separator + filename;
} }
public String getContentType(String name) public String getContentType(String name)
{ {
return mreq.getContentType(name); return ((FileItem)fileitems.get(name)).getContentType();
} }
public File getFile(String name) public File getFile(String name)
{ {
return mreq.getFile(name); String filename = getFilename(((FileItem)fileitems.get(name)).getName());
return new File(tempDir + File.separator + filename);
}
public Enumeration getFileNames()
{
return filenames.elements();
} }
/** /**
@@ -147,4 +188,18 @@ public class FileUploadRequest extends HttpServletRequestWrapper
{ {
return original; return original;
} }
}
// Required due to the fact the contents of getName() may vary based on browser
private String getFilename(String filepath)
{
String filename = filepath;
int index = filepath.lastIndexOf(File.separator);
if (index > -1)
{
filename = filepath.substring(index);
}
return filename;
}
}