List of usage examples for org.apache.wicket.util.resource FileResourceStream FileResourceStream
public FileResourceStream(final java.io.File file)
From source file:au.org.theark.core.util.ByteDataResourceRequestHandler.java
License:Open Source License
public void respond(IRequestCycle requestCycle) { // Write out data as a file in temporary directory final String tempDir = System.getProperty("java.io.tmpdir"); final java.io.File file = new File(tempDir, fileName); FileOutputStream fos = null;/*from w w w . j a va 2 s . c o m*/ try { fos = new FileOutputStream(file); fos.write(this.getData(null)); fos.flush(); } catch (IOException fe) { fe.printStackTrace(); } finally { try { if (fos != null) { fos.close(); } } catch (IOException e) { e.printStackTrace(); } } // Send file back as attachment, and remove after download IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file)); requestCycle.scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) { @Override public void respond(IRequestCycle requestCycle) { super.respond(requestCycle); Files.remove(file); } }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT)); }
From source file:au.org.theark.core.web.component.button.ArkDownloadTemplateButton.java
License:Open Source License
@Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { byte[] data = writeOutXlsFileToBytes(); if (data != null) { InputStream inputStream = new ByteArrayInputStream(data); OutputStream outputStream; try {//from w ww . jav a 2 s . c o m final String tempDir = System.getProperty("java.io.tmpdir"); final java.io.File file = new File(tempDir, templateFilename + ".xls"); final String fileName = templateFilename + ".xls"; outputStream = new FileOutputStream(file); IOUtils.copy(inputStream, outputStream); IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file)); getRequestCycle() .scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) { @Override public void respond(IRequestCycle requestCycle) { super.respond(requestCycle); Files.remove(file); } }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT)); } catch (FileNotFoundException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } } }
From source file:au.org.theark.lims.web.component.inventory.panel.box.display.GridBoxPanel.java
License:Open Source License
/** * Return a download link for the gridBox contents as an Excel Worksheet * @param invCellList/*from w ww. jav a 2 s .c om*/ * @return */ protected Link<String> buildXLSDownloadLink(final List<InvCell> invCellList) { Link<String> link = new Link<String>("downloadGridBoxDataLink") { private static final long serialVersionUID = 1L; public void onClick() { byte[] data = createWorkBookAsByteArray(invCellList); if (data != null) { InputStream inputStream = new ByteArrayInputStream(data); OutputStream outputStream; try { final String tempDir = System.getProperty("java.io.tmpdir"); final java.io.File file = new File(tempDir, limsVo.getInvBox().getName() + ".xls"); final String fileName = limsVo.getInvBox().getName() + ".xls"; outputStream = new FileOutputStream(file); IOUtils.copy(inputStream, outputStream); IResourceStream resourceStream = new FileResourceStream( new org.apache.wicket.util.file.File(file)); getRequestCycle().scheduleRequestHandlerAfterCurrent( new ResourceStreamRequestHandler(resourceStream) { @Override public void respond(IRequestCycle requestCycle) { super.respond(requestCycle); Files.remove(file); } }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT)); } catch (FileNotFoundException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } } } }; return link; }
From source file:au.org.theark.study.web.component.attachments.SearchResultListPanel.java
License:Open Source License
private AjaxButton buildDownloadButton(final SubjectFile subjectFile) { AjaxButton ajaxButton = new AjaxButton(au.org.theark.study.web.Constants.DOWNLOAD_FILE) { private static final long serialVersionUID = 1L; @Override/* w w w.j ava 2 s .c o m*/ protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // Attempt to download the Blob as an array of bytes byte[] data = null; try { // data = subjectFile.getPayload();//.getBytes(1, (int) subjectFile.getPayload().length()); Long studyId = subjectFile.getLinkSubjectStudy().getStudy().getId(); String subjectUID = subjectFile.getLinkSubjectStudy().getSubjectUID(); String fileId = subjectFile.getFileId(); String checksum = subjectFile.getChecksum(); data = arkCommonService.retriveArkFileAttachmentByteArray(studyId, subjectUID, au.org.theark.study.web.Constants.ARK_SUBJECT_ATTACHEMENT_DIR, fileId, checksum); if (data != null) { InputStream inputStream = new ByteArrayInputStream(data); OutputStream outputStream; final String tempDir = System.getProperty("java.io.tmpdir"); final java.io.File file = new File(tempDir, subjectFile.getFilename()); final String fileName = subjectFile.getFilename(); outputStream = new FileOutputStream(file); IOUtils.copy(inputStream, outputStream); IResourceStream resourceStream = new FileResourceStream( new org.apache.wicket.util.file.File(file)); getRequestCycle().scheduleRequestHandlerAfterCurrent( new ResourceStreamRequestHandler(resourceStream) { @Override public void respond(IRequestCycle requestCycle) { super.respond(requestCycle); Files.remove(file); } }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT)); } } catch (ArkSystemException e) { this.error("Unexpected error: Download request could not be fulfilled."); log.error("ArkSystemException" + e.getMessage(), e); } catch (FileNotFoundException e) { this.error("Unexpected error: Download request could not be fulfilled."); log.error("FileNotFoundException" + e.getMessage(), e); } catch (IOException e) { this.error("Unexpected error: Download request could not be fulfilled."); log.error("IOException" + e.getMessage(), e); } target.add(arkCrudContainerVO.getSearchResultPanelContainer()); target.add(containerForm); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected error: Download request could not be fulfilled."); log.error("Unexpected error: Download request could not be fulfilled."); }; }; ajaxButton.setVisible(true); ajaxButton.setDefaultFormProcessing(false); //if (subjectFile.getPayload() == null) //ajaxButton.setVisible(false); return ajaxButton; }
From source file:au.org.theark.study.web.component.subjectUpload.SearchResultListPanel.java
License:Open Source License
public SearchResultListPanel(String id, FeedbackPanel feedBackPanel, ContainerForm containerForm, ArkCrudContainerVO arkCrudContainerVO) { super(id);/*from ww w . j a v a 2 s .com*/ ArkDownloadTemplateButton downloadTemplateButton = new ArkDownloadTemplateButton("downloadTemplate", "SubjectUpload", au.org.theark.study.web.Constants.SUBJECT_TEMPLATE_CELLS) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected Error: Could not proceed with download of the template."); } }; ArkDownloadTemplateButton downloadCustomFieldTemplateButton = new ArkDownloadTemplateButton( "downloadCustomFieldTemplate", "SubjectOrFamilyCustomFieldDataUpload", au.org.theark.study.web.Constants.SUBJECT_OR_FAMILY_CUSTOM_FIELD_DATA_TEMPLATE_CELLS) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected Error: Could not proceed with download of the template."); } }; ArkDownloadTemplateButton downloadConsentFieldTemplateButton = new ArkDownloadTemplateButton( "downloadConsentFieldTemplate", "SubjectConsentFieldUpload", au.org.theark.study.web.Constants.SUBJECT_CONSENT_FIELD_TEMPLATE_CELLS) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected Error: Could not proceed with download of the template."); } }; AjaxButton downLoadPedFileButton = new AjaxButton("downloadPedigreeTemplate") { private static final long serialVersionUID = 1L; { this.setDefaultFormProcessing(false); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { try { Theme theme = new Theme(); Chunk chunk = theme.makeChunk("map_template", "txt"); String tmpDir = System.getProperty("java.io.tmpdir"); String pedFileName = "Ark_pedigree_template" + ".ped"; final File tempFile = new File(tmpDir, pedFileName); FileWriter out = new FileWriter(tempFile); chunk.render(out); IResourceStream resourceStream = new FileResourceStream( new org.apache.wicket.util.file.File(tempFile)); getRequestCycle() .scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) { @Override public void respond(IRequestCycle requestCycle) { super.respond(requestCycle); Files.remove(tempFile); } }.setFileName(pedFileName).setContentDisposition(ContentDisposition.ATTACHMENT)); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected Error: Could not proceed with download of the template."); } }; ArkDownloadTemplateButton downloadSubjectAttachmentTemplateButton = new ArkDownloadTemplateButton( "downloadSubjectAttachmentTemplate", "SubjectAttachmentUpload", au.org.theark.study.web.Constants.SUBJECT_ATTACHMENT_TEMPLATE_CELLS) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { this.error("Unexpected Error: Could not proceed with download of the template."); } }; add(downloadTemplateButton); add(downloadCustomFieldTemplateButton); add(downloadConsentFieldTemplateButton); add(downLoadPedFileButton); add(downloadSubjectAttachmentTemplateButton); }
From source file:com.apachecon.memories.service.UserFile.java
License:Apache License
private Image createImage(String id, boolean small) { File f = small ? thumb : file; IResource resource = new ResourceStreamResource(new FileResourceStream(f)); return new NonCachingImage(id, resource); }
From source file:com.asptt.plongee.resa.util.UtilsFSpdf.java
public ResourceLink createWebResourcePdf(final Adherent adherent, final FicheSecurite fs) { Resource pdfResource = new WebResource() { @Override//from w w w . j a v a 2 s . c om public IResourceStream getResourceStream() { String nom = adherent.getNom(); final String realPath; if (null != fs) { realPath = catalinaBasePath.concat(Parameters.getString("fs.path")).concat(nom).concat("_FS") .concat(".pdf"); // Cration du pdf try { createPdfFS(realPath, fs); } catch (com.itextpdf.io.IOException ex) { java.util.logging.Logger.getLogger(UpdateListeFS.class.getName()).log(Level.SEVERE, null, ex); } catch (java.io.IOException ex) { java.util.logging.Logger.getLogger(UpdateListeFS.class.getName()).log(Level.SEVERE, null, ex); } } else { //Recherche du Certificat mdical nom = nom.substring(0, 1).toUpperCase() + nom.substring(1).toLowerCase(); String license = adherent.getNumeroLicense(); realPath = catalinaBasePath.concat(Parameters.getString("cm.path")).concat(nom).concat("_") .concat(license).concat(".pdf"); } java.io.File file = new java.io.File(realPath); // created FileResourceStream object by passing the above File object name "pdfFile". IResourceStream stream = new FileResourceStream(file); file.deleteOnExit(); //finally returns the stream return stream; } }; /* * Created PopupSettings object named "popupSettings" by passing some parameters in the * constructor and also setted the width and height for popup window. */ PopupSettings popupSettings = new PopupSettings(PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS) .setHeight(500).setWidth(700); /* * Created ResourceLink object named "resourceLink" by passing above Resource object * named "pdfResource" as second parameters.The first parameter is "wicket:id" by which * markup identifies the component and renders it on web page. */ ResourceLink resourceLink = (ResourceLink) new ResourceLink("openPdf", pdfResource); //Setted the popupSettings properties of "resourceLink". resourceLink.setPopupSettings(popupSettings); //if file not found disable resourcelink in case of certificat mdical (fs == null) if (null == fs) { try { pdfResource.getResourceStream().getInputStream(); } catch (ResourceStreamNotFoundException ex) { resourceLink.setEnabled(false); } } //return resourceLink for added in page return resourceLink; }
From source file:com.axway.ats.testexplorer.pages.testcase.statistics.CsvWriter.java
License:Apache License
public DownloadLink getDownloadChartDataLink() { final String fileName = "chartDataFile.csv"; downloadFile = new DownloadLink("download", new File(fileName)) { private static final long serialVersionUID = 1L; @Override//from w w w . j av a 2 s. c o m public void onClick() { IResourceStream resourceStream = new FileResourceStream( new org.apache.wicket.util.file.File(generateFile(fileName))); getRequestCycle() .scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) { }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT)); downloadFile.setDeleteAfterDownload(true); } }; return downloadFile; }
From source file:com.doculibre.constellio.wicket.components.resource.ThemeResourceFinder.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w ww . j a v a2 s. c o m public IResourceStream find(Class clazz, String pathname) { IResourceStream result; String relPackagePath = "com/doculibre/constellio/wicket/"; SearchInterfaceConfigServices searchInterfaceConfigServices = ConstellioSpringUtils .getSearchInterfaceConfigServices(); SearchInterfaceConfig searchInterfaceConfig = searchInterfaceConfigServices.get(); String skin = searchInterfaceConfig.getSkin(); if (pathname.startsWith(relPackagePath)) { { String subPathname = "skins/" + skin + "/" + pathname.substring(relPackagePath.length()); result = null; File pluginsDir = PluginFactory.getPluginsDir(); String adjustedPathname = subPathname.replace("/", File.separator); for (String pluginName : ConstellioSpringUtils.getAvailablePluginNames()) { File pluginDir = new File(pluginsDir, pluginName); File resourcePath = new File(pluginDir, adjustedPathname); if (resourcePath.exists()) { result = new FileResourceStream(resourcePath); break; } } if (result == null) { File defaultPluginDir = new File(pluginsDir, DefaultConstellioPlugin.NAME); File defaultResourcePath = new File(defaultPluginDir, adjustedPathname); if (defaultResourcePath.exists()) { result = new FileResourceStream(defaultResourcePath); } else { result = defaultResourceFinder.find(clazz, pathname); } } } if (result == null) { String subPathname = pathname.substring(relPackagePath.length()); result = null; File pluginsDir = PluginFactory.getPluginsDir(); String adjustedPathname = subPathname.replace("/", File.separator); for (String pluginName : ConstellioSpringUtils.getAvailablePluginNames()) { File pluginDir = new File(pluginsDir, pluginName); File resourcePath = new File(pluginDir, adjustedPathname); if (resourcePath.exists()) { result = new FileResourceStream(resourcePath); break; } } if (result == null) { File defaultPluginDir = new File(pluginsDir, DefaultConstellioPlugin.NAME); File defaultResourcePath = new File(defaultPluginDir, adjustedPathname); if (defaultResourcePath.exists()) { result = new FileResourceStream(defaultResourcePath); } else { result = defaultResourceFinder.find(clazz, pathname); } } } } else { result = defaultResourceFinder.find(clazz, pathname); } return result; }
From source file:com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile.java
License:Apache License
public void onRequest() { final File file = initFile(); IResourceStream resourceStream = new FileResourceStream(new File(file)); getComponent().getRequestCycle()/*from ww w .j a v a 2 s .c o m*/ .scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) { @Override public void respond(IRequestCycle requestCycle) { try { super.respond(requestCycle); } finally { if (removeFile) { LOGGER.debug("Removing file '{}'.", new Object[] { file.getAbsolutePath() }); Files.remove(file); } } } }.setFileName(file.getName()).setContentDisposition(ContentDisposition.ATTACHMENT) .setCacheDuration(Duration.ONE_SECOND)); }