public class DownloadServiceImpl extends DefaultComponent implements DownloadService
Modifier and Type | Class and Description |
---|---|
protected static class |
DownloadServiceImpl.Action |
DownloadService.ByteRange
Modifier and Type | Field and Description |
---|---|
protected static int |
DOWNLOAD_BUFFER_SIZE |
protected RedirectResolver |
redirectResolver |
protected ScriptEngineManager |
scriptEngineManager |
static String |
XP_PERMISSIONS |
static String |
XP_REDIRECT_RESOLVER |
lastModified, name
BLOBHOLDER_0, BLOBHOLDER_PREFIX, EVENT_NAME, NXBIGBLOB, NXBIGFILE, NXBIGZIPFILE, NXBLOBSTATUS, NXDOWNLOADINFO, NXFILE, TRANSIENT_STORE_PARAM_ERROR, TRANSIENT_STORE_PARAM_PROGRESS, TRANSIENT_STORE_STORE_NAME
Constructor and Description |
---|
DownloadServiceImpl() |
Modifier and Type | Method and Description |
---|---|
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
|
boolean |
checkPermission(DocumentModel doc,
String xpath,
Blob blob,
String reason,
Map<String,Serializable> extendedInfos)
Checks whether the download of the blob is allowed.
|
void |
downloadBlob(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
DocumentModel doc,
String xpath,
Blob blob,
String filename,
String reason)
Triggers a blob download.
|
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)
Triggers a blob download.
|
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)
Triggers a blob download.
|
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<DownloadService.ByteRange> blobTransferer)
Triggers a blob download.
|
void |
downloadBlob(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
String key,
String reason)
Triggers a blobs download.
|
protected void |
downloadBlob(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
String key,
String reason,
boolean status) |
void |
downloadBlobStatus(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
String key,
String reason)
Triggers a
AsyncBlob download which gives information about an asynchronous blob. |
protected String |
fixXPath(String xpath) |
protected static boolean |
forceNoCacheOnMSIE() |
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.
|
String |
getDownloadUrl(DocumentModel doc,
String xpath,
String filename)
Gets the URL to use to download the blob at the given xpath in the given document.
|
String |
getDownloadUrl(String storeKey)
Gets the URL to use to download the blobs identified by a storage key.
|
String |
getDownloadUrl(String repositoryName,
String docId,
String xpath,
String filename)
Gets the URL to use to download the blob at the given xpath in the given document.
|
String |
getDownloadUrl(String repositoryName,
String docId,
String xpath,
String filename,
String changeToken)
Gets the URL to use to download the blob at the given xpath in the given document.
|
protected static NuxeoPrincipal |
getPrincipal() |
protected String |
getSanitizedFilenameWithoutPath(String filename) |
void |
handleDownload(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String baseUrl,
String path)
Handles the download of a document.
|
protected void |
handleDownload(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String downloadPath,
String baseUrl,
boolean info) |
void |
logDownload(DocumentModel doc,
String xpath,
String filename,
String reason,
Map<String,Serializable> extendedInfos)
Logs a download.
|
Blob |
resolveBlob(DocumentModel doc)
Finds a document's blob.
|
Blob |
resolveBlob(DocumentModel doc,
String xpath)
Finds a document's blob given an xpath or blobholder index
|
Blob |
resolveBlobFromDownloadUrl(String downloadURL)
Finds a document's blob given the download URL returned by
DownloadService.getDownloadUrl(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, java.lang.String) . |
void |
start(ComponentContext context)
Start the component.
|
void |
stop(ComponentContext context)
Stop the component.
|
String |
storeBlobs(List<Blob> blobs)
Stores the blobs for later download.
|
protected void |
transferBlobWithByteRange(Blob blob,
DownloadService.ByteRange byteRange,
javax.servlet.http.HttpServletResponse response) |
void |
transferBlobWithByteRange(Blob blob,
DownloadService.ByteRange byteRange,
Supplier<OutputStream> outputStreamSupplier)
Copies the blob stream at the given byte range into the supplied
OutputStream . |
activate, deactivate, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerContribution, registerExtension, setLastModified, setModifiedNow, setName, unregister, unregisterContribution, unregisterExtension
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
applicationStarted, getApplicationStartedOrder
public static final String XP_PERMISSIONS
public static final String XP_REDIRECT_RESOLVER
protected static final int DOWNLOAD_BUFFER_SIZE
protected ScriptEngineManager scriptEngineManager
protected RedirectResolver redirectResolver
public DownloadServiceImpl()
public void start(ComponentContext context)
Component
start
in interface Component
start
in class DefaultComponent
public void stop(ComponentContext context) throws InterruptedException
Component
stop
in interface Component
stop
in class DefaultComponent
InterruptedException
public String storeBlobs(List<Blob> blobs)
storeBlobs
in interface DownloadService
DownloadService.getDownloadUrl(String)
public String getDownloadUrl(DocumentModel doc, String xpath, String filename)
DownloadService
The URL is relative to the Nuxeo Web Application context.
Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg?changeToken=5-1
getDownloadUrl
in interface DownloadService
doc
- the documentxpath
- the blob's xpath or blobholder index, or null
for defaultfilename
- the blob's filename, or null
for defaultpublic String getDownloadUrl(String repositoryName, String docId, String xpath, String filename)
DownloadService
The URL is relative to the Nuxeo Web Application context.
Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg
getDownloadUrl
in interface DownloadService
repositoryName
- the document repositorydocId
- the document idxpath
- the blob's xpath or blobholder index, or null
for defaultfilename
- the blob's filename, or null
for defaultpublic String getDownloadUrl(String repositoryName, String docId, String xpath, String filename, String changeToken)
DownloadService
The URL is relative to the Nuxeo Web Application context.
Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg?changeToken=5-1
getDownloadUrl
in interface DownloadService
xpath
- the blob's xpath or blobholder index, or null
for defaultfilename
- the blob's filename, or null
for defaultchangeToken
- the doc changeToken which will be appended as a query parameter for optimized http caching.protected String getSanitizedFilenameWithoutPath(String filename)
public String getDownloadUrl(String storeKey)
DownloadService
The URL is relative to the Nuxeo Web Application context.
Returns something like nxbigblob/key
getDownloadUrl
in interface DownloadService
protected org.apache.commons.lang3.tuple.Pair<String,DownloadServiceImpl.Action> getDownloadPathAndAction(String path)
path
- the path of the URL to use to download blobspublic Blob resolveBlobFromDownloadUrl(String downloadURL)
DownloadService
DownloadService.getDownloadUrl(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, java.lang.String)
.
The permissions are check whether the user can download the blob or not.
resolveBlobFromDownloadUrl
in interface DownloadService
downloadURL
- the URL to use to download the blobnull
if not found or if the user has no permission to download itpublic void handleDownload(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String baseUrl, String path) throws IOException
DownloadService
handleDownload
in interface DownloadService
req
- the requestresp
- the responsebaseUrl
- the request baseUrlpath
- the request path, without the contextIOException
protected void handleDownload(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String downloadPath, String baseUrl, boolean info) throws IOException
IOException
public void downloadBlobStatus(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason) throws IOException
DownloadService
AsyncBlob
download which gives information about an asynchronous blob.downloadBlobStatus
in interface DownloadService
key
- the stored blobs keyreason
- the download reasonIOException
public void downloadBlob(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason) throws IOException
DownloadService
downloadBlob
in interface DownloadService
key
- the stored blobs keyreason
- the download reasonIOException
protected void downloadBlob(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason, boolean status) throws IOException
IOException
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
DownloadService
downloadBlob
in interface DownloadService
doc
- the document, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blob, if already fetchedfilename
- the filename to usereason
- the download reasonIOException
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
DownloadService
downloadBlob
in interface DownloadService
doc
- the document, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blob, if already fetchedfilename
- the filename to usereason
- the download reasonextendedInfos
- an optional map of extended informations to logIOException
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
DownloadService
downloadBlob
in interface DownloadService
doc
- the document, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blob, if already fetchedfilename
- the filename to usereason
- the download reasonextendedInfos
- an optional map of extended informations to loginline
- if not null, force the inline flag for content-dispositionIOException
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<DownloadService.ByteRange> blobTransferer) throws IOException
DownloadService
DownloadExecutor
.downloadBlob
in interface DownloadService
doc
- the document, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blob, if already fetchedfilename
- the filename to usereason
- the download reasonextendedInfos
- an optional map of extended informations to loginline
- if not null, force the inline flag for content-dispositionblobTransferer
- the transferer of the actual blobIOException
protected void transferBlobWithByteRange(Blob blob, DownloadService.ByteRange byteRange, javax.servlet.http.HttpServletResponse response)
public void transferBlobWithByteRange(Blob blob, DownloadService.ByteRange byteRange, Supplier<OutputStream> outputStreamSupplier)
DownloadService
OutputStream
.transferBlobWithByteRange
in interface DownloadService
blob
- the blobbyteRange
- the byte rangeoutputStreamSupplier
- the OutputStream
supplierpublic Blob resolveBlob(DocumentModel doc)
DownloadService
resolveBlob
in interface DownloadService
doc
- the documentnull
if not availablepublic Blob resolveBlob(DocumentModel doc, String xpath)
DownloadService
resolveBlob
in interface DownloadService
doc
- the documentxpath
- the xpath or blobholder indexnull
if not foundpublic boolean checkPermission(DocumentModel doc, String xpath, Blob blob, String reason, Map<String,Serializable> extendedInfos)
DownloadService
checkPermission
in interface DownloadService
doc
- the doc for which this download occurs, if availableblob
- the blobreason
- the download reasonextendedInfos
- an optional map of extended informations to logtrue
if download is allowedprotected void addCacheControlHeaders(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
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
protected static boolean forceNoCacheOnMSIE()
public void logDownload(DocumentModel doc, String xpath, String filename, String reason, Map<String,Serializable> extendedInfos)
DownloadService
logDownload
in interface DownloadService
doc
- the doc for which this download occurs, if availablexpath
- the blob's xpath or blobholder index, if availablefilename
- the filenamereason
- the download reasonextendedInfos
- an optional map of extended informations to logprotected static NuxeoPrincipal getPrincipal()
Copyright © 2019 Nuxeo. All rights reserved.