/** Open a download dialog to save the specified content at the client * with the suggested file name.<br/> * Note: You don't need to close the content (a Reader), it will be closed automatically after download. * @param content the content * @param contentType the content type (a.k.a., MIME type), * e.g., application/pdf * @param flnm the suggested file name, e.g., myfile.pdf. * If null, no suggested name is provided. */ public static void save(Reader content, String contentType, String flnm) { save(new AMedia(flnm, null, contentType, content), flnm); }
/** Open a download dialog to save the specified content at the client * with the suggested file name.<br/> * Note: You don't need to close the content (a InputStream), it will be closed automatically after download. * @param content the content * @param contentType the content type (a.k.a., MIME type), * e.g., application/pdf * @param flnm the suggested file name, e.g., myfile.pdf. * If null, no suggested name is provided. */ public static void save(InputStream content, String contentType, String flnm) { save(new AMedia(flnm, null, contentType, content), flnm); }
/** Open a download dialog to save the specified content at the client * with the suggested file name. * * @param content the content * @param contentType the content type (a.k.a., MIME type), * e.g., application/pdf * @param flnm the suggested file name, e.g., myfile.pdf. * If null, no suggested name is provided. */ public static void save(byte[] content, String contentType, String flnm) { save(new AMedia(flnm, null, contentType, content), flnm); }
/** Open a download dialog to save the specified content at the client * with the suggested file name. * * @param content the content * @param contentType the content type (a.k.a., MIME type), * e.g., application/pdf * @param flnm the suggested file name, e.g., myfile.pdf. * If null, no suggested name is provided. */ public static void save(String content, String contentType, String flnm) { save(new AMedia(flnm, null, contentType, content), flnm); }
/** Open a download dialog to save the specified file at the client. * * @param file the file to download to the client * @param contentType the content type, e.g., application/pdf. * Unlike other save methods, it is optional. If null, the file name's * extension is used to determine the content type. * @exception FileNotFoundException if the file is not found. * @since 3.0.8 */ public static void save(File file, String contentType) throws FileNotFoundException { save(new AMedia(file, contentType, null), file.getName()); }
/** * When output file type is HTML, return image in AMedia * * @param imageName the request image file name * @return A AMdia contains a image. */ private AMedia getImage(String imageName) { if (_imageMap == null) { log.warning("The image map not ready, "+imageName); return null; } byte[] imageBytes = (byte[])_imageMap.get(imageName); return new AMedia(imageName, "", "image/gif", imageBytes); } }
/** Open a download dialog to save the resource of the specified URL * at the client. * The path must be retrievable by use of {@link org.zkoss.zk.ui.WebApp#getResource}. * * @param url the URL to get the resource * @param contentType the content type, e.g., application/pdf. * Unlike other save methods, it is optional. If null, the path's * extension is used to determine the content type. * @exception FileNotFoundException if the resource is not found. * @since 3.0.8 */ public static void save(URL url, String contentType) throws FileNotFoundException { String name = url.toExternalForm(); int j = name.lastIndexOf('/'); if (j >= 0 && j < name.length() - 1) name = name.substring(j + 1); save(new AMedia(url, contentType, null), name); }
@Command public void exportListboxToExcel(@BindingParam("ref") Listbox listbox) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); ExcelExporter exporter = new ExcelExporter(); exporter.export(listbox, out); AMedia amedia = new AMedia("FirstReport.xlsx", "xls", "application/file", out.toByteArray()); Filedownload.save(amedia); out.close(); }
Workbook workbook = new HSSFWorkbook(); Sheet listSheet = workbook.createSheet("Kişi Listesi"); int rowIndex = 0; for (KayitParam kp : kayitList) { Row row = listSheet.createRow(rowIndex++); int cellIndex = 0; row.createCell(cellIndex++).setCellValue(kp.getAd()); row.createCell(cellIndex++).setCellValue(kp.getSoyad()); row.createCell(cellIndex++).setCellValue(kp.getEposta()); row.createCell(cellIndex++).setCellValue(kp.getCinsiyet()); row.createCell(cellIndex++).setCellValue(kp.getDogumtarihi()); row.createCell(cellIndex++).setCellValue(kp.getTahsil()); } try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); workbook.write(baos); AMedia amedia = new AMedia("Kisiler.xls", "xls", "application/file", baos.toByteArray()); Filedownload.save(amedia); baos.close(); } catch (Exception e) { e.printStackTrace(); }
URL url = ctx.getResource(path); if (url != null) media = new AMedia(url, contentType, null); } else if (type == 'f') { File file = new File(path); source = file; media = new AMedia(file, contentType, null); } else if (type == 'u') { URL url = new URL(path); source = url; media = new AMedia(url, contentType, null);
return _media = new AMedia("report.pdf", "pdf", "application/pdf", arrayOutputStream.toByteArray()); return _media = new AMedia("report.xml", "xml", "text/xml", arrayOutputStream.toByteArray()); return _media = new AMedia("report.html", "html", "text/html", arrayOutputStream.toByteArray()); return _media = new AMedia("report.rtf", "rtf", "application/rtf", arrayOutputStream.toByteArray()); return _media = new AMedia("report.xls", "xls", "application/vnd.ms-excel", arrayOutputStream.toByteArray()); return _media = new AMedia("report.xls", "xls", "application/vnd.ms-excel", arrayOutputStream.toByteArray()); return _media = new AMedia("report.csv", "csv", "text/csv", arrayOutputStream.toByteArray()); return _media = new AMedia("report.odt", "odt", "application/vnd.oasis.opendocument.text", arrayOutputStream.toByteArray());