Interface TemporaryAttachmentSessionsManager


  • @Unstable
    @Role
    public interface TemporaryAttachmentSessionsManager
    Interface for operations related to temporary upload of attachments. The idea of this API is to allow obtaining directly a temporary XWikiAttachment from a Part and to keep it in cache until it's saved. The manager is handling a separated map of attachments for each HttpSession.
    Since:
    14.3RC1
    Version:
    $Id: 93453cc619e06caa2f6d8e14acb8ec58beb3f3d6 $
    • Method Detail

      • temporarilyAttach

        @Unstable
        void temporarilyAttach​(XWikiAttachment attachment,
                               DocumentReference documentReference)
                        throws TemporaryAttachmentException
        Allow to temporarily attach the given instance of XWikiAttachment to the given document reference. This can be useful if an API manipulates an XWikiAttachment without saving it, and want it to be discoverable when parsing a document through the download action for example. Note that consumer of this API needs to be aware that the file attached to the XWikiAttachment might be deleted at the end of the session, as any temporary attachment.
        Parameters:
        attachment - the attachment to be temporarily attached to the document
        documentReference - the reference of the document to link this attachment to
        Throws:
        TemporaryAttachmentException - in case of problem when performing the link
        Since:
        14.10
      • getUploadedAttachments

        Collection<XWikiAttachment> getUploadedAttachments​(DocumentReference documentReference)
        Retrieve all temporary attachments related to the given document reference in the current user session.
        Parameters:
        documentReference - the reference for which to retrieve temporary attachments.
        Returns:
        a collection of temporary attachments or an empty collection.
      • getUploadedAttachment

        Optional<XWikiAttachment> getUploadedAttachment​(DocumentReference documentReference,
                                                        String filename)
        Retrieve a specific temporary attachment related to the given document reference and matching the given filename.
        Parameters:
        documentReference - the reference for which to retrieve the temporary attachment.
        filename - the filename to look for.
        Returns:
        an Optional.empty() if the attachment cannot be found, else an optional containing the attachment
      • getUploadedAttachment

        default Optional<XWikiAttachment> getUploadedAttachment​(AttachmentReference attachmentReference)
        Retrieve a specific temporary attachment related to the given document reference and matching the given filename. This method is only a helper to getUploadedAttachment(DocumentReference, String).
        Parameters:
        attachmentReference - the reference of the attachment to retrieve
        Returns:
        an Optional.empty() if the attachment cannot be found, else an optional containing the attachment
        Since:
        14.3.1, 14.4RC1
      • removeUploadedAttachment

        boolean removeUploadedAttachment​(DocumentReference documentReference,
                                         String filename)
        Search for temporary attachment related to the given document reference and matching the given filename, and remove it from the cache.
        Parameters:
        documentReference - the reference for which to retrieve the temporary attachment.
        filename - the filename to look for.
        Returns:
        true if the attachment have been found for deletion, false if no matching attachment could be find.
      • removeUploadedAttachments

        boolean removeUploadedAttachments​(DocumentReference documentReference)
        Remove all uploaded attachments from the cache related to the given document reference in the current user session.
        Parameters:
        documentReference - the reference for which to retrieve the temporary attachments.
        Returns:
        true if there was some temporary attachments in cache for the given document reference in the current user session, false if there was no matching temporary attachment in cache.
      • attachTemporaryAttachmentsInDocument

        @Unstable
        default void attachTemporaryAttachmentsInDocument​(XWikiDocument document,
                                                          List<String> fileNames)
        This method aims at attaching the XWikiAttachment that might have been previously temporary upload to the XWikiDocument they are targeting. This method should only be called before performing a save of the document to actually persist them. Also note that this method cannot call removeUploadedAttachment(DocumentReference, String) as removing the attachment would delete the data before they can be properly saved in the persistent storage. So the consumer of the API should take care of properly calling this API when needed.
        Parameters:
        document - the actual document instance that should receive the attachments
        fileNames - the names of the uploaded files to attach
        Since:
        14.10