Java Code Examples for org.apache.wicket.markup.html.form.upload.FileUpload#getClientFileName()

The following examples show how to use org.apache.wicket.markup.html.form.upload.FileUpload#getClientFileName() . 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: UploadableImagePanel.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
public void process(Optional<AjaxRequestTarget> target) {
	FileUpload fu = fileUploadField.getFileUpload();
	if (fu != null) {
		File temp = null;
		try {
			temp = fu.writeToTempFile();
			StoredFile sf = new StoredFile(fu.getClientFileName(), temp);
			if (sf.isImage()) {
				processImage(sf, temp);
			}
		} catch (Exception e) {
			log.error("Error", e);
		} finally {
			if (temp != null && temp.exists()) {
				log.debug("Temp file was deleted ? {}", temp.delete());
			}
			fu.closeStreams();
			fu.delete();
		}
	}
	update(target);
}
 
Example 2
Source File: BinaryEditPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public void convertInput() {
	if (clear.getConvertedInput())
	{
		setConvertedInput(null);
		tempName = null;
		return;
	}

	FileUpload fileUpload = fileUploadField.getFileUpload();
	if(fileUpload!=null) {
		setConvertedInput(fileUpload.getBytes());
		tempName = fileUpload.getClientFileName();
	}
	else {
		setConvertedInput(getModelObject());
	}
}
 
Example 3
Source File: DatevImportPage.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
protected void importAccountList()
{
  checkAccess();
  final FileUpload fileUpload = form.fileUploadField.getFileUpload();
  if (fileUpload != null) {
    try {
      final InputStream is = fileUpload.getInputStream();
      actionLog.reset();
      final String clientFileName = fileUpload.getClientFileName();
      setStorage(datevImportDao.importKontenplan(is, clientFileName, actionLog));
    } catch (final Exception ex) {
      log.error(ex.getMessage(), ex);
      error("An error occurred (see log files for details): " + ex.getMessage());
      clear();
    }
  }
}
 
Example 4
Source File: DatevImportPage.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
protected void importAccountRecords()
{
  checkAccess();
  final FileUpload fileUpload = form.fileUploadField.getFileUpload();
  if (fileUpload != null) {
    try {
      final InputStream is = fileUpload.getInputStream();
      actionLog.reset();
      final String clientFileName = fileUpload.getClientFileName();
      setStorage(datevImportDao.importBuchungsdaten(is, clientFileName, actionLog));
    } catch (final Exception ex) {
      log.error(ex.getMessage(), ex);
      error("An error occurred (see log files for details): " + ex.getMessage());
      clear();
    }
  }
}
 
Example 5
Source File: ReportObjectivesPage.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
protected void importReportObjectivs()
{
  checkAccess();
  log.info("import report objectives.");
  final FileUpload fileUpload = form.fileUploadField.getFileUpload();
  if (fileUpload != null) {
    try {
      final String clientFileName = fileUpload.getClientFileName();
      final InputStream is = fileUpload.getInputStream();
      final Report report = reportDao.createReport(is);
      reportStorage = new ReportStorage(report);
      reportStorage.setFileName(clientFileName);
      putUserPrefEntry(KEY_REPORT_STORAGE, reportStorage, false);
    } catch (final Exception ex) {
      log.error(ex.getMessage(), ex);
      error("An error occurred (see log files for details): " + ex.getMessage());
    }
  }
}
 
Example 6
Source File: TeamCalImportPage.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
protected void importEvents()
{
  checkAccess();
  final FileUpload fileUpload = form.fileUploadField.getFileUpload();
  if (fileUpload != null) {
    try {
      final InputStream is = fileUpload.getInputStream();
      actionLog.reset();
      final String clientFilename = fileUpload.getClientFileName();
      final CalendarBuilder builder = new CalendarBuilder();
      final Calendar calendar = builder.build(is);
      final ImportStorage<TeamEventDO> storage = teamCalImportDao.importEvents(calendar, clientFilename, actionLog);
      setStorage(storage);
    } catch (final Exception ex) {
      log.error(ex.getMessage(), ex);
      error("An error occurred (see log files for details): " + ex.getMessage());
      clear();
    } finally {
      fileUpload.closeStreams();
    }
  }
}
 
