示例#1
0
  /**
   * Process input from get file type page
   *
   * @param context current DSpace context
   * @param request current servlet request object
   * @param response current servlet response object
   * @param subInfo submission info object
   * @return Status or error flag which will be processed by UI-related code! (if STATUS_COMPLETE or
   *     0 is returned, no errors occurred!)
   */
  protected int processSaveFileFormat(
      Context context,
      HttpServletRequest request,
      HttpServletResponse response,
      SubmissionInfo subInfo)
      throws ServletException, IOException, SQLException, AuthorizeException {
    if (subInfo.getBitstream() != null) {
      // Did the user select a format?
      int typeID = Util.getIntParameter(request, "format");

      BitstreamFormat format = BitstreamFormat.find(context, typeID);

      if (format != null) {
        subInfo.getBitstream().setFormat(format);
      } else {
        String userDesc = request.getParameter("format_description");

        subInfo.getBitstream().setUserFormatDescription(userDesc);
      }

      // update database
      subInfo.getBitstream().update();
    } else {
      return STATUS_INTEGRITY_ERROR;
    }

    return STATUS_COMPLETE;
  }
示例#2
0
  /**
   * Process the input from the CC license page
   *
   * @param context current DSpace context
   * @param request current servlet request object
   * @param response current servlet response object
   * @param subInfo submission info object
   * @return Status or error flag which will be processed by doPostProcessing() below! (if
   *     STATUS_COMPLETE or 0 is returned, no errors occurred!)
   */
  protected int processCC(
      Context context,
      HttpServletRequest request,
      HttpServletResponse response,
      SubmissionInfo subInfo)
      throws ServletException, IOException, SQLException, AuthorizeException {
    String buttonPressed = Util.getSubmitButton(request, NEXT_BUTTON);

    // RLR hack - need to distinguish between progress bar real submission
    // (if cc_license_url exists, then users has accepted the CC License)
    String ccLicenseUrl = request.getParameter("cc_license_url");

    if (buttonPressed.equals("submit_no_cc")) {
      // Skipping the CC license - remove any existing license selection
      creativeCommonsService.removeLicense(context, subInfo.getSubmissionItem().getItem());
    } else if ((ccLicenseUrl != null) && (ccLicenseUrl.length() > 0)) {
      Item item = subInfo.getSubmissionItem().getItem();

      // save the CC license
      creativeCommonsService.setLicense(context, item, ccLicenseUrl);
    }

    // commit changes
    context.dispatchEvents();

    // completed without errors
    return STATUS_COMPLETE;
  }
示例#3
0
  protected Group checkGroup(Context context, HttpServletRequest request)
      throws ServletException, IOException, SQLException, AuthorizeException {

    // Find out if there's a group parameter
    int groupID = Util.getIntParameter(request, "group_id");
    Group group = null;

    if (groupID >= 0) {
      group = Group.find(context, groupID);
    }

    return group;
  } // end checkGroup
示例#4
0
 /**
  * Returns canonical link to a bitstream in the item.
  *
  * @param item The DSpace Item that the bitstream is part of
  * @param bitstream The bitstream to link to
  * @returns a String link to the bitstream
  */
 private String makeBitstreamLink(Item item, Bitstream bitstream) {
   String name = bitstream.getName();
   StringBuilder result = new StringBuilder(contextPath);
   result.append("/bitstream/item/").append(String.valueOf(item.getID()));
   // append name although it isn't strictly necessary
   try {
     if (name != null) {
       result.append("/").append(Util.encodeBitstreamName(name, "UTF-8"));
     }
   } catch (UnsupportedEncodingException uee) {
     // just ignore it, we don't have to have a pretty
     // name on the end of the url because the sequence id will
     // locate it. However it means that links in this file might
     // not work....
   }
   result.append("?sequence=").append(String.valueOf(bitstream.getSequenceID()));
   return result.toString();
 }
示例#5
0
 /**
  * Do any processing of the information input by the user, and/or perform step processing (if no
  * user interaction required)
  *
  * <p>It is this method's job to save any data to the underlying database, as necessary, and
  * return error messages (if any) which can then be processed by the appropriate user interface
  * (JSP-UI or XML-UI)
  *
  * <p>NOTE: If this step is a non-interactive step (i.e. requires no UI), then it should perform
  * *all* of its processing in this method!
  *
  * @param context current DSpace context
  * @param request current servlet request object
  * @param response current servlet response object
  * @param subInfo submission info object
  * @return Status or error flag which will be processed by doPostProcessing() below! (if
  *     STATUS_COMPLETE or 0 is returned, no errors occurred!)
  */
 @Override
 public int doProcessing(
     Context context,
     HttpServletRequest request,
     HttpServletResponse response,
     SubmissionInfo subInfo)
     throws ServletException, IOException, SQLException, AuthorizeException, java.io.IOException {
   HttpSession session = request.getSession();
   session.setAttribute("inProgress", "TRUE");
   // check what submit button was pressed in User Interface
   String buttonPressed = Util.getSubmitButton(request, NEXT_BUTTON);
   if ("submit_grant".equalsIgnoreCase(buttonPressed)
       || "submit_no_cc".equalsIgnoreCase(buttonPressed)) {
     return processCC(context, request, response, subInfo);
   }
   String choiceButton = Util.getSubmitButton(request, SELECT_CHANGE);
   Enumeration e = request.getParameterNames();
   String isFieldRequired = "FALSE";
   while (e.hasMoreElements()) {
     String parameterName = (String) e.nextElement();
     if (parameterName.equals("button_required")) {
       isFieldRequired = "TRUE";
       break;
     }
   }
   session.setAttribute("isFieldRequired", isFieldRequired);
   if (choiceButton.equals(SELECT_CHANGE)) {
     Item item = subInfo.getSubmissionItem().getItem();
     LicenseMetadataValue uriField = creativeCommonsService.getCCField("uri");
     LicenseMetadataValue nameField = creativeCommonsService.getCCField("name");
     String licenseUri = uriField.ccItemValue(item);
     if (licenseUri != null)
     // if (CreativeCommons.hasLicense(item, "dc", "rights", "uri", Item.ANY)
     //	&& !CreativeCommons.getRightsURI(item, "dc", "rights", "uri", Item.ANY).equals(""))
     {
       // CreativeCommons.setItemMetadata(item, licenseURI, "dc", "rights", "uri",
       // ConfigurationManager.getProperty("default.locale"));
       uriField.removeItemValue(context, item, licenseUri);
       if (ConfigurationManager.getBooleanProperty("cc.submit.setname")) {
         String licenseName = nameField.keyedItemValue(item, licenseUri);
         nameField.removeItemValue(context, item, licenseName);
         // CreativeCommons.setItemMetadata(item, CreativeCommons.getRightsName(item, "dc",
         // "rights", null, Item.ANY), "dc", "rights", null,
         // ConfigurationManager.getProperty("default.locale"));
       }
       if (ConfigurationManager.getBooleanProperty("cc.submit.addBitstream")) {
         creativeCommonsService.removeLicense(context, item);
       }
       removeRequiredAttributes(session);
       itemService.update(context, item);
       context.dispatchEvents();
     }
     return STATUS_COMPLETE;
   } else if (buttonPressed.startsWith(PROGRESS_BAR_PREFIX)
       || buttonPressed.equals(PREVIOUS_BUTTON)) {
     removeRequiredAttributes(session);
   }
   if (buttonPressed.equals(NEXT_BUTTON) || buttonPressed.equals(CANCEL_BUTTON)) {
     return processCCWS(context, request, response, subInfo);
   } else {
     removeRequiredAttributes(session);
     session.removeAttribute("inProgress");
     return STATUS_COMPLETE;
   }
 }
