public void deleteShare(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    try {
      request = wrapRequest(request);
      User user = securityService.getCurrentUser(request);
      int id = ServletRequestUtils.getRequiredIntParameter(request, "id");

      Share share = shareService.getShareById(id);
      if (share == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Shared media not found.");
        return;
      }
      if (!user.isAdminRole() && !share.getUsername().equals(user.getUsername())) {
        error(
            request, response, ErrorCode.NOT_AUTHORIZED, "Not authorized to delete shared media.");
        return;
      }

      shareService.deleteShare(id);
      XMLBuilder builder = createXMLBuilder(request, response, true).endAll();
      response.getWriter().print(builder);

    } catch (ServletRequestBindingException x) {
      error(request, response, ErrorCode.MISSING_PARAMETER, getErrorMessage(x));
    } catch (Exception x) {
      LOG.warn("Error in REST API.", x);
      error(request, response, ErrorCode.GENERIC, getErrorMessage(x));
    }
  }
  private String handleParameters(HttpServletRequest request) {
    User user = securityService.getCurrentUser(request);
    for (Share share : shareService.getSharesForUser(user)) {
      int id = share.getId();

      String description = getParameter(request, "description", id);
      boolean delete = getParameter(request, "delete", id) != null;
      String expireIn = getParameter(request, "expireIn", id);

      if (delete) {
        shareService.deleteShare(id);
      } else {
        if (expireIn != null) {
          share.setExpires(parseExpireIn(expireIn));
        }
        share.setDescription(description);
        shareService.updateShare(share);
      }
    }

    return null;
  }