Package org.xwiki.store
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 temporaryXWikiAttachment
from aPart
and to keep it in cache until it's saved. The manager is handling a separated map of attachments for eachHttpSession
.- Since:
- 14.3RC1
- Version:
- $Id: 93453cc619e06caa2f6d8e14acb8ec58beb3f3d6 $
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
attachTemporaryAttachmentsInDocument(XWikiDocument document, List<String> fileNames)
This method aims at attaching theXWikiAttachment
that might have been previously temporary upload to theXWikiDocument
they are targeting.default Optional<XWikiAttachment>
getUploadedAttachment(AttachmentReference attachmentReference)
Retrieve a specific temporary attachment related to the given document reference and matching the given filename.Optional<XWikiAttachment>
getUploadedAttachment(DocumentReference documentReference, String filename)
Retrieve a specific temporary attachment related to the given document reference and matching the given filename.Collection<XWikiAttachment>
getUploadedAttachments(DocumentReference documentReference)
Retrieve all temporary attachments related to the given document reference in the current user session.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.boolean
removeUploadedAttachments(DocumentReference documentReference)
Remove all uploaded attachments from the cache related to the given document reference in the current user session.void
temporarilyAttach(XWikiAttachment attachment, DocumentReference documentReference)
Allow to temporarily attach the given instance ofXWikiAttachment
to the given document reference.XWikiAttachment
uploadAttachment(DocumentReference documentReference, javax.servlet.http.Part part)
XWikiAttachment
uploadAttachment(DocumentReference documentReference, javax.servlet.http.Part part, String filename)
-
-
-
Method Detail
-
uploadAttachment
XWikiAttachment uploadAttachment(DocumentReference documentReference, javax.servlet.http.Part part) throws TemporaryAttachmentException, AttachmentValidationException
- Parameters:
documentReference
- the reference of the document that the attachment should be attached to.part
- the actual data that is uploaded.- Returns:
- an attachment that is not saved yet but cached and contains the data of the given part.
- Throws:
TemporaryAttachmentException
- in case of problem when reading the partAttachmentValidationException
- in case of error when validating the attachment (e.g., the maximum filesize is reached)
-
uploadAttachment
@Unstable XWikiAttachment uploadAttachment(DocumentReference documentReference, javax.servlet.http.Part part, String filename) throws TemporaryAttachmentException, AttachmentValidationException
- Parameters:
documentReference
- the reference of the document that the attachment should be attached topart
- the actual data that is uploadedfilename
- an optional filename used instead of usingPart.getSubmittedFileName()
, ignored whennull
or blank- Returns:
- an attachment that is not saved yet but cached and contains the data of the given part
- Throws:
TemporaryAttachmentException
- in case of problem when reading the partAttachmentValidationException
- in case of error when validating the attachment (e.g., the maximum filesize is reached)- Since:
- 14.9RC1
-
temporarilyAttach
@Unstable void temporarilyAttach(XWikiAttachment attachment, DocumentReference documentReference) throws TemporaryAttachmentException
Allow to temporarily attach the given instance ofXWikiAttachment
to the given document reference. This can be useful if an API manipulates anXWikiAttachment
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 theXWikiAttachment
might be deleted at the end of the session, as any temporary attachment.- Parameters:
attachment
- the attachment to be temporarily attached to the documentdocumentReference
- 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 togetUploadedAttachment(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 theXWikiAttachment
that might have been previously temporary upload to theXWikiDocument
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 callremoveUploadedAttachment(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 attachmentsfileNames
- the names of the uploaded files to attach- Since:
- 14.10
-
-