public Gallery getGallery(Integer id) {
   Gallery template = (Gallery) getEnvironment().getEntityFactory().create("diary-gallery");
   template.setId(id);
   Gallery gallery =
       (Gallery)
           getEnvironment().getEntityStorageFactory().getStorage("diary-gallery").load(template);
   return gallery;
 }
  protected void executeLogic(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    SelectGalleryFB fb = (SelectGalleryFB) form;
    Gallery gallery = getGallery(fb.getGallery());
    GalleryPB pbGallery = new GalleryPB();
    PropertyUtils.copyProperties(pbGallery, gallery);

    String username = request.getRemoteUser();
    if (username == null) {
      username = fb.getUser();
    }
    Map parameters = new HashMap();
    parameters.put("gallery", gallery.getId());
    parameters.put("user", username);
    ActionForward forward = mapping.findForward("update-gallery-link");
    if (forward != null) {
      pbGallery.setUpdateLink(
          ServletParameterHelper.replaceDynamicParameters(forward.getPath(), parameters));
    }
    forward = mapping.findForward("delete-gallery-link");
    if (forward != null) {
      pbGallery.setRemoveLink(
          ServletParameterHelper.replaceDynamicParameters(forward.getPath(), parameters));
    }
    if (gallery.getGallery() != null && gallery.getGallery().intValue() != 0) {
      request.setAttribute("galleryInfoPB", pbGallery);
      request.setAttribute("externalgallery", gallery.getGallery());
      return;
    } else {
      forward = mapping.findForward("new-picture-link");
      if (forward != null) {
        pbGallery.setNewEntryLink(
            ServletParameterHelper.replaceDynamicParameters(forward.getPath(), parameters));
      }
      request.setAttribute("galleryInfoPB", pbGallery);

      QueryFilter filter = new QueryFilter("allforgallery");
      filter.setAttribute("gallery", fb.getGallery());
      EntityInterface[] entities =
          getEnvironment()
              .getEntityStorageFactory()
              .getStorage("diary-galleryentry")
              .search(filter);

      ActionForward updateForward = mapping.findForward("update-picture-link");
      ActionForward deleteForward = mapping.findForward("delete-picture-link");
      GalleryEntryPB[] pbPictures = new GalleryEntryPB[entities.length];
      for (int i = 0; i < entities.length; i++) {
        pbPictures[i] = new GalleryEntryPB();
        PropertyUtils.copyProperties(pbPictures[i], entities[i]);
        parameters.put("picture", pbPictures[i].getId());
        if (updateForward != null) {
          pbPictures[i].setUpdateLink(
              ServletParameterHelper.replaceDynamicParameters(updateForward.getPath(), parameters));
        }
        if (deleteForward != null) {
          pbPictures[i].setRemoveLink(
              ServletParameterHelper.replaceDynamicParameters(deleteForward.getPath(), parameters));
        }
      }
      GalleryEntryCollectionPB pb = new GalleryEntryCollectionPB();
      pb.setPictures(pbPictures);
      request.setAttribute("picturesPB", pb);
    }
  }