use of org.nuxeo.ecm.core.io.download.DownloadService in project nuxeo-drive-server by nuxeo.
the class DocumentBackedFileItem method updateDownloadURL.
protected void updateDownloadURL() {
DownloadService downloadService = Framework.getService(DownloadService.class);
// Remove chars that are invalid in filesystem names
String escapedFilename = name.replaceAll("(/|\\\\|\\*|<|>|\\?|\"|:|\\|)", "-");
downloadURL = downloadService.getDownloadUrl(repositoryName, docId, DownloadService.BLOBHOLDER_0, escapedFilename);
}
use of org.nuxeo.ecm.core.io.download.DownloadService in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveActions method getDriveEditURL.
/**
* Returns the Drive edit URL for the given document.
* <p>
* {@link #NXDRIVE_PROTOCOL} must be handled by a protocol handler configured on the client side (either on the
* browser, or on the OS).
*
* @since 7.4
* @return Drive edit URL in the form "{@link #NXDRIVE_PROTOCOL}:// {@link #PROTOCOL_COMMAND_EDIT}
* /protocol/server[:port]/webappName/[user/userName/]repo/repoName/nxdocid/docId/filename/fileName[/
* downloadUrl/downloadUrl]"
*/
public String getDriveEditURL(@SuppressWarnings("hiding") DocumentModel currentDocument) {
if (currentDocument == null) {
return null;
}
// TODO NXP-15397: handle Drive not started exception
BlobHolder bh = currentDocument.getAdapter(BlobHolder.class);
if (bh == null) {
throw new NuxeoException(String.format("Document %s (%s) is not a BlobHolder, cannot get Drive Edit URL.", currentDocument.getPathAsString(), currentDocument.getId()));
}
Blob blob = bh.getBlob();
if (blob == null) {
throw new NuxeoException(String.format("Document %s (%s) has no blob, cannot get Drive Edit URL.", currentDocument.getPathAsString(), currentDocument.getId()));
}
String fileName = blob.getFilename();
ServletRequest servletRequest = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String baseURL = VirtualHostHelper.getBaseURL(servletRequest);
StringBuilder sb = new StringBuilder();
sb.append(NXDRIVE_PROTOCOL).append("://");
sb.append(PROTOCOL_COMMAND_EDIT).append("/");
sb.append(baseURL.replaceFirst("://", "/"));
sb.append("user/");
sb.append(documentManager.getPrincipal().getName());
sb.append("/");
sb.append("repo/");
sb.append(documentManager.getRepositoryName());
sb.append("/nxdocid/");
sb.append(currentDocument.getId());
sb.append("/filename/");
String escapedFilename = fileName.replaceAll("(/|\\\\|\\*|<|>|\\?|\"|:|\\|)", "-");
sb.append(URIUtils.quoteURIPathComponent(escapedFilename, true));
sb.append("/downloadUrl/");
DownloadService downloadService = Framework.getService(DownloadService.class);
String downloadUrl = downloadService.getDownloadUrl(currentDocument, DownloadService.BLOBHOLDER_0, "");
sb.append(downloadUrl);
return sb.toString();
}
Aggregations