Class DownloadServiceImpl

    • Constructor Detail

      • DownloadServiceImpl

        public DownloadServiceImpl()
    • Method Detail

      • storeBlobs

        public String storeBlobs​(List<Blob> blobs)
        Stores the blobs for later download. Multipart download are not yet supported. You can only provide a blob singleton at this time.
        Specified by:
        storeBlobs in interface DownloadService
        Parameters:
        blobs - the list of blobs to store
        Returns:
        the store key used for retrieving the blobs (@see DownloadService.getDownloadUrl(String)
      • getFullDownloadUrl

        public String getFullDownloadUrl​(DocumentModel doc,
                                         String xpath,
                                         Blob blob,
                                         String baseUrl)
        Description copied from interface: DownloadService
        Gets the full download URL (after redirects if configured so) for the given blob.
        Specified by:
        getFullDownloadUrl in interface DownloadService
        Parameters:
        doc - the document
        xpath - the blob's xpath or blobholder index, or null for default
        blob - the blob
        baseUrl - the base URL to use for Nuxeo downloads (if there is no redirect)
        Returns:
        the full URL (which may be to a redirected server)
      • getDownloadUrl

        public String getDownloadUrl​(DocumentModel doc,
                                     String xpath,
                                     String filename)
        Description copied from interface: DownloadService
        Gets the URL to use to download the blob at the given xpath in the given document.

        The URL is relative to the Nuxeo Web Application context.

        Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg?changeToken=5-1

        Specified by:
        getDownloadUrl in interface DownloadService
        Parameters:
        doc - the document
        xpath - the blob's xpath or blobholder index, or null for default
        filename - the blob's filename, or null for default
        Returns:
        the download URL with changeToken as query param for optimized http caching
      • getDownloadUrl

        public String getDownloadUrl​(String repositoryName,
                                     String docId,
                                     String xpath,
                                     String filename)
        Description copied from interface: DownloadService
        Gets the URL to use to download the blob at the given xpath in the given document.

        The URL is relative to the Nuxeo Web Application context.

        Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg

        Specified by:
        getDownloadUrl in interface DownloadService
        Parameters:
        repositoryName - the document repository
        docId - the document id
        xpath - the blob's xpath or blobholder index, or null for default
        filename - the blob's filename, or null for default
        Returns:
        the download URL
      • getDownloadUrl

        public String getDownloadUrl​(String repositoryName,
                                     String docId,
                                     String xpath,
                                     String filename,
                                     String changeToken)
        Description copied from interface: DownloadService
        Gets the URL to use to download the blob at the given xpath in the given document.

        The URL is relative to the Nuxeo Web Application context.

        Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg?changeToken=5-1

        Specified by:
        getDownloadUrl in interface DownloadService
        Parameters:
        repositoryName - the document repository
        docId - the document id
        xpath - the blob's xpath or blobholder index, or null for default
        filename - the blob's filename, or null for default
        changeToken - the doc changeToken which will be appended as a query parameter for optimized http caching.
        Returns:
        the download URL
      • getSanitizedFilenameWithoutPath

        protected String getSanitizedFilenameWithoutPath​(String filename)
      • getDownloadUrl

        public String getDownloadUrl​(String storeKey)
        Description copied from interface: DownloadService
        Gets the URL to use to download the blobs identified by a storage key.

        The URL is relative to the Nuxeo Web Application context.

        Returns something like nxbigblob/key

        Specified by:
        getDownloadUrl in interface DownloadService
        Parameters:
        storeKey - The key of stored blobs to download
        Returns:
        the download URL
      • getDownloadPathAndAction

        protected org.apache.commons.lang3.tuple.Pair<String,​DownloadServiceImpl.Action> getDownloadPathAndAction​(String path)
        Gets the download path and action of the URL to use to download blobs. For instance, from the path "nxfile/default/3727ef6b-cf8c-4f27-ab2c-79de0171a2c8/files:files/0/file/image.png", the pair ("default/3727ef6b-cf8c-4f27-ab2c-79de0171a2c8/files:files/0/file/image.png", Action.DOWNLOAD_FROM_DOC) is returned.
        Parameters:
        path - the path of the URL to use to download blobs
        Returns:
        the pair download path and action
        Since:
        9.1
      • handleDownload

        public void handleDownload​(javax.servlet.http.HttpServletRequest req,
                                   javax.servlet.http.HttpServletResponse resp,
                                   String baseUrl,
                                   String path)
                            throws IOException
        Description copied from interface: DownloadService
        Handles the download of a document.
        Specified by:
        handleDownload in interface DownloadService
        Parameters:
        req - the request
        resp - the response
        baseUrl - the request baseUrl
        path - the request path, without the context
        Throws:
        IOException
      • isHead

        protected static boolean isHead​(javax.servlet.http.HttpServletRequest request)
      • handleDownload

        protected void handleDownload​(javax.servlet.http.HttpServletRequest req,
                                      javax.servlet.http.HttpServletResponse resp,
                                      String downloadPath,
                                      String baseUrl,
                                      boolean info)
                               throws IOException
        Throws:
        IOException
      • downloadBlobStatus

        public void downloadBlobStatus​(javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response,
                                       String key,
                                       String reason)
                                throws IOException
        Description copied from interface: DownloadService
        Triggers a AsyncBlob download which gives information about an asynchronous blob.
        Specified by:
        downloadBlobStatus in interface DownloadService
        key - the stored blobs key
        reason - the download reason
        Throws:
        IOException
      • downloadBlob

        public void downloadBlob​(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 String key,
                                 String reason)
                          throws IOException
        Description copied from interface: DownloadService
        Triggers a blobs download. Once the temporary blobs are transfered from the store, they are automatically deleted. The returned HTTP Status Code is 200 if the blob is ready or 202 if it is still being processed.
        Specified by:
        downloadBlob in interface DownloadService
        key - the stored blobs key
        reason - the download reason
        Throws:
        IOException
      • downloadBlob

        protected void downloadBlob​(javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response,
                                    String key,
                                    String reason,
                                    boolean status)
                             throws IOException
        Throws:
        IOException
      • downloadBlob

        @Deprecated
        public void downloadBlob​(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 DocumentModel doc,
                                 String xpath,
                                 Blob blob,
                                 String filename,
                                 String reason)
                          throws IOException
        Deprecated.
        Description copied from interface: DownloadService
        Triggers a blob download.
        Specified by:
        downloadBlob in interface DownloadService
        doc - the document, if available
        xpath - the blob's xpath or blobholder index, if available
        blob - the blob, if already fetched
        filename - the filename to use
        reason - the download reason
        Throws:
        IOException
      • downloadBlob

        @Deprecated
        public void downloadBlob​(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 DocumentModel doc,
                                 String xpath,
                                 Blob blob,
                                 String filename,
                                 String reason,
                                 Map<String,​Serializable> extendedInfos)
                          throws IOException
        Deprecated.
        Description copied from interface: DownloadService
        Triggers a blob download.
        Specified by:
        downloadBlob in interface DownloadService
        doc - the document, if available
        xpath - the blob's xpath or blobholder index, if available
        blob - the blob, if already fetched
        filename - the filename to use
        reason - the download reason
        extendedInfos - an optional map of extended informations to log
        Throws:
        IOException
      • downloadBlob

        @Deprecated
        public void downloadBlob​(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 DocumentModel doc,
                                 String xpath,
                                 Blob blob,
                                 String filename,
                                 String reason,
                                 Map<String,​Serializable> extendedInfos,
                                 Boolean inline)
                          throws IOException
        Deprecated.
        Description copied from interface: DownloadService
        Triggers a blob download.
        Specified by:
        downloadBlob in interface DownloadService
        doc - the document, if available
        xpath - the blob's xpath or blobholder index, if available
        blob - the blob, if already fetched
        filename - the filename to use
        reason - the download reason
        extendedInfos - an optional map of extended informations to log
        inline - if not null, force the inline flag for content-disposition
        Throws:
        IOException
      • downloadBlob

        @Deprecated
        public void downloadBlob​(javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 DocumentModel doc,
                                 String xpath,
                                 Blob blob,
                                 String filename,
                                 String reason,
                                 Map<String,​Serializable> extendedInfos,
                                 Boolean inline,
                                 Consumer<ByteRange> blobTransferer)
                          throws IOException
        Deprecated.
        Description copied from interface: DownloadService
        Triggers a blob download.
        Specified by:
        downloadBlob in interface DownloadService
        doc - the document, if available
        xpath - the blob's xpath or blobholder index, if available
        blob - the blob, if already fetched
        filename - the filename to use
        reason - the download reason
        extendedInfos - an optional map of extended informations to log
        inline - if not null, force the inline flag for content-disposition
        blobTransferer - the transferer of the actual blob
        Throws:
        IOException
      • getByteRange

        protected ByteRange getByteRange​(javax.servlet.http.HttpServletRequest request,
                                         long length)
      • getWantDigests

        protected Set<String> getWantDigests​(javax.servlet.http.HttpServletRequest request)
      • hexToBase64

        protected static String hexToBase64​(String hexString)
      • transferBlobWithByteRange

        protected void transferBlobWithByteRange​(Blob blob,
                                                 ByteRange byteRange,
                                                 javax.servlet.http.HttpServletResponse response)
      • resolveBlob

        public Blob resolveBlob​(DocumentModel doc,
                                String xpath)
        Description copied from interface: DownloadService
        Finds a document's blob given an xpath or blobholder index
        Specified by:
        resolveBlob in interface DownloadService
        Parameters:
        doc - the document
        xpath - the xpath or blobholder index
        Returns:
        the blob, or null if not found
      • checkPermission

        public boolean checkPermission​(DocumentModel doc,
                                       String xpath,
                                       Blob blob,
                                       String reason,
                                       Map<String,​Serializable> extendedInfos)
        Description copied from interface: DownloadService
        Checks whether the download of the blob is allowed.
        Specified by:
        checkPermission in interface DownloadService
        Parameters:
        doc - the doc for which this download occurs, if available
        xpath - the blob's xpath or blobholder index, if available
        blob - the blob
        reason - the download reason
        extendedInfos - an optional map of extended informations to log
        Returns:
        true if download is allowed
      • addCacheControlHeaders

        protected void addCacheControlHeaders​(javax.servlet.http.HttpServletRequest request,
                                              javax.servlet.http.HttpServletResponse response)
        Internet Explorer file downloads over SSL do not work with certain HTTP cache control headers

        See http://support.microsoft.com/kb/323308/

        What is not mentioned in the above Knowledge Base is that "Pragma: no-cache" also breaks download in MSIE over SSL

      • forceNoCacheOnMSIE

        protected static boolean forceNoCacheOnMSIE()
      • logDownload

        public void logDownload​(javax.servlet.http.HttpServletRequest request,
                                DocumentModel doc,
                                String xpath,
                                String filename,
                                String reason,
                                Map<String,​Serializable> extendedInfos)
        Description copied from interface: DownloadService
        Logs a download.
        Specified by:
        logDownload in interface DownloadService
        Parameters:
        request - the HTTP request, if available
        doc - the doc for which this download occurs, if available
        xpath - the blob's xpath or blobholder index, if available
        filename - the filename
        reason - the download reason
        extendedInfos - an optional map of extended informations to log