Improve output: distinguish between failed assertions (failures) and unexpected exceptions (errors), and print a filtered stack trace for any exception.
This commit is contained in:
commit
4f2e303079
1839 changed files with 235630 additions and 0 deletions
23
webapp/web/fileupload/datastreamModification.jsp
Normal file
23
webapp/web/fileupload/datastreamModification.jsp
Normal file
|
@ -0,0 +1,23 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
|
||||
<%/* this is used by the FedoraDatastreamController and not by the N3 editing system.*/%>
|
||||
|
||||
<h2>Upload a replacement for ${fileName}</h2>
|
||||
<form action="<c:url value="/fedoraDatastreamController"/>"
|
||||
enctype="multipart/form-data" method="POST">
|
||||
|
||||
<p>File <input type="file" id="fileRes" name="fileRes" /></p>
|
||||
|
||||
<%/* <p><input type="radio" name="useNewName" value="false" checked/>
|
||||
use existing file name</p>
|
||||
<p><input type="radio" name="useNewName" value="true"/>
|
||||
rename file to name of file being uploaded</p> */%>
|
||||
|
||||
<input type="hidden" name="fileUri" value="${fileUri}"/>
|
||||
<input type="hidden" name="pid" value="${pid}"/>
|
||||
<input type="hidden" name="dsid" value="${dsid}"/>
|
||||
|
||||
<input type="submit" id="submit" value="submit" />
|
||||
</form>
|
16
webapp/web/fileupload/datastreamModificationSuccess.jsp
Normal file
16
webapp/web/fileupload/datastreamModificationSuccess.jsp
Normal file
|
@ -0,0 +1,16 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
|
||||
<div>The file ${orginalFileName} was updated. The file received from you had the MD5 checksum ${checksum}.</div>
|
||||
|
||||
<c:if test="${useNewName}">
|
||||
<div>The name of the file was also changed to ${newFileName}.</div>
|
||||
</c:if>
|
||||
|
||||
<c:url value="/individual" var="url">
|
||||
<c:param name="uri" value="${fileUri}"/>
|
||||
</c:url>
|
||||
|
||||
<div>Goto <a href="${url}">${newFileName}</a></div>
|
||||
|
23
webapp/web/fileupload/fileUploadForm.jsp
Normal file
23
webapp/web/fileupload/fileUploadForm.jsp
Normal file
|
@ -0,0 +1,23 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
|
||||
<script src="../js/jquery.js" type="text/javascript" language="javascript"></script>
|
||||
<script src="../js/jquery_plugins/jquery.MultiFile.js" type="text/javascript" language="javascript"></script>
|
||||
|
||||
<title> file upload for ${projectName} </title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="fileUploadProcess.jsp" method="post" enctype="multipart/form-data">
|
||||
<input type="text" name="creator" value="Brian Caruso"/></br>
|
||||
<input type="file" class="multi" name="file1" value="file1"/></br>
|
||||
<input type="submit" name="submit" value="Submit"/>
|
||||
</form>
|
||||
|
||||
<form action="" class="P10">
|
||||
<input type="file" class="multi" accept="gif|jpg"/>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
128
webapp/web/fileupload/fileUploadProcess.jsp
Normal file
128
webapp/web/fileupload/fileUploadProcess.jsp
Normal file
|
@ -0,0 +1,128 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
|
||||
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
|
||||
<%@ page import="org.apache.commons.fileupload.FileItem" %>
|
||||
<%@ page import="java.util.Iterator" %>
|
||||
<%@ page import="java.util.List" %>
|
||||
<%@ page import="java.io.File" %>
|
||||
|
||||
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
|
||||
|
||||
<%-- This is a jsp to handle uploading files. --%>
|
||||
<%-- It was written with Datastar in mind --%>
|
||||
|
||||
<%-- This JSP code expects that the user is logged in,
|
||||
that a datastar project is specified, and that the
|
||||
request is a multipart POST. --%>
|
||||
|
||||
<%-- Since this is for Datastar we need the URI of the user
|
||||
who is uploading this file, the URI of the project it is
|
||||
associated with and a project spcific directory to save
|
||||
the file to. %>
|
||||
|
||||
<%! static final int MAX_IN_MEM_SIZE = 1024*1024 * 50 ; //50 Mbyte file limit %>
|
||||
|
||||
|
||||
<%-- http://vivo.library.cornell.edu/ns/0.1#coordinatorOf --%>
|
||||
<%-- http://vivo.library.cornell.edu/ns/0.1#resourceAuthor --%>
|
||||
|
||||
<%! static final int MAX_IN_MEM_SIZE = 1024*1024 * 50; %>
|
||||
|
||||
<%
|
||||
if( ! ServletFileUpload.isMultipartContent(request) ){
|
||||
//return an error message0.
|
||||
out.write("<html><p>you need to submit a file.</p></html>");
|
||||
return;
|
||||
}
|
||||
|
||||
//Create a factory for disk-based file items
|
||||
DiskFileItemFactory factory = new DiskFileItemFactory();
|
||||
factory.setSizeThreshold(MAX_IN_MEM_SIZE);
|
||||
|
||||
// Create a new file upload handler
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
upload.setSizeMax(MAX_IN_MEM_SIZE);
|
||||
|
||||
// Parse the request
|
||||
List /* FileItem */ items = upload.parseRequest(request);
|
||||
|
||||
String user = getUserUri(request);
|
||||
String project = getProjectUri(request);
|
||||
String dir = getDirectory(user,project,request);
|
||||
|
||||
if( ! canWriteDirectory( dir )){
|
||||
out.write( doDirectoryWriteError( dir ) );
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator iter = items.iterator();
|
||||
while( iter.hasNext()){
|
||||
|
||||
FileItem item = (FileItem)iter.next();
|
||||
if( item.isFormField()){
|
||||
out.write("<p>");
|
||||
out.write("fieldname: " + item.getFieldName() + " value: " + item.getString() );
|
||||
out.write("</p>");
|
||||
}else{
|
||||
System.out.println("fileUPloadProcess.jsp: attempting to upload a file" );
|
||||
out.write("<p>");
|
||||
out.write("form field name: " + item.getFieldName()
|
||||
+" filename: " + item.getName()
|
||||
+" type: " + item.getContentType()
|
||||
+" isInMem: " + item.isInMemory() );
|
||||
out.write("</p>");
|
||||
|
||||
String fileLocation = dir + '/' + item.getName();
|
||||
if( fileWithNameAlreadyExists( fileLocation ) ){
|
||||
doFileExistsError( fileLocation );
|
||||
return;
|
||||
}
|
||||
|
||||
File uploadedFile = new File( fileLocation );
|
||||
item.write( uploadedFile );
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
<%!
|
||||
public String getDirectory(String userUri, String projectUri, HttpServletRequest request){
|
||||
//this should be stored in the model as a dataproperty on the project
|
||||
return "/usr/local/datastar/data";
|
||||
}
|
||||
|
||||
public String getUserUri( HttpServletRequest request ){
|
||||
return "http://vivo.library.cornell.edu/ns/0.1#individual762"; //Medha Devare
|
||||
}
|
||||
|
||||
public String getProjectUri( HttpServletRequest request ){
|
||||
return "http://vivo.library.cornell.edu/ns/0.1#individual1"; //Mann Lib.
|
||||
}
|
||||
%>
|
||||
|
||||
<%!
|
||||
public boolean canWriteDirectory( String dir ){
|
||||
File df = new File(dir);
|
||||
//attempt to create directory if not found
|
||||
if( ! df.exists() ){
|
||||
if( !df.mkdir() )
|
||||
return false;
|
||||
}
|
||||
return df.canWrite();
|
||||
}
|
||||
|
||||
public String doDirectoryWriteError( String dir ) {
|
||||
return "The system could not save your file, contact you system"
|
||||
+" administrators and inform them that the directory "
|
||||
+ dir + " is not writeable";
|
||||
}
|
||||
|
||||
public boolean fileWithNameAlreadyExists( String fileLocation ){
|
||||
File f = new File(fileLocation);
|
||||
return f.exists();
|
||||
}
|
||||
|
||||
public String doFileExistsError( String file ) {
|
||||
return "There is already a file named " + file + " on the system. Please rename your file " ;
|
||||
}
|
||||
%>
|
11
webapp/web/fileupload/md5.jsp
Normal file
11
webapp/web/fileupload/md5.jsp
Normal file
|
@ -0,0 +1,11 @@
|
|||
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
|
||||
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
||||
|
||||
<div>${checksum} "${fileName}"</div>
|
||||
|
||||
<c:url value="/individual" var="url">
|
||||
<c:param name="uri" value="${uri}"/>
|
||||
</c:url>
|
||||
<div>return to <a href="${url}">${name}</a></div>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue