Java Code Examples for org.apache.wicket.markup.html.form.upload.FileUpload#writeTo()
The following examples show how to use
org.apache.wicket.markup.html.form.upload.FileUpload#writeTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LicenseErrorPage.java From nextreports-server with Apache License 2.0 | 6 votes |
@Override protected void onSubmit() { FileUpload upload = fileUploadField.getFileUpload(); if (upload != null) { File licenseFile = new File(getUploadFolder(), "license.dat"/*upload.getClientFileName()*/); // check new file, delete if it allready existed checkFileExists(licenseFile); try { // Save to new file licenseFile.createNewFile(); upload.writeTo(licenseFile); LicenseErrorPage.this.info("Uploaded file: " + upload.getClientFileName()); setResponsePage(getApplication().getHomePage()); } catch (Exception e) { throw new IllegalStateException("Unable to write file"); } } }
Example 2
Source File: OrienteerClassLoaderUtil.java From Orienteer with Apache License 2.0 | 5 votes |
/** * Add artifact jar file to temp folder * @param artifactName artifact name * @param fileUpload {@link FileUpload} of artifact's jar * @return {@link File} of artifact's jar file or Optional.absent() if can't add artifact's jar file to folder * @throws IllegalArgumentException if artifactName is null or empty. Or when fileUpload is null. */ public static File createJarTempFile(String artifactName, FileUpload fileUpload) { Args.notEmpty(artifactName, "artifactName"); Args.notNull(fileUpload, "fileUpload"); String fileName = fileUpload.getClientFileName(); try { File file = File.createTempFile(fileName.replaceAll("\\.jar", ""), ".jar"); fileUpload.writeTo(file); return file; } catch (Exception e) { LOG.error("Cannot upload file: {}", fileName, e); } return null; }
Example 3
Source File: ScriptingPage.java From projectforge-webapp with GNU General Public License v3.0 | 5 votes |
protected void upload() { accessChecker.checkIsLoggedInUserMemberOfGroup(ProjectForgeGroup.FINANCE_GROUP, ProjectForgeGroup.CONTROLLING_GROUP); accessChecker.checkRestrictedOrDemoUser(); log.info("upload"); final FileUpload fileUpload = form.fileUploadField.getFileUpload(); if (fileUpload != null) { final boolean delete = false; try { final InputStream is = fileUpload.getInputStream(); final String clientFileName = fileUpload.getClientFileName(); if (clientFileName.endsWith(".jrxml") == true) { log.error("Jasper reports not supported."); // delete = true; // final JasperReport report = JasperCompileManager.compileReport(is); // if (report != null) { // getReportScriptingStorage().setJasperReport(report, clientFileName); // } } else if (clientFileName.endsWith(".xls") == true) { final StringBuffer buf = new StringBuffer(); buf.append("report_").append(FileHelper.createSafeFilename(PFUserContext.getUser().getUsername(), 20)).append(".xls"); final File file = new File(ConfigXml.getInstance().getWorkingDirectory(), buf.toString()); fileUpload.writeTo(file); getReportScriptingStorage().setFilename(clientFileName, file.getAbsolutePath()); } else { log.error("File extension not supported: " + clientFileName); } } catch (final Exception ex) { log.error(ex.getMessage(), ex); error("An error occurred (see log files for details): " + ex.getMessage()); } finally { if (delete == true) { fileUpload.delete(); } } } }
Example 4
Source File: ConsoleImportProjectPage.java From artifact-listener with Apache License 2.0 | 4 votes |
public ConsoleImportProjectPage(PageParameters parameters) { super(parameters); addHeadPageTitleKey("console.import.project"); // File select form final FileUploadField fileSelect = new FileUploadField("fileSelectInput", this.fileUploadsModel); fileSelect.setLabel(new ResourceModel("console.import.project.file")); fileSelect.add(AttributeModifier.replace("accept", getAcceptAttribute())); Form<Void> form = new Form<Void>("fileSelectForm") { private static final long serialVersionUID = 1L; @Override protected void onSubmit() { File file = null; try { FileUpload fileUpload = fileSelect.getFileUpload(); if (fileUpload == null) { getSession().error(getString("console.import.project.error.noFile")); return; } file = File.createTempFile("uploaded-", ".xls", configurer.getTmpDirectory()); fileUpload.writeTo(file); projectImportDataService.importProjects(file); Session.get().success(getString("console.import.project.success")); } catch (Exception e) { LOGGER.error("Unable to parse " + fileSelect.getFileUpload().getClientFileName() + " file", e); Session.get().error(getString("console.import.project.error")); } finally { FileUtils.deleteQuietly(file); } } }; form.add(fileSelect); // Example excel file download link form.add(new ResourceLink<Void>("downloadTemplate", ProjectImportModelResourceReference.get())); form.add(new SubmitLink("importButton")); add(form); }