示例#6
0
  @RequestMapping(method = RequestMethod.POST)
  protected String processPost(
      @RequestAttribute Context context,
      ModelMap model,
      HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException, SQLException, AuthorizeException {

    Group group = null;
    group = checkGroup(context, request);

    if (group != null) {

      // is this user authorized to edit this group?
      AuthorizeManager.authorizeAction(context, group, Constants.ADD);

      boolean submit_edit = (request.getParameter("submit_edit") != null);
      boolean submit_group_update = (request.getParameter("submit_group_update") != null);
      boolean submit_group_delete = (request.getParameter("submit_group_delete") != null);
      boolean submit_confirm_delete = (request.getParameter("submit_confirm_delete") != null);
      boolean submit_cancel_delete = (request.getParameter("submit_cancel_delete") != null);

      // just chosen a group to edit - get group and pass it to
      // group-edit.jsp
      if (submit_edit && !submit_group_update && !submit_group_delete) {
        model.addAttribute("group", group);
        model.addAttribute("members", group.getMembers());
        model.addAttribute("membergroups", group.getMemberGroups());
        String utilsGrpName = Utils.addEntities(group.getName());
        model.addAttribute("utilsGrpName", utilsGrpName);

        return "pages/admin/group-edit";
      } // update the members of the group
      else if (submit_group_update) {
        // first off, did we change the group name?
        String newName = request.getParameter("group_name");

        if (!newName.equals(group.getName())) {
          group.setName(newName);
          group.update();
        }

        int[] eperson_ids = Util.getIntParameters(request, "eperson_id");
        int[] group_ids = Util.getIntParameters(request, "group_ids");

        // now get members, and add new ones and remove missing ones
        EPerson[] members = group.getMembers();
        Group[] membergroups = group.getMemberGroups();

        if (eperson_ids != null) {
          // some epeople were listed, now make group's epeople match
          // given epeople
          Set memberSet = new HashSet();
          Set epersonIDSet = new HashSet();

          // add all members to a set
          for (int x = 0; x < members.length; x++) {
            Integer epersonID = Integer.valueOf(members[x].getID());
            memberSet.add(epersonID);
          }

          // now all eperson_ids are put in a set
          for (int x = 0; x < eperson_ids.length; x++) {
            epersonIDSet.add(Integer.valueOf(eperson_ids[x]));
          }

          // process eperson_ids, adding those to group not already
          // members
          Iterator i = epersonIDSet.iterator();

          while (i.hasNext()) {
            Integer currentID = (Integer) i.next();

            if (!memberSet.contains(currentID)) {
              group.addMember(EPerson.find(context, currentID.intValue()));
            }
          }

          // process members, removing any that aren't in eperson_ids
          for (int x = 0; x < members.length; x++) {
            EPerson e = members[x];

            if (!epersonIDSet.contains(Integer.valueOf(e.getID()))) {
              group.removeMember(e);
            }
          }
        } else {
          // no members found (ids == null), remove them all!

          for (int y = 0; y < members.length; y++) {
            group.removeMember(members[y]);
          }
        }

        if (group_ids != null) {
          // some groups were listed, now make group's member groups
          // match given group IDs
          Set memberSet = new HashSet();
          Set groupIDSet = new HashSet();

          // add all members to a set
          for (int x = 0; x < membergroups.length; x++) {
            Integer myID = Integer.valueOf(membergroups[x].getID());
            memberSet.add(myID);
          }

          // now all eperson_ids are put in a set
          for (int x = 0; x < group_ids.length; x++) {
            groupIDSet.add(Integer.valueOf(group_ids[x]));
          }

          // process group_ids, adding those to group not already
          // members
          Iterator i = groupIDSet.iterator();

          while (i.hasNext()) {
            Integer currentID = (Integer) i.next();

            if (!memberSet.contains(currentID)) {
              group.addMember(Group.find(context, currentID.intValue()));
            }
          }

          // process members, removing any that aren't in eperson_ids
          for (int x = 0; x < membergroups.length; x++) {
            Group g = membergroups[x];

            if (!groupIDSet.contains(Integer.valueOf(g.getID()))) {
              group.removeMember(g);
            }
          }

        } else {
          // no members found (ids == null), remove them all!
          for (int y = 0; y < membergroups.length; y++) {
            group.removeMember(membergroups[y]);
          }
        }

        group.update();

        model.addAttribute("group", group);
        model.addAttribute("members", group.getMembers());
        model.addAttribute("membergroups", group.getMemberGroups());
        String utilsGrpName = Utils.addEntities(group.getName());
        model.addAttribute("utilsGrpName", utilsGrpName);

        context.commit();
        return "pages/admin/group-edit";
      } else if (submit_group_delete) {
        // direct to a confirmation step
        model.addAttribute("group", group);
        return "pages/admin/group-confirm-delete";
      } else if (submit_confirm_delete) {
        // phony authorize, only admins can do this
        AuthorizeManager.authorizeAction(context, group, Constants.WRITE);

        // delete group, return to group-list.jsp
        group.delete();

        return showMainPage(context, model, request, response);
      } else if (submit_cancel_delete) {
        // show group list
        return showMainPage(context, model, request, response);
      } else {
        // unknown action, show edit page
        model.addAttribute("group", group);
        model.addAttribute("members", group.getMembers());
        model.addAttribute("membergroups", group.getMemberGroups());
        String utilsGrpName = Utils.addEntities(group.getName());
        model.addAttribute("utilsGrpName", utilsGrpName);

        return "pages/admin/group-edit";
      }
    } else {

      // want to add a group - create a blank one, and pass to
      // group_edit.jsp
      String button = UIUtil.getSubmitButton(request, "submit");

      if (button.equals("submit_add")) {
        group = Group.create(context);

        group.setName("new group" + group.getID());
        group.update();

        model.addAttribute("group", group);
        model.addAttribute("members", group.getMembers());
        model.addAttribute("membergroups", group.getMemberGroups());
        String utilsGrpName = Utils.addEntities(group.getName());
        model.addAttribute("utilsGrpName", utilsGrpName);

        context.commit();
        return "pages/admin/group-edit";

      } else {
        // show the main page (select groups)
        return showMainPage(context, model, request, response);
      }
    } // end
  } // end processGet
示例#7
0
  /**
   * Generate a METS file element for a given bitstream.
   *
   * @param context
   * @param item If the bitstream is associated with an item, provide the item, otherwise leave
   *     null.
   * @param bitstream The bitstream to build a file element for.
   * @param fileID The unique file id for this file.
   * @param groupID The group id for this file, if it is derived from another file then they should
   *     share the same groupID.
   * @param admID The IDs of the administrative metadata sections which pertain to this file
   * @throws org.xml.sax.SAXException passed through.
   * @throws java.sql.SQLException passed through.
   */
  protected final void renderFile(
      Context context, Item item, Bitstream bitstream, String fileID, String groupID, String admID)
      throws SAXException, SQLException {
    AttributeMap attributes;

    // //////////////////////////////
    // Determine the file attributes
    BitstreamFormat format = bitstream.getFormat(context);
    String mimeType = null;
    if (format != null) {
      mimeType = format.getMIMEType();
    }
    String checksumType = bitstream.getChecksumAlgorithm();
    String checksum = bitstream.getChecksum();
    long size = bitstream.getSize();

    // ////////////////////////////////
    // Start the actual file
    attributes = new AttributeMap();
    attributes.put("ID", fileID);
    attributes.put("GROUPID", groupID);
    if (admID != null && admID.length() > 0) {
      attributes.put("ADMID", admID);
    }
    if (mimeType != null && mimeType.length() > 0) {
      attributes.put("MIMETYPE", mimeType);
    }
    if (checksumType != null && checksum != null) {
      attributes.put("CHECKSUM", checksum);
      attributes.put("CHECKSUMTYPE", checksumType);
    }
    attributes.put("SIZE", String.valueOf(size));
    startElement(METS, "file", attributes);

    // ////////////////////////////////////
    // Determine the file location attributes
    String name = bitstream.getName();
    String description = bitstream.getDescription();

    // If possible, reference this bitstream via a handle, however this may
    // be null if a handle has not yet been assigned. In this case reference the
    // item its internal id. In the last case where the bitstream is not associated
    // with an item (such as a community logo) then reference the bitstreamID directly.
    String identifier = null;
    if (item != null && item.getHandle() != null) {
      identifier = "handle/" + item.getHandle();
    } else if (item != null) {
      identifier = "item/" + item.getID();
    } else {
      identifier = "id/" + bitstream.getID();
    }

    String url = contextPath + "/bitstream/" + identifier + "/";

    // If we can, append the pretty name of the bitstream to the URL
    try {
      if (bitstream.getName() != null) {
        url += Util.encodeBitstreamName(bitstream.getName(), "UTF-8");
      }
    } catch (UnsupportedEncodingException uee) {
      // just ignore it, we don't have to have a pretty
      // name at the end of the URL because the sequence id will
      // locate it. However it means that links in this file might
      // not work....
    }

    url += "?sequence=" + bitstream.getSequenceID();

    // //////////////////////
    // Start the file location
    attributes = new AttributeMap();
    AttributeMap attributesXLINK = new AttributeMap();
    attributesXLINK.setNamespace(XLINK);
    attributes.put("LOCTYPE", "URL");
    attributesXLINK.put("type", "locator");
    attributesXLINK.put("title", name);
    if (description != null) {
      attributesXLINK.put("label", description);
    }
    attributesXLINK.put("href", url);
    startElement(METS, "FLocat", attributes, attributesXLINK);

    // ///////////////////////
    // End file location
    endElement(METS, "FLocate");

    // ////////////////////////////////
    // End the file
    endElement(METS, "file");
  }
  protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // dispense with simple service document requests
    String scope = request.getParameter("scope");
    if (scope != null && "".equals(scope)) {
      scope = null;
    }
    String path = request.getPathInfo();
    if (path != null && path.endsWith("description.xml")) {
      String svcDescrip = OpenSearch.getDescription(scope);
      response.setContentType(OpenSearch.getContentType("opensearchdescription"));
      response.setContentLength(svcDescrip.length());
      response.getWriter().write(svcDescrip);
      return;
    }

    // get enough request parameters to decide on action to take
    String format = request.getParameter("format");
    if (format == null || "".equals(format)) {
      // default to atom
      format = "atom";
    }

    // do some sanity checking
    if (!OpenSearch.getFormats().contains(format)) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // then the rest - we are processing the query
    String query = request.getParameter("query");
    int start = Util.getIntParameter(request, "start");
    int rpp = Util.getIntParameter(request, "rpp");
    int sort = Util.getIntParameter(request, "sort_by");
    String order = request.getParameter("order");
    String sortOrder =
        (order == null || order.length() == 0 || order.toLowerCase().startsWith("asc"))
            ? SortOption.ASCENDING
            : SortOption.DESCENDING;

    QueryArgs qArgs = new QueryArgs();
    // can't start earlier than 0 in the results!
    if (start < 0) {
      start = 0;
    }
    qArgs.setStart(start);

    if (rpp > 0) {
      qArgs.setPageSize(rpp);
    }
    qArgs.setSortOrder(sortOrder);

    if (sort > 0) {
      try {
        qArgs.setSortOption(SortOption.getSortOption(sort));
      } catch (Exception e) {
        // invalid sort id - do nothing
      }
    }
    qArgs.setSortOrder(sortOrder);

    // Ensure the query is non-null
    if (query == null) {
      query = "";
    }

    // If there is a scope parameter, attempt to dereference it
    // failure will only result in its being ignored
    DSpaceObject container = (scope != null) ? HandleManager.resolveToObject(context, scope) : null;

    // Build log information
    String logInfo = "";

    // get the start of the query results page
    qArgs.setQuery(query);

    // Perform the search
    QueryResults qResults = null;
    if (container == null) {
      qResults = DSQuery.doQuery(context, qArgs);
    } else if (container instanceof Collection) {
      logInfo = "collection_id=" + container.getID() + ",";
      qResults = DSQuery.doQuery(context, qArgs, (Collection) container);
    } else if (container instanceof Community) {
      logInfo = "community_id=" + container.getID() + ",";
      qResults = DSQuery.doQuery(context, qArgs, (Community) container);
    }

    // now instantiate the results
    DSpaceObject[] results = new DSpaceObject[qResults.getHitHandles().size()];
    for (int i = 0; i < qResults.getHitHandles().size(); i++) {
      String myHandle = (String) qResults.getHitHandles().get(i);
      DSpaceObject dso = HandleManager.resolveToObject(context, myHandle);
      if (dso == null) {
        throw new SQLException("Query \"" + query + "\" returned unresolvable handle: " + myHandle);
      }
      results[i] = dso;
    }

    // Log
    log.info(
        LogManager.getHeader(
            context,
            "search",
            logInfo + "query=\"" + query + "\",results=(" + results.length + ")"));

    // format and return results
    Map<String, String> labelMap = getLabels(request);
    Document resultsDoc =
        OpenSearch.getResultsDoc(format, query, qResults, container, results, labelMap);
    try {
      Transformer xf = TransformerFactory.newInstance().newTransformer();
      response.setContentType(OpenSearch.getContentType(format));
      xf.transform(new DOMSource(resultsDoc), new StreamResult(response.getWriter()));
    } catch (TransformerException e) {
      log.error(e);
      throw new ServletException(e.toString());
    }
  }
