Class 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 Detail

      • TemporaryAttachmentsScriptService

        public TemporaryAttachmentsScriptService()
    • Method Detail

      • 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 type multipart/form-data.
        Parameters:
        documentReference - the target document reference the attachment should be later attached to
        fieldName - the name of the field of the uploaded data
        filename - an optional filename used instead of using the filename of the file passing in fieldName, ignored when null
        Returns:
        a temporary Attachment not yet persisted attachment, or null in case of error
        Throws:
        TemporaryAttachmentException - in case of problem when reading the attachment
        AttachmentValidationException - in case of error when validating the attachment (e.g., the maximum filesize is reached)
        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 return true for the same XWikiAttachment 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)