/** Removes attachments created on volatile resources that have not been persisted. */
 private void deleteAllAttachments() {
   for (Map.Entry<ForeignPK, Object> componentResource : componentResources.entrySet()) {
     AttachmentServiceProvider.getAttachmentService()
         .deleteAllAttachments(
             componentResource.getKey().getId(), componentResource.getKey().getInstanceId());
   }
 }
  @Override
  public String getDestination(String objectId, HttpServletRequest req, HttpServletResponse res)
      throws Exception {
    MainSessionController mainSessionCtrl = util.getMainSessionController(req);
    String language = I18NHelper.defaultLanguage;
    if (mainSessionCtrl != null) {
      language = mainSessionCtrl.getFavoriteLanguage();
    }
    SimpleDocumentPK pk = new SimpleDocumentPK(objectId);
    if (StringUtil.isLong(objectId)) {
      pk.setOldSilverpeasId(Long.parseLong(objectId));
    }

    SimpleDocument attachment =
        AttachmentServiceProvider.getAttachmentService().searchDocumentById(pk, language);
    if (attachment == null) {
      return null;
    }
    String componentId = attachment.getInstanceId();
    String foreignId = attachment.getForeignId();

    if (isUserLogin(req) && isUserAllowed(req, componentId)) {
      boolean isAccessAuthorized = true;
      if (componentId.startsWith("kmelia")) {
        try {
          ComponentAuthorization security =
              (ComponentAuthorization) Class.forName(KMELIA_SECURITY_CLASS).newInstance();
          isAccessAuthorized = security.isAccessAuthorized(componentId, getUserId(req), foreignId);
        } catch (Exception e) {
          SilverTrace.error(
              "util",
              "GoToFile.doPost",
              "root.EX_CLASS_NOT_INITIALIZED",
              "org.silverpeas.components.kmelia.KmeliaAuthorization",
              e);
          return null;
        }
      }
      if (isAccessAuthorized) {
        res.setCharacterEncoding(CharEncoding.UTF_8);
        res.setContentType("text/html; charset=utf-8");
        String fileName = ClientBrowserUtil.rfc2047EncodeFilename(req, attachment.getFilename());
        res.setHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");
        return URLUtil.getFullApplicationURL(req) + encodeFilename(attachment.getAttachmentURL());
      }
    }
    return "ComponentId="
        + componentId
        + "&AttachmentId="
        + objectId
        + "&Mapping=File&ForeignId="
        + foreignId;
  }