示例#1
0
  /**
   * Remove xml files and zipFile.
   *
   * @param zipFile
   */
  private static void removeSendedFiles(File zipFile) {
    IPath pluginSaveFolder = FeedbackUtils.getFeedbackSaveFolder();
    java.io.File source = pluginSaveFolder.toFile();
    List<java.io.File> fileList = FileHelper.listAll(source);
    for (java.io.File f : fileList) {
      if (f.getName().endsWith(FeedbackUtils.END_FILE_NAME)) {
        f.delete();
      }
    }

    try {
      File.umount(true);
    } catch (ArchiveException e) {
      e.printStackTrace();
    }

    // Delete with trueZip function doesn't work
    java.io.File testFile = new java.io.File(source, FeedbackActivator.ZIP_FILE_NAME);
    if (testFile.exists()) {
      try {
        testFile.delete();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
示例#2
0
  /**
   * Import zipped documents
   *
   * @param path Where import into the repository.
   * @param is The zip file to import.
   */
  private synchronized String importZip(String path, InputStream is)
      throws PathNotFoundException, ItemExistsException, AccessDeniedException, RepositoryException,
          IOException, DatabaseException, ExtensionException, AutomationException {
    log.debug("importZip({}, {})", path, is);
    java.io.File tmpIn = null;
    java.io.File tmpOut = null;
    String errorMsg = null;

    try {
      // Create temporal
      tmpIn = File.createTempFile("okm", ".zip");
      tmpOut = FileUtils.createTempDir();
      FileOutputStream fos = new FileOutputStream(tmpIn);
      IOUtils.copy(is, fos);
      fos.close();

      // Unzip files
      File fileTmpIn = new File(tmpIn);
      fileTmpIn.archiveCopyAllTo(tmpOut);
      File.umount();

      // Import files
      StringWriter out = new StringWriter();
      ImpExpStats stats =
          RepositoryImporter.importDocuments(
              null, tmpOut, path, false, false, false, out, new TextInfoDecorator(tmpOut));

      if (!stats.isOk()) {
        errorMsg = out.toString();
      }

      out.close();
    } catch (IOException e) {
      log.error("Error importing zip", e);
      throw e;
    } finally {
      IOUtils.closeQuietly(is);

      if (tmpIn != null) {
        org.apache.commons.io.FileUtils.deleteQuietly(tmpIn);
      }

      if (tmpOut != null) {
        org.apache.commons.io.FileUtils.deleteQuietly(tmpOut);
      }
    }

    log.debug("importZip: {}", errorMsg);
    return errorMsg;
  }