use of com.haulmont.cuba.web.toolkit.ui.CubaFileDownloader in project cuba by cuba-platform.
the class WebExportDisplay method show.
/**
* Show/Download resource at client side
*
* @param dataProvider ExportDataProvider
* @param resourceName ResourceName for client side
* @param exportFormat ExportFormat
* @see com.haulmont.cuba.gui.export.FileDataProvider
* @see com.haulmont.cuba.gui.export.ByteArrayDataProvider
*/
@Override
public void show(ExportDataProvider dataProvider, String resourceName, final ExportFormat exportFormat) {
backgroundWorker.checkUIAccess();
boolean showNewWindow = this.newWindow;
if (useViewList) {
String fileExt;
if (exportFormat != null) {
fileExt = exportFormat.getFileExt();
} else {
fileExt = FilenameUtils.getExtension(resourceName);
}
WebConfig webConfig = configuration.getConfig(WebConfig.class);
showNewWindow = webConfig.getViewFileExtensions().contains(StringUtils.lowerCase(fileExt));
}
if (exportFormat != null) {
if (StringUtils.isEmpty(FilenameUtils.getExtension(resourceName))) {
resourceName += "." + exportFormat.getFileExt();
}
}
CubaFileDownloader fileDownloader = AppUI.getCurrent().getFileDownloader();
StreamResource resource = new StreamResource(dataProvider::provide, resourceName);
if (exportFormat != null && StringUtils.isNotEmpty(exportFormat.getContentType())) {
resource.setMIMEType(exportFormat.getContentType());
} else {
resource.setMIMEType(FileTypesHelper.getMIMEType(resourceName));
}
if (showNewWindow && isBrowserSupportsPopups()) {
fileDownloader.viewDocument(resource);
} else {
fileDownloader.downloadFile(resource);
}
}
Aggregations