Package org.xwiki.store.script
Class TemporaryAttachmentsScriptService
- java.lang.Object
-
- org.xwiki.store.script.TemporaryAttachmentsScriptService
-
- All Implemented Interfaces:
org.xwiki.script.service.ScriptService
@Component @Singleton @Named("temporaryAttachments") @Unstable public class TemporaryAttachmentsScriptService extends Object implements org.xwiki.script.service.ScriptService
Script service dedicated to the handling of temporary attachments.- Since:
- 14.3RC1
- Version:
- $Id: fed84f23fe93b824c4abe5912a9f63d6c66b5525 $
- See Also:
TemporaryAttachmentSessionsManager
-
-
Constructor Summary
Constructors Constructor Description TemporaryAttachmentsScriptService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<Attachment>
listAllAttachments(DocumentReference documentReference)
Build a list of all the attachments of a given document, sorted by filenames (ignoring the case).List<Attachment>
listTemporaryAttachments(DocumentReference documentReference)
Return a list of the temporary attachments, sorted by filenames (ignoring the case).boolean
persistentAttachmentExists(Attachment attachment)
Check if a given attachment is persisted.boolean
temporaryAttachmentExists(Attachment attachment)
Check if a given attachment is found in the temporary attachment session.Attachment
uploadTemporaryAttachment(DocumentReference documentReference, String fieldName)
Temporary upload the attachment identified by the given field name: the request should be of typemultipart/form-data
.Attachment
uploadTemporaryAttachment(DocumentReference documentReference, String fieldName, String filename)
Temporary upload the attachment identified by the given field name: the request should be of typemultipart/form-data
.
-
-
-
Method Detail
-
uploadTemporaryAttachment
public Attachment uploadTemporaryAttachment(DocumentReference documentReference, String fieldName) throws TemporaryAttachmentException, AttachmentValidationException
Temporary upload the attachment identified by the given field name: the request should be of typemultipart/form-data
.- Parameters:
documentReference
- the target document reference the attachment should be later attached tofieldName
- the name of the field of the uploaded data- Returns:
- a temporary
Attachment
not yet persisted attachment, ornull
in case of error - Throws:
TemporaryAttachmentException
- in case of problem when reading the attachmentAttachmentValidationException
- in case of error when validating the attachment (e.g., the maximum filesize is reached)
-
uploadTemporaryAttachment
@Unstable public Attachment uploadTemporaryAttachment(DocumentReference documentReference, String fieldName, String filename) throws TemporaryAttachmentException, AttachmentValidationException
Temporary upload the attachment identified by the given field name: the request should be of typemultipart/form-data
.- Parameters:
documentReference
- the target document reference the attachment should be later attached tofieldName
- the name of the field of the uploaded datafilename
- an optional filename used instead of using the filename of the file passing infieldName
, ignored whennull
- Returns:
- a temporary
Attachment
not yet persisted attachment, ornull
in case of error - Throws:
TemporaryAttachmentException
- in case of problem when reading the attachmentAttachmentValidationException
- in case of error when validating the attachment (e.g., the maximum filesize is reached)- Since:
- 14.9RC1
-
listTemporaryAttachments
@Unstable public List<Attachment> listTemporaryAttachments(DocumentReference documentReference) throws StoreFilesystemOldcoreException
Return a list of the temporary attachments, sorted by filenames (ignoring the case).- Parameters:
documentReference
- the target document reference the attachments should be later attached to- Returns:
- the list of temporary attachments linked to the given document reference. The list is sorted by the
attachments filenames (
XWikiAttachment.getFilename()
) - Throws:
StoreFilesystemOldcoreException
- Since:
- 14.9RC1
-
listAllAttachments
@Unstable public List<Attachment> listAllAttachments(DocumentReference documentReference) throws StoreFilesystemOldcoreException
Build a list of all the attachments of a given document, sorted by filenames (ignoring the case). The list contains the persisted attachments of the document, merged with the temporary attachments. The persisted attachments are replaced by the temporary one if their names match.- Parameters:
documentReference
- the target document reference the temporary attachments should be later attached to- Returns:
- the list of all attachments linked to the given document reference. Persisted attachments are overridden
by temporary one if names match. The list is sorted by the attachments filenames
(
XWikiAttachment.getFilename()
) - Throws:
StoreFilesystemOldcoreException
- Since:
- 14.9RC1
-
temporaryAttachmentExists
@Unstable public boolean temporaryAttachmentExists(Attachment attachment)
Check if a given attachment is found in the temporary attachment session.persistentAttachmentExists(Attachment)
exists as well to check if a given attachment can be found in the persisted attachments. Note that both method can returntrue
for the sameXWikiAttachment
when an attachment is overridden in the temporary attachment session.- Parameters:
attachment
- an attachment- Returns:
true
if a matching attachment exists in the temporary attachment session (i.e., same filename and document reference),false
otherwise- Since:
- 14.9RC1
- See Also:
persistentAttachmentExists(Attachment)
-
persistentAttachmentExists
@Unstable public boolean persistentAttachmentExists(Attachment attachment) throws StoreFilesystemOldcoreException
Check if a given attachment is persisted.temporaryAttachmentExists(Attachment)
exists as well to check if a given attachment can be found in the temporary attachment session. Note that both method can returntrue
at for the sameXWikiAttachment
when an attachment is overridden in the temporary attachment session.- Parameters:
attachment
- an attachment- Returns:
true
if a matching persisted attachment exists (i.e., same filename and document reference),false
otherwise- Throws:
StoreFilesystemOldcoreException
- in case of error when accessing the attachment's document- Since:
- 14.9RC1
- See Also:
temporaryAttachmentExists(Attachment)
-
-