VIVO-617 Adjust the client code to use the new file upload tools.

This commit is contained in:
j2blake 2013-12-20 17:11:16 -05:00
parent b7b28cc896
commit c42d9af70f
8 changed files with 116 additions and 140 deletions

View file

@ -45,7 +45,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess; import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
import fedora.client.FedoraClient; import fedora.client.FedoraClient;
import fedora.common.Constants; import fedora.common.Constants;
import fedora.server.management.FedoraAPIM; import fedora.server.management.FedoraAPIM;
@ -220,12 +219,22 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
} }
@Override @Override
public long maximumMultipartFileSize() {
return maxFileSize;
}
@Override
public boolean stashFileSizeException() {
return true;
}
@Override
public void doPost(HttpServletRequest rawRequest, HttpServletResponse res) public void doPost(HttpServletRequest rawRequest, HttpServletResponse res)
throws ServletException, IOException { throws ServletException, IOException {
try{ try{
FileUploadServletRequest req = FileUploadServletRequest.parseRequest(rawRequest, maxFileSize); VitroRequest req = new VitroRequest(rawRequest);
if (req.hasFileUploadException()) { if (req.hasFileSizeException()) {
throw new FdcException("Size limit exceeded: " + req.getFileUploadException().getLocalizedMessage()); throw new FdcException("Size limit exceeded: " + req.getFileSizeException().getLocalizedMessage());
} }
if (!req.isMultipart()) { if (!req.isMultipart()) {
throw new FdcException("Must POST a multipart encoded request"); throw new FdcException("Must POST a multipart encoded request");

View file

@ -2,12 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.controller.freemarker; package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.UnavailableException; import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -36,7 +30,6 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup; import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
import edu.cornell.mannlib.vitro.webapp.i18n.I18n; import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
import edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil; import edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil;
@ -52,6 +45,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
private static final String ERROR_CODE_UNRECOGNIZED_URI = "imageUpload.errorUnrecognizedURI"; private static final String ERROR_CODE_UNRECOGNIZED_URI = "imageUpload.errorUnrecognizedURI";
private static final String ERROR_CODE_NO_URI = "imageUpload.errorNoURI"; private static final String ERROR_CODE_NO_URI = "imageUpload.errorNoURI";
private static final String ERROR_CODE_FILE_TOO_BIG = "imageUpload.errorFileTooBig";
/** Limit file size to 6 megabytes. */ /** Limit file size to 6 megabytes. */
public static final int MAXIMUM_FILE_SIZE = 6 * 1024 * 1024; public static final int MAXIMUM_FILE_SIZE = 6 * 1024 * 1024;
@ -137,6 +131,22 @@ public class ImageUploadController extends FreemarkerHttpServlet {
} }
} }
/**
* How large an image file will we accept?
*/
@Override
public long maximumMultipartFileSize() {
return MAXIMUM_FILE_SIZE;
}
/**
* What will we do if there is a problem parsing the request?
*/
@Override
public boolean stashFileSizeException() {
return true;
}
/** /**
* The required action depends on what we are trying to do. * The required action depends on what we are trying to do.
*/ */
@ -171,52 +181,17 @@ public class ImageUploadController extends FreemarkerHttpServlet {
} }
} }
/**
* <p>
* Parse the multi-part request, process the request, and produce the
* output.
* </p>
* <p>
* If the request was a multi-part file upload, it will parse to a
* normal-looking request with a "file_item_map" attribute.
* </p>
* <p>
* The processing will produce a {@link ResponseValues} object, which
* represents either a request for a FreeMarker template or a forwarding
* operation.
* <ul>
* <li>If a FreeMarker template, we emulate the actions that
* FreeMarkerHttpServlet would have taken to produce the output.</li>
* <li>If a forwarding operation, we create a {@link RequestDispatcher} to
* do the forwarding.</li>
* </ul>
* </p>
*/
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
try {
// Parse the multi-part request.
FileUploadServletRequest.parseRequest(vreq, MAXIMUM_FILE_SIZE);
if (log.isTraceEnabled()) {
dumpRequestDetails(vreq);
}
return buildTheResponse(vreq);
} catch (Exception e) {
// log.error("Could not produce response page", e);
return new ExceptionResponseValues(e);
}
}
/** /**
* Handle the different actions. If not specified, the default action is to * Handle the different actions. If not specified, the default action is to
* show the intro screen. * show the intro screen.
*/ */
private ResponseValues buildTheResponse(VitroRequest vreq) { @Override
String action = vreq.getParameter(PARAMETER_ACTION); protected ResponseValues processRequest(VitroRequest vreq) {
try { try {
checkForFileTooBigException(vreq);
String action = vreq.getParameter(PARAMETER_ACTION);
Individual entity = validateEntityUri(vreq); Individual entity = validateEntityUri(vreq);
if (ACTION_UPLOAD.equals(action)) { if (ACTION_UPLOAD.equals(action)) {
return doUploadImage(vreq, entity); return doUploadImage(vreq, entity);
@ -240,6 +215,19 @@ public class ImageUploadController extends FreemarkerHttpServlet {
} }
} }
/**
* If our exception handler caught a "file too big" exception, we need to
* deal with it before anything else, since we can't trust the other
* parameters.
*/
private void checkForFileTooBigException(VitroRequest vreq)
throws UserMistakeException {
if (vreq.hasFileSizeException()) {
int limit = MAXIMUM_FILE_SIZE / (1024 * 1024);
throw new UserMistakeException(ERROR_CODE_FILE_TOO_BIG, limit);
}
}
/** /**
* We are just starting the upload process. Record where we came from, so if * We are just starting the upload process. Record where we came from, so if
* they hit "cancel" we know where to send them. If we have problems, just * they hit "cancel" we know where to send them. If we have problems, just
@ -626,31 +614,6 @@ public class ImageUploadController extends FreemarkerHttpServlet {
} }
/**
* For debugging, dump all sorts of information about the request.
*
* WARNING: if "req" represents a Multi-part request which has not yet been
* parsed, then reading these parameters will consume them.
*/
@SuppressWarnings("unchecked")
private void dumpRequestDetails(HttpServletRequest req) {
log.trace("Request is " + req.getClass().getName());
Map<String, String[]> parms = req.getParameterMap();
for (Entry<String, String[]> entry : parms.entrySet()) {
log.trace("Parameter '" + entry.getKey() + "'="
+ Arrays.deepToString(entry.getValue()));
}
Enumeration<String> attrs = req.getAttributeNames();
while (attrs.hasMoreElements()) {
String key = attrs.nextElement();
String valueString = String.valueOf(req.getAttribute(key));
String valueOneLine = valueString.replace("\n", " | ");
log.trace("Attribute '" + key + "'=" + valueOneLine);
}
}
static class Dimensions { static class Dimensions {
final int width; final int width;
final int height; final int height;

View file

@ -2,12 +2,9 @@
package edu.cornell.mannlib.vitro.webapp.controller.freemarker; package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.MAXIMUM_FILE_SIZE;
import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.PARAMETER_UPLOADED_FILE; import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.PARAMETER_UPLOADED_FILE;
import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.THUMBNAIL_HEIGHT; import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.THUMBNAIL_HEIGHT;
import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.THUMBNAIL_WIDTH; import static edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadController.THUMBNAIL_WIDTH;
import static edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest.FILE_ITEM_MAP;
import static edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest.FILE_UPLOAD_EXCEPTION;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -21,7 +18,6 @@ import javax.media.jai.JAI;
import javax.media.jai.RenderedOp; import javax.media.jai.RenderedOp;
import javax.media.jai.util.ImagingListener; import javax.media.jai.util.ImagingListener;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
@ -41,7 +37,6 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.UploadedFileHelper;
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileAlreadyExistsException; import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileAlreadyExistsException;
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage; import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.model.FileInfo;
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
/** /**
* Handle the mechanics of validating, storing, and deleting file images. * Handle the mechanics of validating, storing, and deleting file images.
@ -55,7 +50,6 @@ public class ImageUploadHelper {
private static final String ERROR_CODE_NO_IMAGE_TO_CROP = "imageUpload.errorNoImageForCropping"; private static final String ERROR_CODE_NO_IMAGE_TO_CROP = "imageUpload.errorNoImageForCropping";
private static final String ERROR_CODE_IMAGE_TOO_SMALL = "imageUpload.errorImageTooSmall"; private static final String ERROR_CODE_IMAGE_TOO_SMALL = "imageUpload.errorImageTooSmall";
private static final String ERROR_CODE_UNKNOWN = "imageUpload.errorUnknown"; private static final String ERROR_CODE_UNKNOWN = "imageUpload.errorUnknown";
private static final String ERROR_CODE_FILE_TOO_BIG = "imageUpload.errorFileTooBig";
private static final String ERROR_CODE_UNRECOGNIZED_FILE_TYPE = "imageUpload.errorUnrecognizedFileType"; private static final String ERROR_CODE_UNRECOGNIZED_FILE_TYPE = "imageUpload.errorUnrecognizedFileType";
private static final String ERROR_CODE_NO_PHOTO_SELECTED = "imageUpload.errorNoPhotoSelected"; private static final String ERROR_CODE_NO_PHOTO_SELECTED = "imageUpload.errorNoPhotoSelected";
private static final String ERROR_CODE_BAD_MULTIPART_REQUEST = "imageUpload.errorBadMultipartRequest"; private static final String ERROR_CODE_BAD_MULTIPART_REQUEST = "imageUpload.errorBadMultipartRequest";
@ -133,20 +127,13 @@ public class ImageUploadHelper {
* if there is no file, if it is empty, or if it is not an image * if there is no file, if it is empty, or if it is not an image
* file. * file.
*/ */
@SuppressWarnings("unchecked") FileItem validateImageFromRequest(VitroRequest vreq)
FileItem validateImageFromRequest(HttpServletRequest request)
throws UserMistakeException { throws UserMistakeException {
Object exception = request.getAttribute(FILE_UPLOAD_EXCEPTION); Map<String, List<FileItem>> map = vreq.getFiles();
if (exception != null) {
int limit = MAXIMUM_FILE_SIZE / (1024 * 1024);
throw new UserMistakeException(ERROR_CODE_FILE_TOO_BIG, limit);
}
Map<String, List<FileItem>> map = (Map<String, List<FileItem>>) request
.getAttribute(FILE_ITEM_MAP);
if (map == null) { if (map == null) {
throw new IllegalStateException(ERROR_CODE_BAD_MULTIPART_REQUEST); throw new IllegalStateException(ERROR_CODE_BAD_MULTIPART_REQUEST);
} }
List<FileItem> list = map.get(PARAMETER_UPLOADED_FILE); List<FileItem> list = map.get(PARAMETER_UPLOADED_FILE);
if ((list == null) || list.isEmpty()) { if ((list == null) || list.isEmpty()) {
throw new UserMistakeException(ERROR_CODE_FORM_FIELD_MISSING, throw new UserMistakeException(ERROR_CODE_FORM_FIELD_MISSING,

View file

@ -25,7 +25,6 @@ import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
import edu.cornell.mannlib.vitro.webapp.utils.Csv2Rdf; import edu.cornell.mannlib.vitro.webapp.utils.Csv2Rdf;
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils; import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
@ -37,6 +36,17 @@ public class JenaCsv2RdfController extends JenaIngestController {
private static final String CSV2RDF_SELECT_URI_JSP = "/jenaIngest/csv2rdfSelectUri.jsp"; private static final String CSV2RDF_SELECT_URI_JSP = "/jenaIngest/csv2rdfSelectUri.jsp";
private static int maxFileSizeInBytes = 1024 * 1024 * 2000; //2000mb private static int maxFileSizeInBytes = 1024 * 1024 * 2000; //2000mb
@Override
public long maximumMultipartFileSize() {
return maxFileSizeInBytes;
}
@Override
public boolean stashFileSizeException() {
return true;
}
@Override @Override
public void doPost(HttpServletRequest rawRequest, public void doPost(HttpServletRequest rawRequest,
HttpServletResponse response) throws ServletException, IOException { HttpServletResponse response) throws ServletException, IOException {
@ -45,15 +55,13 @@ public class JenaCsv2RdfController extends JenaIngestController {
return; return;
} }
FileUploadServletRequest req = FileUploadServletRequest.parseRequest(rawRequest, VitroRequest request = new VitroRequest(rawRequest);
maxFileSizeInBytes); if (request.hasFileSizeException()) {
if (req.hasFileUploadException()) { forwardToFileUploadError(request.getFileSizeException().getLocalizedMessage(), request, response);
forwardToFileUploadError(req.getFileUploadException().getLocalizedMessage(), req, response);
return; return;
} }
VitroRequest request = new VitroRequest(req); Map<String, List<FileItem>> fileStreams = request.getFiles();
Map<String, List<FileItem>> fileStreams = req.getFiles();
FileItem fileStream = fileStreams.get("filePath").get(0); FileItem fileStream = fileStreams.get("filePath").get(0);
String filePath = fileStreams.get("filePath").get(0).getName(); String filePath = fileStreams.get("filePath").get(0).getName();
@ -70,7 +78,7 @@ public class JenaCsv2RdfController extends JenaIngestController {
csv2rdfResult = doExecuteCsv2Rdf( csv2rdfResult = doExecuteCsv2Rdf(
request, fileStream, filePath); request, fileStream, filePath);
}catch(Exception ex){ }catch(Exception ex){
forwardToFileUploadError(ex.getMessage(),req,response); forwardToFileUploadError(ex.getMessage(),request,response);
return; return;
} }
ModelMaker maker = getVitroJenaModelMaker(request); ModelMaker maker = getVitroJenaModelMaker(request);

View file

@ -36,7 +36,6 @@ import com.hp.hpl.jena.shared.Lock;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
public class JenaXMLFileUpload extends JenaIngestController { public class JenaXMLFileUpload extends JenaIngestController {
Log log = LogFactory.getLog(JenaXMLFileUpload.class); Log log = LogFactory.getLog(JenaXMLFileUpload.class);
@ -76,6 +75,16 @@ public class JenaXMLFileUpload extends JenaIngestController {
} }
} }
@Override
public long maximumMultipartFileSize() {
return maxFileSize;
}
@Override
public boolean stashFileSizeException() {
return true;
}
/** /**
* Each file will be converted to RDF/XML and loaded to the target model. * Each file will be converted to RDF/XML and loaded to the target model.
* If any of the files fail, no data will be loaded. * If any of the files fail, no data will be loaded.
@ -86,14 +95,14 @@ public class JenaXMLFileUpload extends JenaIngestController {
* *
*/ */
@Override @Override
public void doPost(HttpServletRequest rawRequest, HttpServletResponse resp) public void doPost(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException { throws ServletException, IOException {
FileUploadServletRequest request = FileUploadServletRequest.parseRequest(rawRequest, maxFileSize); VitroRequest vreq = new VitroRequest(request);
if (request.hasFileUploadException()) { if (vreq.hasFileSizeException()) {
throw new ServletException("Size limit exceeded: " throw new ServletException("Size limit exceeded: "
+ request.getFileUploadException().getLocalizedMessage()); + vreq.getFileSizeException().getLocalizedMessage());
} }
if (request.isMultipart()) { if (vreq.isMultipart()) {
log.debug("multipart content detected"); log.debug("multipart content detected");
} else { } else {
// TODO: forward to error message // TODO: forward to error message
@ -105,7 +114,6 @@ public class JenaXMLFileUpload extends JenaIngestController {
return; return;
} }
VitroRequest vreq = new VitroRequest(request);
ModelMaker modelMaker = getVitroJenaModelMaker(vreq); ModelMaker modelMaker = getVitroJenaModelMaker(vreq);
String targetModel = request.getParameter("targetModel"); String targetModel = request.getParameter("targetModel");
if (targetModel == null) { if (targetModel == null) {
@ -117,7 +125,7 @@ public class JenaXMLFileUpload extends JenaIngestController {
throw new ServletException("targetModel '" + targetModel + "' was not found."); throw new ServletException("targetModel '" + targetModel + "' was not found.");
request.setAttribute("targetModel", targetModel); request.setAttribute("targetModel", targetModel);
List<File> filesToLoad = saveFiles( request.getFiles() ); List<File> filesToLoad = saveFiles( vreq.getFiles() );
List<File> rdfxmlToLoad = convertFiles( filesToLoad); List<File> rdfxmlToLoad = convertFiles( filesToLoad);
List<Model> modelsToLoad = loadRdfXml( rdfxmlToLoad ); List<Model> modelsToLoad = loadRdfXml( rdfxmlToLoad );
@ -136,7 +144,7 @@ public class JenaXMLFileUpload extends JenaIngestController {
request.setAttribute("title","Uploaded files and converted to RDF"); request.setAttribute("title","Uploaded files and converted to RDF");
request.setAttribute("bodyJsp","/jenaIngest/xmlFileUploadSuccess.jsp"); request.setAttribute("bodyJsp","/jenaIngest/xmlFileUploadSuccess.jsp");
request.setAttribute("fileItems",request.getFiles()); request.setAttribute("fileItems",vreq.getFiles());
RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""+vreq.getAppBean().getThemeDir()+"css/edit.css\"/>"); request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""+vreq.getAppBean().getThemeDir()+"css/edit.css\"/>");

View file

@ -42,7 +42,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent; import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet; import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
@ -56,31 +55,39 @@ public class RDFUploadController extends JenaIngestController {
private static FileItem fileStream = null; private static FileItem fileStream = null;
private static final String LOAD_RDF_DATA_JSP="/jenaIngest/loadRDFData.jsp"; private static final String LOAD_RDF_DATA_JSP="/jenaIngest/loadRDFData.jsp";
public void doPost(HttpServletRequest rawRequest, @Override
public long maximumMultipartFileSize() {
return maxFileSizeInBytes;
}
@Override
public boolean stashFileSizeException() {
return true;
}
public void doPost(HttpServletRequest req,
HttpServletResponse response) throws ServletException, IOException { HttpServletResponse response) throws ServletException, IOException {
if (!isAuthorizedToDisplayPage(rawRequest, response, if (!isAuthorizedToDisplayPage(req, response,
SimplePermission.USE_ADVANCED_DATA_TOOLS_PAGES.ACTIONS)) { SimplePermission.USE_ADVANCED_DATA_TOOLS_PAGES.ACTIONS)) {
return; return;
} }
FileUploadServletRequest req = FileUploadServletRequest.parseRequest( VitroRequest request = new VitroRequest(req);
rawRequest, maxFileSizeInBytes); if (request.hasFileSizeException()) {
if (req.hasFileUploadException()) {
forwardToFileUploadError( forwardToFileUploadError(
req.getFileUploadException().getLocalizedMessage(), request.getFileSizeException().getLocalizedMessage(),
req, response); req, response);
return; return;
} }
Map<String, List<FileItem>> fileStreams = req.getFiles(); Map<String, List<FileItem>> fileStreams = request.getFiles();
VitroRequest request = new VitroRequest(req);
LoginStatusBean loginBean = LoginStatusBean.getBean(request); LoginStatusBean loginBean = LoginStatusBean.getBean(request);
try { try {
String modelName = req.getParameter("modelName"); String modelName = req.getParameter("modelName");
if(modelName!=null){ if(modelName!=null){
loadRDF(req,request,response); loadRDF(request,response);
return; return;
} }
} catch (Exception e) { } catch (Exception e) {
@ -234,15 +241,13 @@ public class RDFUploadController extends JenaIngestController {
} }
} }
public void loadRDF(FileUploadServletRequest req, public void loadRDF(VitroRequest request, HttpServletResponse response)
VitroRequest request, throws ServletException {
HttpServletResponse response) Map<String, List<FileItem>> fileStreams = request.getFiles();
throws ServletException, IOException {
Map<String, List<FileItem>> fileStreams = req.getFiles();
String filePath = fileStreams.get("filePath").get(0).getName(); String filePath = fileStreams.get("filePath").get(0).getName();
fileStream = fileStreams.get("filePath").get(0); fileStream = fileStreams.get("filePath").get(0);
String modelName = req.getParameter("modelName"); String modelName = request.getParameter("modelName");
String docLoc = req.getParameter("docLoc"); String docLoc = request.getParameter("docLoc");
String languageStr = request.getParameter("language"); String languageStr = request.getParameter("language");
ModelMaker maker = getVitroJenaModelMaker(request); ModelMaker maker = getVitroJenaModelMaker(request);

View file

@ -23,7 +23,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServ
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
/** /**
@ -35,7 +34,10 @@ public class SearchServiceController extends FreemarkerHttpServlet {
.getLog(SearchServiceController.class); .getLog(SearchServiceController.class);
/** Limit file size to 1 Gigabyte. */ /** Limit file size to 1 Gigabyte. */
public static final int MAXIMUM_FILE_SIZE = 1024 * 1024 * 1024; @Override
public long maximumMultipartFileSize() {
return 1024 * 1024 * 1024;
}
/** /**
* Handle the different actions. If not specified, the default action is to * Handle the different actions. If not specified, the default action is to
@ -44,9 +46,6 @@ public class SearchServiceController extends FreemarkerHttpServlet {
@Override @Override
protected ResponseValues processRequest(VitroRequest req) { protected ResponseValues processRequest(VitroRequest req) {
try { try {
req = new VitroRequest(FileUploadServletRequest.parseRequest(req,
MAXIMUM_FILE_SIZE));
// Check the authorization here, because we don't want to redirect // Check the authorization here, because we don't want to redirect
// to the login page if they are not authorized. (The file upload // to the login page if they are not authorized. (The file upload
// would be lost. // would be lost.

View file

@ -2,8 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.search.controller; package edu.cornell.mannlib.vitro.webapp.search.controller;
import static edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest.FILE_ITEM_MAP;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
@ -21,6 +19,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder; import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
/** /**
@ -41,9 +40,7 @@ public class UpdateUrisInIndex {
*/ */
protected int doUpdateUris(HttpServletRequest req, IndexBuilder builder) protected int doUpdateUris(HttpServletRequest req, IndexBuilder builder)
throws ServletException, IOException { throws ServletException, IOException {
@SuppressWarnings("unchecked") Map<String, List<FileItem>> map = new VitroRequest(req).getFiles();
Map<String, List<FileItem>> map = (Map<String, List<FileItem>>) req
.getAttribute(FILE_ITEM_MAP);
if (map == null) { if (map == null) {
throw new ServletException("Expected Multipart Content"); throw new ServletException("Expected Multipart Content");
} }
@ -54,13 +51,13 @@ public class UpdateUrisInIndex {
for (String name : map.keySet()) { for (String name : map.keySet()) {
for (FileItem item : map.get(name)) { for (FileItem item : map.get(name)) {
log.debug("Found " + item.getSize() + " byte file for '" + name + "'"); log.debug("Found " + item.getSize() + " byte file for '" + name + "'");
uriCount += processFileItem(builder, name, item, enc); uriCount += processFileItem(builder, item, enc);
} }
} }
return uriCount; return uriCount;
} }
private int processFileItem(IndexBuilder builder, String name, private int processFileItem(IndexBuilder builder,
FileItem item, Charset enc) throws IOException { FileItem item, Charset enc) throws IOException {
int count = 0; int count = 0;
Reader reader = new InputStreamReader(item.getInputStream(), enc.name()); Reader reader = new InputStreamReader(item.getInputStream(), enc.name());