List of usage examples for com.vaadin.server DownloadStream getParameter
public String getParameter(String name)
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 av a 2 s. 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; }//ww w . java 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; }
From source file:fr.univlorraine.mondossierweb.utils.MyFileDownloader.java
License:Apache License
@Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { BusyIndicatorWindow busyIndicatorWindow = new BusyIndicatorWindow(); UI ui = UI.getCurrent();/*www .ja va2 s .c om*/ ui.access(() -> ui.addWindow(busyIndicatorWindow)); try { if (!path.matches("dl(/.*)?")) { // Ignore if it isn't for us return false; } Resource resource = getFileDownloadResource(); if (resource instanceof ConnectorResource) { DownloadStream stream = ((ConnectorResource) resource).getStream(); if (stream == null) return false; if (stream.getParameter("Content-Disposition") == null) { // Content-Disposition: attachment generally forces download stream.setParameter("Content-Disposition", "attachment; filename=\"" + stream.getFileName() + "\""); } //Forcer "Ouvrir avec" par dfaut. Permet de proposer "Ouvrir avec" sous Firefox/MacOS. Indisponible sinon stream.setParameter("Content-Type", "application/force-download"); // Content-Type to block eager browser plug-ins from hijacking the // file if (isOverrideContentType()) { stream.setContentType("application/octet-stream;charset=UTF-8"); } if (fileSize > 0) { stream.setParameter("Content-Length", "" + fileSize); } stream.writeResponse(request, response); return true; } else { return false; } } finally { busyIndicatorWindow.close(); } }
From source file:org.vaadin.gridfiledownloader.GridFileDownloader.java
License:Apache License
@Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { if (!path.matches("dl(/.*)?")) { // Ignore if it isn't for us return false; }// w w w. j a v a 2 s .c o m boolean markedProcessed = false; try { if (!waitForRPC()) { handleRPCTimeout(); return false; } getResource().setFilename(gridStreamResource.getFilename()); VaadinSession session = getSession(); session.lock(); DownloadStream stream; try { Resource resource = getFileDownloadResource(); if (!(resource instanceof ConnectorResource)) { return false; } stream = ((ConnectorResource) resource).getStream(); if (stream.getParameter("Content-Disposition") == null) { // Content-Disposition: attachment generally forces download stream.setParameter("Content-Disposition", "attachment; filename=\"" + stream.getFileName() + "\""); } // Content-Type to block eager browser plug-ins from hijacking // the file if (isOverrideContentType()) { stream.setContentType("application/octet-stream;charset=UTF-8"); } } finally { try { markProcessed(); markedProcessed = true; } finally { session.unlock(); } } try { stream.writeResponse(request, response); } catch (Exception e) { handleWriteResponseException(e); } return true; } finally { // ensure the download request always gets marked processed if (!markedProcessed) { markProcessed(); } } }