/**
   * Change handle prefix. It is assumed that the user has already confirmed this selection.
   *
   * @param context The current DSpace context.
   * @param oldPrefix The prefix to be replace.
   * @param newPrefix The prefix to be used.
   * @param archiveOldHandles Should the former handles be archived?
   * @return A results object.
   */
  public static FlowResult changeHandlePrefix(
      Context context, String oldPrefix, String newPrefix, boolean archiveOldHandles)
      throws SQLException, AuthorizeException, IOException {
    FlowResult result = new FlowResult();

    result.setContinue(false);
    result.setOutcome(false);

    // If we have errors, the form needs to be resubmitted to fix those problems
    if (StringUtils.isEmpty(oldPrefix)) {
      result.addError("old_prefix_empty");
    }
    if (StringUtils.isEmpty(newPrefix)) {
      result.addError("new_prefix_empty");
    }
    if (result.getErrors() == null && oldPrefix.equals(newPrefix)) {
      result.addError("old_prefix_equals_new_prefix");
    }

    if (result.getErrors() == null) {
      try {
        // change prefixes
        HandleManager.changePrefix(context, oldPrefix, newPrefix, archiveOldHandles);
        context.commit();

        // reindex
        IndexBrowse.main(new String[] {"-i"});

        result.setContinue(true);
        result.setOutcome(true);
        result.setMessage(T_prefix_successfully_changed);

      } catch (Exception e) {
        result.setMessage(T_prefix_change_failed);
        log.error(e.getMessage());
        context.abort();
      }
    }

    return result;
  }