Example 7
Source File: FileUploadDownloadHelper.java    From inception with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the input stream to a temporary file. The file is deleted if the object behind marker
 * is garbage collected. The temporary file will keep its extension based on the specified file
 * name.
 *
 * @param fileUpload The file upload handle to write to the temporary file
 * @param marker The object to whose lifetime the temporary file is bound
 * @return A handle to the created temporary file
 */
public File writeFileUploadToTemporaryFile(FileUpload fileUpload, Object marker)
    throws IOException
{
    String fileName = fileUpload.getClientFileName();
    File tmpFile = File.createTempFile(INCEPTION_TMP_FILE_PREFIX, fileName);
    log.debug("Creating temporary file for [{}] in [{}]", fileName, tmpFile.getAbsolutePath());
    fileTracker.track(tmpFile, marker);
    try (InputStream is = fileUpload.getInputStream()) {
        FileUtils.copyInputStreamToFile(is, tmpFile);
    }
    return tmpFile;
}
 
Example 8
Source File: AccessSpecificSettingsPanel.java    From inception with Apache License 2.0 5 votes vote down vote up
private File uploadFile(FileUpload fu) throws IOException
{
    String fileName = fu.getClientFileName();
    if (!uploadedFiles.containsKey(fileName)) {
        FileUploadDownloadHelper fileUploadDownloadHelper = new FileUploadDownloadHelper(
            getApplication());
        File tmpFile = fileUploadDownloadHelper.writeFileUploadToTemporaryFile(fu, kbModel);
        uploadedFiles.put(fileName, tmpFile);
    }
    else {
        log.debug("File [{}] already downloaded, skipping!", fileName);
    }
    return uploadedFiles.get(fileName);
}
 
Example 9
Source File: ImportGuidelinesPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
private void actionImport(AjaxRequestTarget aTarget, Form<Void> aForm)
{
    List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
    Project project = projectModel.getObject();

    if (isNull(project.getId())) {
        aTarget.addChildren(getPage(), IFeedback.class);
        error("Project not yet created, please save project details!");
        return;
    }
    if (isEmpty(uploadedFiles)) {
        aTarget.addChildren(getPage(), IFeedback.class);
        error("No document is selected to upload, please select a document first");
        return;
    }

    for (FileUpload guidelineFile : uploadedFiles) {
        try {
            // Workaround for WICKET-6425
            File tempFile = File.createTempFile("webanno-guidelines", null);
            try (InputStream is = guidelineFile.getInputStream();
                    OutputStream os = new FileOutputStream(tempFile);) {
                IOUtils.copyLarge(is, os);

                String fileName = guidelineFile.getClientFileName();
                projectRepository.createGuideline(project, tempFile, fileName);
            }
            finally {
                tempFile.delete();
            }
        }
        catch (Exception e) {
            error("Unable to write guideline file " + ExceptionUtils.getRootCauseMessage(e));
        }
    }

    WicketUtil.refreshPage(aTarget, getPage());
}
 
Example 10
Source File: OrienteerClassLoaderUtil.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source File: UserOArtifactPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private File getJarFile(FileUploadField fileUploadField) {
    FileUpload fileUpload = fileUploadField.getFileUpload();
    if (fileUpload == null) return null;
    String clientFileName = fileUpload.getClientFileName();
    if (!fileUpload.getClientFileName().endsWith(".jar")) return null;
    return OrienteerClassLoaderUtil.createJarTempFile(clientFileName, fileUpload);
}
 
Example 12
Source File: ScriptingPage.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
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();
      }
    }
  }
}