示例#9
0
  /** Insure that the context path is added to the page meta. */
  public void addPageMeta(PageMeta pageMeta)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    // FIXME: I don't think these should be set here, but there needed and I'm
    // not sure where else it could go. Perhaps the linkResolver?
    Request request = ObjectModelHelper.getRequest(objectModel);
    pageMeta.addMetadata("contextPath").addContent(contextPath);
    pageMeta.addMetadata("request", "queryString").addContent(request.getQueryString());
    pageMeta.addMetadata("request", "scheme").addContent(request.getScheme());
    pageMeta.addMetadata("request", "serverPort").addContent(request.getServerPort());
    pageMeta.addMetadata("request", "serverName").addContent(request.getServerName());
    pageMeta.addMetadata("request", "URI").addContent(request.getSitemapURI());

    String dspaceVersion = Util.getSourceVersion();
    if (dspaceVersion != null) {
      pageMeta.addMetadata("dspace", "version").addContent(dspaceVersion);
    }

    String analyticsKey = ConfigurationManager.getProperty("xmlui.google.analytics.key");
    if (analyticsKey != null && analyticsKey.length() > 0) {
      analyticsKey = analyticsKey.trim();
      pageMeta.addMetadata("google", "analytics").addContent(analyticsKey);
    }

    // add metadata for OpenSearch auto-discovery links if enabled
    if (ConfigurationManager.getBooleanProperty("websvc.opensearch.autolink")) {
      pageMeta
          .addMetadata("opensearch", "shortName")
          .addContent(ConfigurationManager.getProperty("websvc.opensearch.shortname"));
      pageMeta
          .addMetadata("opensearch", "context")
          .addContent(ConfigurationManager.getProperty("websvc.opensearch.svccontext"));
    }

    // Add metadata for quick searches:
    pageMeta.addMetadata("search", "simpleURL").addContent(contextPath + "/search");
    pageMeta.addMetadata("search", "advancedURL").addContent(contextPath + "/advanced-search");
    pageMeta.addMetadata("search", "queryField").addContent("query");

    pageMeta.addMetadata("page", "contactURL").addContent(contextPath + "/contact");
    pageMeta.addMetadata("page", "feedbackURL").addContent(contextPath + "/feedback");

    // Add the locale meta data including language dependant labels
    Locale[] locales = I18nUtil.getSupportedLocales();
    for (int i = 0; i < locales.length; i++) {
      pageMeta.addMetadata("page", "supportedLocale").addContent(locales[i].toString());
      // now add the appropriate labels
      pageMeta
          .addMetadata("supportedLocale", locales[i].toString())
          .addContent(locales[i].getDisplayName(locales[i]));
    }

    pageMeta.addMetadata("page", "currentLocale").addContent(context.getCurrentLocale().toString());

    DSpaceObject dso = HandleUtil.obtainHandle(objectModel);
    if (dso != null) {
      if (dso instanceof Item) {
        pageMeta.addMetadata("focus", "object").addContent("hdl:" + dso.getHandle());
        this.getObjectManager().manageObject(dso);
        dso = ((Item) dso).getOwningCollection();
      }

      if (dso instanceof Collection || dso instanceof Community) {
        pageMeta.addMetadata("focus", "container").addContent("hdl:" + dso.getHandle());
        this.getObjectManager().manageObject(dso);
      }
    }
  }
