use of net.jforum.exceptions.MultipartHandlingException in project jforum2 by rafaelsteil.
the class WebRequestContext method handleMultipart.
/**
* @param superRequest HttpServletRequest
* @param encoding String
* @throws UnsupportedEncodingException
*/
private void handleMultipart(HttpServletRequest superRequest, String encoding) throws UnsupportedEncodingException {
String tmpPath = new StringBuffer(256).append(SystemGlobals.getApplicationPath()).append('/').append(SystemGlobals.getValue(ConfigKeys.TMP_DIR)).toString();
File tmpDir = new File(tmpPath);
boolean success = false;
try {
if (!tmpDir.exists()) {
tmpDir.mkdirs();
success = true;
}
} catch (Exception e) {
// We won't log it because the directory
// creation failed for some reason - a SecurityException
// or something else. We don't care about it, as the
// code below tries to use java.io.tmpdir
}
if (!success) {
tmpPath = System.getProperty("java.io.tmpdir");
tmpDir = new File(tmpPath);
}
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory(100 * 1024, tmpDir));
upload.setHeaderEncoding(encoding);
try {
List items = upload.parseRequest(superRequest);
for (Iterator iter = items.iterator(); iter.hasNext(); ) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
this.addParameter(item.getFieldName(), item.getString(encoding));
} else {
if (item.getSize() > 0) {
// We really don't want to call addParameter(), as
// there should not be possible to have multiple
// values for a InputStream data
this.query.put(item.getFieldName(), item);
}
}
}
} catch (FileUploadException e) {
throw new MultipartHandlingException("Error while processing multipart content: " + e);
}
}
Aggregations