/** Processes a file uploaded from the client.
*/
public void service(
HttpServletRequest request, HttpServletResponse response, String pathInfo)
throws ServletException, IOException {
final Session sess = Sessions.getCurrent(false);
if (sess == null) {
response.setIntHeader("ZK-Error", HttpServletResponse.SC_GONE);
return;
}
final Map attrs = new HashMap();
String alert = null, uuid = null, nextURI = null, sid = null;
Desktop desktop = null;
try {
if (!isMultipartContent(request)) {
if ("uploadInfo".equals(request.getParameter("cmd"))) {
uuid = request.getParameter("wid");
sid = request.getParameter("sid");
desktop = ((WebAppCtrl)sess.getWebApp()).getDesktopCache(sess).getDesktop(request.getParameter("dtid"));
Map precent = (Map) desktop.getAttribute(Attributes.UPLOAD_PERCENT);
Map size = (Map)desktop.getAttribute(Attributes.UPLOAD_SIZE);
final String key = uuid + '_' + sid;
Object sinfo = size.get(key);
if (sinfo instanceof String) {
response.getWriter().append("error:" + sinfo);
size.remove(key);
precent.remove(key);
return;
}
final Integer p = (Integer)precent.get(key);
final Long cb = (Long)sinfo;
response.getWriter().append((p != null ? p.intValue(): -1)+ ","
+(cb != null ? cb.longValue(): -1));
return;
} else
alert = "enctype must be multipart/form-data";
} else {
uuid = request.getParameter("uuid");
sid = request.getParameter("sid");
if (uuid == null || uuid.length() == 0) {
alert = "uuid is required!";
} else {
attrs.put("uuid", uuid);
attrs.put("sid", sid);
final String dtid = request.getParameter("dtid");
if (dtid == null || dtid.length() == 0) {
alert = "dtid is required!";
} else {
desktop = ((WebAppCtrl)sess.getWebApp())
.getDesktopCache(sess).getDesktop(dtid);
final Map params = parseRequest(request, desktop, uuid + '_' + sid);
nextURI = (String)params.get("nextURI");
// Bug 3054784