/**
  * Creates a new file in the repository
  *
  * @param bundle
  * @param destinationPath
  * @param bundlePath
  * @param ext
  * @param data
  * @param comment
  */
 protected RepositoryFile createFile(
     final ImportSource.IRepositoryFileBundle bundle,
     final String destinationPath,
     final boolean hidden,
     final IRepositoryFileData data,
     final String comment) {
   final RepositoryFile file =
       new RepositoryFile.Builder(bundle.getFile())
           .hidden(hidden)
           .title(RepositoryFile.DEFAULT_LOCALE, getTitle(bundle.getFile().getName()))
           .versioned(true)
           .build();
   final Serializable parentId = getParentId(destinationPath);
   final RepositoryFileAcl acl = bundle.getAcl();
   if (null == acl) {
     return repository.createFile(parentId, file, data, comment);
   } else {
     return repository.createFile(parentId, file, data, acl, comment);
   }
 }
  /**
   * Processes the list of files and performs any processing required to import that data into the
   * repository. If during processing it handles file(s) which should not be handled by downstream
   * import handlers, then it should remove them from the set of files provided.
   *
   * @param importFileSet the set of files to be imported - any files handled to completion by this
   *     Import Handler should remove this files from this list
   * @param comment the import comment provided
   * @param overwrite indicates if the process is authorized to overwrite existing content in the
   *     repository
   * @throws ImportException indicates a significant error during import processing
   */
  @Override
  public void doImport(
      final Iterable<ImportSource.IRepositoryFileBundle> importFileSet,
      final String destinationPath,
      final String comment,
      final boolean overwrite)
      throws ImportException {
    if (null == importFileSet || StringUtils.isEmpty(destinationPath)) {
      throw new IllegalArgumentException();
    }

    // Ensure the destination path is valid
    Assert.notNull(
        getParentId(RepositoryFilenameUtils.normalize(destinationPath + RepositoryFile.SEPARATOR)));

    // Iterate through the file set
    for (Iterator<IRepositoryFileBundle> iterator = importFileSet.iterator();
        iterator.hasNext(); ) {
      final ImportSource.IRepositoryFileBundle bundle =
          (ImportSource.IRepositoryFileBundle) iterator.next();

      // Make sure we don't try to do anything in a system-defined folder
      final String bundlePathName =
          RepositoryFilenameUtils.concat(computeBundlePath(bundle), bundle.getFile().getName());
      if (isSystemPath(bundlePathName)) {
        log.trace("Skipping [" + bundlePathName + "] since it is in admin / system folders");
        continue;
      }
      final String repositoryFilePath =
          RepositoryFilenameUtils.concat(destinationPath, bundlePathName);
      log.trace("Processing [" + bundlePathName + "]");

      // See if the destination already exists in the repository
      final RepositoryFile file = repository.getFile(repositoryFilePath);
      if (file != null) {
        if (file.isFolder() != bundle.getFile().isFolder()) {
          log.warn(
              "Entry already exists in the repository - but it is a "
                  + (file.isFolder() ? "folder" : "file")
                  + " and the entry to be imported is a "
                  + (bundle.getFile().isFolder() ? "folder" : "file"));
        }

        if (!overwrite) {
          log.trace("File already exists in repository and overwrite is false - skipping");
        } else if (file.isFolder()) {
          log.trace("Folder already exists - skip");
        } else {
          // It is a file we can overwrite...
          log.trace("Updating...");
          copyFileToRepository(bundle, bundlePathName, repositoryFilePath, file, comment);
        }
        // We handled this file (even if by doing nothing)
        iterator.remove();
        continue;
      }

      // The file doesn't exist - if it is a folder then this is easy
      if (bundle.getFile().isFolder()) {
        log.trace("Creating folder [" + bundlePathName + "]");
        final Serializable parentId = getParentId(repositoryFilePath);
        if (bundle.getAcl() != null) {
          repository.createFolder(parentId, bundle.getFile(), bundle.getAcl(), comment);
        } else {
          repository.createFolder(parentId, bundle.getFile(), comment);
        }
        iterator.remove();
      } else {
        // It is a file ...
        if (copyFileToRepository(bundle, bundlePathName, repositoryFilePath, null, comment)) {
          iterator.remove();
        }
      }
    }
  }