예제 #1
0
  /** @see Form#onSubmit() */
  @Override
  protected void onSubmit() {
    final String project = identifier.getModel().getObject();
    try {
      final FileUpload upload = file.getFileUpload();
      if (upload != null) {
        File dir = projects.reserveResourceId(project);

        //				File target = new File(dir, upload.getClientFileName());
        String type = upload.getContentType();
        if (checkContentType(type)) {
          //					IOUtils.copy(upload.getInputStream(), new FileOutputStream(target));

          // try extracting the archive
          IOUtils.extract(dir, new BufferedInputStream(upload.getInputStream()));

          // trigger scan after upload
          projects.triggerScan();
          info("Successfully uploaded project");

          onUploadSuccess();
        } else {
          projects.releaseResourceId(project);
          error(getTypeErrorMessage(type));
        }
      } else {
        warn("Please provide a file for upload");
      }
    } catch (ScavengerException e) {
      error(e.getMessage());
    } catch (Exception e) {
      projects.releaseResourceId(project);
      log.error("Error while uploading file", e);
      error("Error saving the file");
    }
  }