protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    super.doPost(request, response);

    try {
      if (!ServletFileUpload.isMultipartContent(request)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
      }

      ServletFileUpload sfU = new ServletFileUpload();
      FileItemIterator items = sfU.getItemIterator(request);
      while (items.hasNext()) {
        FileItemStream item = items.next();
        if (!item.isFormField()) {
          InputStream stream = item.openStream();
          Document doc = editor.toDocument(stream);
          stream.close();
          handleDocument(request, response, doc);
          return;
        }
      }

      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No XML uploaded");
    } catch (FileUploadException fuE) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, fuE.getMessage());
    } catch (JDOMException jE) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, jE.getMessage());
    }
  }
 private int countBytes(InputStream is) {
   int nrBytes = 0;
   byte[] buf = new byte[10000];
   int len = 0;
   //	StringBuffer sb = new StringBuffer(1000);
   try {
     while ((len = is.read(buf)) != -1) {
       nrBytes += len; // resultCount counts the returned bytes
       //			String temp = new String(buf,0,len);
       //			temp = "\n\n" + temp + "\n\n";
       //			logger.log(Level.ALL, temp);
       //			sb.append(temp);
     }
   } catch (IOException e) {
     System.err.println("Could not read result from input stream");
   }
   //	System.out.println(sb.toString());
   return nrBytes;
 }