use of org.nutz.mvc.upload.FastUploading in project nutz by nutzam.
the class WhaleFilter method handleUpload.
@SuppressWarnings("unchecked")
public HttpServletRequest handleUpload(HttpServletRequest req) throws ServletException {
try {
FastUploading fup = new FastUploading();
final Map<String, Object> params = fup.parse(req, (UploadingContext) uc);
final List<TempFile> files = new ArrayList<TempFile>();
Iterator<Entry<String, Object>> it = params.entrySet().iterator();
while (it.hasNext()) {
Object obj = it.next().getValue();
final boolean[] re = new boolean[1];
Lang.each(obj, new Each<Object>() {
public void invoke(int index, Object ele, int length) {
if (ele != null && ele instanceof TempFile) {
files.add((TempFile) ele);
re[0] = true;
}
}
});
if (re[0])
it.remove();
}
req.setAttribute("_files", files);
params.putAll(req.getParameterMap());
return new HttpServletRequestWrapper(req) {
public String getParameter(String name) {
return (String) params.get(name);
}
@SuppressWarnings("rawtypes")
public Map getParameterMap() {
return params;
}
@SuppressWarnings("rawtypes")
public Enumeration getParameterNames() {
return Collections.enumeration(params.keySet());
}
public String[] getParameterValues(String name) {
if (params.containsKey(name))
return new String[] { (String) params.get(name) };
return null;
}
};
} catch (UploadException e) {
throw new ServletException("upload fail", e);
}
}
Aggregations