示例#10
0
  /**
   * Do any processing of the information input by the user, and/or perform step processing (if no
   * user interaction required)
   *
   * <p>It is this method's job to save any data to the underlying database, as necessary, and
   * return error messages (if any) which can then be processed by the appropriate user interface
   * (JSP-UI or XML-UI)
   *
   * <p>NOTE: If this step is a non-interactive step (i.e. requires no UI), then it should perform
   * *all* of its processing in this method!
   *
   * @param context current DSpace context
   * @param request current servlet request object
   * @param response current servlet response object
   * @param subInfo submission info object
   * @return Status or error flag which will be processed by doPostProcessing() below! (if
   *     STATUS_COMPLETE or 0 is returned, no errors occurred!)
   */
  public int doProcessing(
      Context context,
      HttpServletRequest request,
      HttpServletResponse response,
      SubmissionInfo subInfo)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // get button user pressed
    String buttonPressed = Util.getSubmitButton(request, NEXT_BUTTON);

    // get reference to item
    Item item = subInfo.getSubmissionItem().getItem();

    // -----------------------------------
    // Step #0: Upload new files (if any)
    // -----------------------------------
    String contentType = request.getContentType();

    // if multipart form, then we are uploading a file
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") != -1)) {
      // This is a multipart request, so it's a file upload
      // (return any status messages or errors reported)
      int status = processUploadFile(context, request, response, subInfo);

      // if error occurred, return immediately
      if (status != STATUS_COMPLETE) {
        return status;
      }
    }

    // if user pressed jump-to button in process bar,
    // return success (so that jump will occur)
    if (buttonPressed.startsWith(PROGRESS_BAR_PREFIX)) {
      // check if a file is required to be uploaded
      if (fileRequired && !item.hasUploadedFiles()) {
        return STATUS_NO_FILES_ERROR;
      } else {
        return STATUS_COMPLETE;
      }
    }

    // ---------------------------------------------
    // Step #1: Check if this was just a request to
    // edit file information.
    // (or canceled editing information)
    // ---------------------------------------------
    // check if we're already editing a specific bitstream
    if (request.getParameter("bitstream_id") != null) {
      if (buttonPressed.equals(CANCEL_EDIT_BUTTON)) {
        // canceled an edit bitstream request
        subInfo.setBitstream(null);

        // this flag will just return us to the normal upload screen
        return STATUS_EDIT_COMPLETE;
      } else {
        // load info for bitstream we are editing
        Bitstream b =
            Bitstream.find(context, Integer.parseInt(request.getParameter("bitstream_id")));

        // save bitstream to submission info
        subInfo.setBitstream(b);
      }
    } else if (buttonPressed.startsWith("submit_edit_")) {
      // get ID of bitstream that was requested for editing
      String bitstreamID = buttonPressed.substring("submit_edit_".length());

      Bitstream b = Bitstream.find(context, Integer.parseInt(bitstreamID));

      // save bitstream to submission info
      subInfo.setBitstream(b);

      // return appropriate status flag to say we are now editing the
      // bitstream
      return STATUS_EDIT_BITSTREAM;
    }

    // ---------------------------------------------
    // Step #2: Process any remove file request(s)
    // ---------------------------------------------
    // Remove-selected requests come from Manakin
    if (buttonPressed.equalsIgnoreCase("submit_remove_selected")) {
      // this is a remove multiple request!

      if (request.getParameter("remove") != null) {
        // get all files to be removed
        String[] removeIDs = request.getParameterValues("remove");

        // remove each file in the list
        for (int i = 0; i < removeIDs.length; i++) {
          int id = Integer.parseInt(removeIDs[i]);

          int status = processRemoveFile(context, item, id);

          // if error occurred, return immediately
          if (status != STATUS_COMPLETE) {
            return status;
          }
        }

        // remove current bitstream from Submission Info
        subInfo.setBitstream(null);
      }
    } else if (buttonPressed.startsWith("submit_remove_")) {
      // A single file "remove" button must have been pressed

      int id = Integer.parseInt(buttonPressed.substring(14));
      int status = processRemoveFile(context, item, id);

      // if error occurred, return immediately
      if (status != STATUS_COMPLETE) {
        return status;
      }

      // remove current bitstream from Submission Info
      subInfo.setBitstream(null);
    }

    // -------------------------------------------------
    // Step #3: Check for a change in file description
    // -------------------------------------------------
    String fileDescription = request.getParameter("description");

    if (fileDescription != null && fileDescription.length() > 0) {
      // save this file description
      int status = processSaveFileDescription(context, request, response, subInfo);

      // if error occurred, return immediately
      if (status != STATUS_COMPLETE) {
        return status;
      }
    }

    // ------------------------------------------
    // Step #4: Check for a file format change
    // (if user had to manually specify format)
    // ------------------------------------------
    int formatTypeID = Util.getIntParameter(request, "format");
    String formatDesc = request.getParameter("format_description");

    // if a format id or description was found, then save this format!
    if (formatTypeID >= 0 || (formatDesc != null && formatDesc.length() > 0)) {
      // save this specified format
      int status = processSaveFileFormat(context, request, response, subInfo);

      // if error occurred, return immediately
      if (status != STATUS_COMPLETE) {
        return status;
      }
    }

    // ---------------------------------------------------
    // Step #5: Check if primary bitstream has changed
    // -------------------------------------------------
    if (request.getParameter("primary_bitstream_id") != null) {
      Bundle[] bundles = item.getBundles("ORIGINAL");
      if (bundles.length > 0) {
        bundles[0].setPrimaryBitstreamID(
            Integer.valueOf(request.getParameter("primary_bitstream_id")).intValue());
        bundles[0].update();
      }
    }

    // ---------------------------------------------------
    // Step #6: Determine if there is an error because no
    // files have been uploaded.
    // ---------------------------------------------------
    // check if a file is required to be uploaded
    if (fileRequired && !item.hasUploadedFiles()) {
      return STATUS_NO_FILES_ERROR;
    }

    // commit all changes to database
    context.commit();

    return STATUS_COMPLETE;
  }