/** * Puts document in store and redirects */ private void redirectExport() { String viewId = Pages.getViewId(FacesContext.getCurrentInstance()); String baseName = Pages.getCurrentBaseName(); DocumentData documentData = new ByteArrayDocumentData(baseName, excelWorkbook.getDocumentType(), excelWorkbook.getBytes()); String id = DocumentStore.instance().newId(); String url = DocumentStore.instance().preferredUrlForContent(baseName, excelWorkbook.getDocumentType().getExtension(), id); url = Manager.instance().encodeConversationId(url, viewId); DocumentStore.instance().saveData(id, documentData); try { FacesContext.getCurrentInstance().getExternalContext().redirect(url); } catch (IOException e) { throw new ExcelWorkbookException(Interpolator.instance().interpolate("Could not redirect to #0", url), e); } }
response.setContentType(documentData.getDocumentType().getMimeType()); response.setHeader("Content-Disposition", documentData.getDisposition() + "; filename=\"" + documentData.getFileName() + "\"");
DocumentType documentType = new DocumentData.DocumentType("pdf", "application/pdf"); DocumentData documentData = new ByteArrayDocumentData(baseName, documentType, buffer.toByteArray()); documentData.setFilename(getFilename()); String url = store.preferredUrlForContent(baseName, documentType.getExtension(), id); url = Manager.instance().encodeConversationId(url, viewId); store.saveData(id, documentData);
String id = store.newId(); String url = store.preferredUrlForContent(baseName, documentType.getExtension(), id); url = Manager.instance().encodeConversationId(url, viewId);
String id = store.newId(); String url = store.preferredUrlForContent(baseName, type.getExtension(), id); url = Manager.instance().encodeConversationId(url, viewId);
public void sendContent(FacesContext context, String contentId) { try { DocumentData documentData = DocumentStore.instance().getDocumentData(contentId); if (documentData != null) { HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType(documentData.getDocumentType().getMimeType()); response.setHeader("Content-Disposition", documentData.getDisposition() + "; filename=\"" + documentData.getFileName() + "\""); documentData.writeDataToStream(response.getOutputStream()); context.responseComplete(); } } catch (IOException e) { log.warn(e); } }
public static String addResourceToDataStore(FacesContext ctx, UIResource resource) { String baseName = Pages.getCurrentBaseName(); String viewId = Pages.getViewId(ctx); DocumentStore store = DocumentStore.instance(); String id = store.newId(); DocumentType type = new DocumentType("", resource.getContentType()); DocumentData documentData = new DownloadableDocumentData(baseName, type, resource.getData()); documentData.setFilename(resource.getFileName()); documentData.setDisposition(resource.getDisposition()); String url = store.preferredUrlForContent(resource.getFileName(), type.getExtension(), id); url = Manager.instance().encodeConversationId(url, viewId); store.saveData(id, documentData); return url; }
public DocumentType getDocumentType() { return new DocumentData.DocumentType("csv", "text/csv"); }
public String getFileName() { if (fileName == null) { return getBaseName() + "." + getDocumentType().getExtension(); } else { return fileName; } }
/** * Gets the document type of the data for the DocumentStore * * @return the document type (Excel workbook) */ public DocumentType getDocumentType() { return new DocumentData.DocumentType("xls", "application/vnd.ms-excel"); }