List of usage examples for com.vaadin.server DownloadStream getContentDispositionFilename
public static String getContentDispositionFilename(String filename)
From source file:com.foc.property.FCloudStoragePropertyResource.java
License:Apache License
@Override public DownloadStream getStream() { DownloadStream downloadStream = null; if (cloudStorageProperty != null) { if (Utils.isStringEmpty(cloudStorageProperty.getKey())) { Globals.logString("DOWNLOAD: newBlobResource 1 Key Empty, generating it"); cloudStorageProperty.generateKey(); }/*from w w w . j a v a 2s. co m*/ Globals.logString("DOWNLOAD: newBlobResource 1bis Key=" + cloudStorageProperty.getKey()); if (cloudStorageProperty.getDirectory() == null) { Globals.logString("DOWNLOAD: newBlobResource 2 Directory null computing it"); cloudStorageProperty.setDirectory(Globals.getApp().getCloudStorageDirectory(), false); } Globals.logString("DOWNLOAD: newBlobResource 2bis Key=" + cloudStorageProperty.getDirectory()); InputStream is = (InputStream) cloudStorageProperty.getObject(); if (is == null) Globals.logString("DOWNLOAD: newBlobResource 3 inputStream is null"); else Globals.logString("DOWNLOAD: newBlobResource 3bis inputStream is Good"); Globals.logString("DOWNLOAD: newBlobResource 4 FileName : " + cloudStorageProperty.getFileName()); if (is != null) { downloadStream = new DownloadStream(is, "application/x-unknown", cloudStorageProperty.getFileName()); downloadStream.setParameter("Content-Disposition", "attachment; filename=" + DownloadStream.getContentDispositionFilename(cloudStorageProperty.getFileName())); downloadStream.setCacheTime(0); } } return downloadStream; }
From source file:com.haulmont.cuba.web.toolkit.ui.CubaFileDownloader.java
License:Apache License
@Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { if (path == null) { return false; }//from w w w . jav a 2s.c o m String targetResourceKey; DownloadStream stream; VaadinSession session = getSession(); session.lock(); try { String[] parts = path.split("/", 2); targetResourceKey = parts[0]; if (targetResourceKey.isEmpty()) { return false; } Resource resource = getResource(targetResourceKey); if (resource == null) { return false; } boolean isViewDocumentRequest = targetResourceKey.startsWith(VIEW_RESOURCE_PREFIX); stream = ((ConnectorResource) resource).getStream(); String contentDisposition = stream.getParameter(DownloadStream.CONTENT_DISPOSITION); if (contentDisposition == null) { // Content-Disposition: attachment generally forces download contentDisposition = (isViewDocumentRequest ? "inline" : "attachment") + "; " + DownloadStream.getContentDispositionFilename(stream.getFileName()); } stream.setParameter(DownloadStream.CONTENT_DISPOSITION, contentDisposition); // Content-Type to block eager browser plug-ins from hijacking the file if (isOverrideContentType() && !isViewDocumentRequest) { stream.setContentType("application/octet-stream;charset=UTF-8"); } else { if (StringUtils.isNotEmpty(stream.getContentType())) { stream.setContentType(stream.getContentType() + ";charset=UTF-8\""); } else { stream.setContentType(";charset=UTF-8\""); } } } finally { session.unlock(); } stream.writeResponse(request, response); return true; }
From source file:com.haulmont.cuba.web.widgets.CubaFileDownloader.java
License:Apache License
@Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { if (path == null) { return false; }//from w w w . j a va 2s . com String targetResourceKey; DownloadStream stream; VaadinSession session = getSession(); session.lock(); try { String[] parts = path.split("/", 2); targetResourceKey = parts[0]; if (targetResourceKey.isEmpty()) { return false; } Resource resource = getResource(targetResourceKey); if (resource == null) { return false; } boolean isViewDocumentRequest = targetResourceKey.startsWith(VIEW_RESOURCE_PREFIX); stream = ((ConnectorResource) resource).getStream(); String contentDisposition = stream.getParameter(DownloadStream.CONTENT_DISPOSITION); if (contentDisposition == null) { // Content-Disposition: attachment generally forces download contentDisposition = (isViewDocumentRequest ? "inline" : "attachment") + "; " + DownloadStream.getContentDispositionFilename(stream.getFileName()); } stream.setParameter(DownloadStream.CONTENT_DISPOSITION, contentDisposition); // Content-Type to block eager browser plug-ins from hijacking the file if (isOverrideContentType() && !isViewDocumentRequest && !isSafariOrIOS()) { stream.setContentType("application/octet-stream;charset=UTF-8"); } else { if (StringUtils.isNotEmpty(stream.getContentType())) { stream.setContentType(stream.getContentType() + ";charset=UTF-8\""); } else { stream.setContentType(";charset=UTF-8\""); } } } finally { session.unlock(); } stream.writeResponse(request, response); return true; }