protected void handlePlaintext( ContentProfileProvider modelProvider, SubmissionTemplate template, Submission.Builder submissionBuilder, Attachment attachment, String actingAsId) throws PieceworkException { String contentType = MediaType.TEXT_PLAIN; if (LOG.isDebugEnabled()) LOG.debug( "Processing multipart with content type " + contentType + " and content id " + attachment.getContentId()); String name = sanitizer.sanitize(attachment.getDataHandler().getName()); String value = sanitizer.sanitize(attachment.getObject(String.class)); if (!submissionStorageService.store( modelProvider, template, submissionBuilder, name, value, actingAsId)) { LOG.warn( "Submission included field (" + name + ") that is not acceptable, and no attachments are allowed for this template"); } }
protected void handleAllContentTypes( ContentProfileProvider modelProvider, SubmissionTemplate template, Submission.Builder submissionBuilder, Attachment attachment, String actingAsId) throws PieceworkException { ContentDisposition contentDisposition = attachment.getContentDisposition(); MediaType mediaType = attachment.getContentType(); if (contentDisposition != null) { String contentType = mediaType.toString(); String name = sanitizer.sanitize(contentDisposition.getParameter("name")); String filename = sanitizer.sanitize(contentDisposition.getParameter("filename")); if (StringUtils.isNotEmpty(filename)) { if (LOG.isDebugEnabled()) LOG.debug( "Processing multipart with content type " + contentType + " content id " + attachment.getContentId() + " and filename " + filename); try { if (!submissionStorageService.store( modelProvider, template, submissionBuilder, name, filename, actingAsId, attachment.getDataHandler().getInputStream(), contentType)) { LOG.warn( "Submission included field (" + name + ") that is not acceptable, and no attachments are allowed for this template"); } } catch (IOException e) { LOG.warn( "Unable to store file with content type " + contentType + " and filename " + filename); } } else if (mediaType.equals(MediaType.TEXT_PLAIN_TYPE)) { handlePlaintext(modelProvider, template, submissionBuilder, attachment, actingAsId); } } }