List of usage examples for com.vaadin.server DownloadStream CONTENT_DISPOSITION
String CONTENT_DISPOSITION
To view the source code for com.vaadin.server DownloadStream CONTENT_DISPOSITION.
Click Source Link
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 ww w . j a v a 2s.c om 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; }/*w w w. j a v a 2 s . co 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 && !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; }