@Override
  protected ModelAndView processFinish(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors)
      throws Exception {
    log.debug("processFinish: Save the Rx content item.");
    String contentid = request.getParameter(IPSHtmlParameters.SYS_CONTENTID);
    log.debug("processFinish: content id is " + contentid);
    String folderid = request.getParameter(IPSHtmlParameters.SYS_FOLDERID);
    log.debug("processFinish: folder id is " + folderid);
    String actionParam = request.getParameter("action");
    log.debug("processFinish: action is " + actionParam);

    Boolean closeWindow = new Boolean(false);

    UserSessionData usd = getUserSessionData(request);
    MasterImageMetaData mimd = usd.getMimd();

    String user = RxRequestUtils.getUserName(request);
    log.debug("processFinish: user is " + user);
    String session = RxRequestUtils.getSessionId(request);
    log.debug("processFinish: session is " + session);

    // remove any empty images (this can happen if the user
    // presses "finish" part way through the process).
    Map<String, SizedImageMetaData> sized = mimd.getSizedImages();
    mimd.setSizedImages(cleanEmptySizedImages(sized));

    if (StringUtils.isNotBlank(contentid)) {
      imagePersistenceManager.UpdateImage(mimd, contentid, null, session, user);
      log.debug("processFinish: mimd persisted to existing Rx item: " + contentid);
    } else {
      if (StringUtils.isBlank(folderid)) folderid = null;

      contentid = imagePersistenceManager.CreateImage(mimd, folderid, false, session, user);
      log.debug("processFinish: the contentid of the new item is: " + contentid);
    }
    // everything is saved now...
    usd.setDirty(false);
    String redirectUrl = "imageeditor?sys_contentid=" + contentid + "&sys_folderid=" + folderid;
    ModelAndView mav = new ModelAndView("results");
    mav.addObject("image", command);
    if (actionParam.equalsIgnoreCase("close")) {
      log.debug("processFinish: closing window");
      redirectUrl = "";
      closeWindow = new Boolean(true);
    }
    mav.addObject("redirectUrl", redirectUrl);
    mav.addObject("closeWindow", closeWindow);
    mav.addObject("contentid", contentid);
    return mav;
  }
  public void setupSizedImages(
      HttpServletRequest request, String sizedImages, MasterImageMetaData mimd) {
    Collection<SizedImageMetaData> simds = mimd.getSizedImages().values();

    UserSessionData usd = getUserSessionData(request);
    if (!StringUtils.isBlank(sizedImages)) {
      log.debug("setupSizedImages: Handling the sized images...");
      // Images have been selected and we didn't have any images stored previously
      String[] sizedImagesArray = sizedImages.split(",");
      log.debug(
          "setupSizedImages: the bean has " + sizedImagesArray.length + " sized image(s) selected");

      if (simds.size() == 0) {
        log.debug("setupSizedImages: no simds were previously defined");
        for (int x = 1; x <= sizedImagesArray.length; x++) {
          SizedImageMetaData simd = new SizedImageMetaData();
          ImageSizeDefinition isd = imageSizeDefMgr.getImageSize(sizedImagesArray[x - 1]);
          simd.setSizeDefinition(isd);
          mimd.addSizedImage(simd);
          log.debug("setupSizedImages: adding new image size " + isd.getLabel());
          usd.setDirty(true);
        }

      } else
      // Images have been selected and there were others stored previously
      {
        log.debug("setupSizedImages: simds have been previously defined");

        Map<String, SizedImageMetaData> previousSimds = mimd.getSizedImages();
        Map<String, SizedImageMetaData> newSimds = new HashMap<String, SizedImageMetaData>();

        for (int x = 0; x < sizedImagesArray.length; x++) {
          SizedImageMetaData simd = null;

          String key = sizedImagesArray[x];
          if (previousSimds.containsKey(key)) {
            simd = previousSimds.get(key);
            log.debug(
                "setupSizedImages: Image of type ["
                    + key
                    + "] previously chosen, re-using existing one");
            previousSimds.remove(key);
          } else {
            simd = new SizedImageMetaData();
            ImageSizeDefinition isd = imageSizeDefMgr.getImageSize(key);
            simd.setSizeDefinition(isd);
            log.debug(
                "setupSizedImages: Image of type ["
                    + key
                    + "] not previously chosen, created a new one");
            usd.setDirty(true);
          }
          newSimds.put(simd.getSizeDefinition().getCode(), simd);
        }
        mimd.setSizedImages(newSimds);
        if (previousSimds.size() > 0) { // some SIMDs were "left over", something has changed.
          usd.setDirty(true);
        }
      }

      log.debug("setupSizedImages: Sized Images in MIMD: " + mimd.getSizedImages().size());
    } else {
      if (simds.size() > 0) {
        log.debug(
            "setupSizedImages: There were sized images selected, but none have been selected now, so clearing out sized images");
        mimd.setSizedImages(new LinkedHashMap<String, SizedImageMetaData>());
        usd.setDirty(true);
      }
    }
  }