org.apache.commons.vfs2.FileSelectInfo Java Examples

The following examples show how to use org.apache.commons.vfs2.FileSelectInfo. 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: Mail.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {
    if ( !info.getFile().toString().equals( sourceFolder ) ) {
      // Pass over the Base folder itself
      String short_filename = info.getFile().getName().getBaseName();

      if ( info.getFile().getParent().equals( info.getBaseFolder() )
        || ( ( !info.getFile().getParent().equals( info.getBaseFolder() ) && meta.isIncludeSubFolders() ) ) ) {
        if ( ( info.getFile().getType() == FileType.FILE && fileWildcard == null )
          || ( info.getFile().getType() == FileType.FILE && fileWildcard != null && GetFileWildcard(
            short_filename, fileWildcard ) ) ) {
          returncode = true;
        }
      }
    }
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "Mail.Error.FindingFiles", info.getFile().toString(), e
      .getMessage() ) );
    returncode = false;
  }
  return returncode;
}
 
Example #2
Source File: Mail.java    From hop with Apache License 2.0 6 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {
    if ( !info.getFile().toString().equals( sourceFolder ) ) {
      // Pass over the Base folder itself
      String short_filename = info.getFile().getName().getBaseName();

      if ( info.getFile().getParent().equals( info.getBaseFolder() )
        || ( ( !info.getFile().getParent().equals( info.getBaseFolder() ) && meta.isIncludeSubFolders() ) ) ) {
        if ( ( info.getFile().getType() == FileType.FILE && fileWildcard == null )
          || ( info.getFile().getType() == FileType.FILE && fileWildcard != null && GetFileWildcard(
          short_filename, fileWildcard ) ) ) {
          returncode = true;
        }
      }
    }
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "Mail.Error.FindingFiles", info.getFile().toString(), e
      .getMessage() ) );
    returncode = false;
  }
  return returncode;
}
 
Example #3
Source File: JobEntryAddResultFilenames.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {
    if ( !info.getFile().toString().equals( sourceFolder ) ) {
      // Pass over the Base folder itself
      String short_filename = info.getFile().getName().getBaseName();

      if ( info.getFile().getParent().equals( info.getBaseFolder() )
        || ( !info.getFile().getParent().equals( info.getBaseFolder() ) && includeSubfolders ) ) {
        if ( ( info.getFile().getType() == FileType.FILE && fileWildcard == null )
          || ( info.getFile().getType() == FileType.FILE && fileWildcard != null && GetFileWildcard(
            short_filename, fileWildcard ) ) ) {
          returncode = true;
        }
      }
    }
  } catch ( Exception e ) {
    logError( "Error while finding files ... in ["
      + info.getFile().toString() + "]. Exception :" + e.getMessage() );
    returncode = false;
  }
  return returncode;
}
 
Example #4
Source File: CanWriteFileFilter.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to see if the file can be written to.
 *
 * @param fileInfo the File to check
 *
 * @return {@code true} if the file can be written to, otherwise {@code false}.
 * @throws FileSystemException Thrown for file system errors.
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException {
    try (final FileObject file = fileInfo.getFile()) {
        final FileSystem fileSystem = file.getFileSystem();
        if (file.exists()) {
            if (!fileSystem.hasCapability(Capability.WRITE_CONTENT)) {
                return false;
            }
            return file.isWriteable();
        }
        if (!fileSystem.hasCapability(Capability.CREATE)) {
            return false;
        }
        return file.getParent().isWriteable();
    }
}
 
Example #5
Source File: VerifyingFileSelector.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if a file or folder should be selected.
 */
@Override
public boolean includeFile(final FileSelectInfo fileInfo) throws FileSystemException {
    final FileObject file = fileInfo.getFile();
    if (file == currentFolder) {
        // Pop current folder
        assertEquals(0, children.size());
        currentFolder = currentFolder.getParent();
        currentFolderInfo = currentFolderInfo.getParent();
        children = stack.remove(0);
    }

    final String baseName = file.getName().getBaseName();

    final FileInfo childInfo = getChild(baseName);
    assertSame(childInfo.type, file.getType());

    final boolean isChild = children.remove(baseName);
    assertTrue(isChild);

    files.add(file);
    return true;
}
 
Example #6
Source File: OrFileFilterTest.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Test
public void testAccept() throws FileSystemException {

    final FileSelectInfo any = createFileSelectInfo(new File("anyfile"));

    // Empty
    Assert.assertFalse(new OrFileFilter().accept(any));

    // True
    Assert.assertTrue(new OrFileFilter(new True()).accept(any));
    Assert.assertTrue(new OrFileFilter(new True(), new True()).accept(any));
    Assert.assertTrue(new OrFileFilter(new False(), new True()).accept(any));
    Assert.assertTrue(new OrFileFilter(new True(), new False()).accept(any));

    // False
    Assert.assertFalse(new OrFileFilter(new False()).accept(any));
    Assert.assertFalse(new OrFileFilter(new False(), new False()).accept(any));

}
 
Example #7
Source File: EmptyFileFilter.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to see if the file is empty. A non-existing file is also considered empty.
 *
 * @param fileInfo the file or directory to check
 *
 * @return {@code true} if the file or directory is <i>empty</i>, otherwise {@code false}.
 * @throws FileSystemException Thrown for file system errors.
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException {
    try (final FileObject file = fileInfo.getFile()) {
        if (!file.exists()) {
            return true;
        }
        if (file.getType() == FileType.FOLDER) {
            final FileObject[] files = file.getChildren();
            return files == null || files.length == 0;
        }
        try (final FileContent content = file.getContent();) {
            return content.isEmpty();
        }
    }
}
 
Example #8
Source File: ActionAddResultFilenames.java    From hop with Apache License 2.0 6 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {
    if ( !info.getFile().toString().equals( sourceFolder ) ) {
      // Pass over the Base folder itself
      String short_filename = info.getFile().getName().getBaseName();

      if ( info.getFile().getParent().equals( info.getBaseFolder() )
        || ( !info.getFile().getParent().equals( info.getBaseFolder() ) && includeSubfolders ) ) {
        if ( ( info.getFile().getType() == FileType.FILE && fileWildcard == null )
          || ( info.getFile().getType() == FileType.FILE && fileWildcard != null && GetFileWildcard(
          short_filename, fileWildcard ) ) ) {
          returncode = true;
        }
      }
    }
  } catch ( Exception e ) {
    logError( "Error while finding files ... in ["
      + info.getFile().toString() + "]. Exception :" + e.getMessage() );
    returncode = false;
  }
  return returncode;
}
 
Example #9
Source File: LanguageFileScanSelector.java    From spoofax with Apache License 2.0 5 votes vote down vote up
@Override public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
    final FileObject file = fileInfo.getFile();
    if(isLanguageSpecDirectory(file)) {
        return true;
    }
    return file.getName().getExtension().equals("spoofax-language");
}
 
Example #10
Source File: BasicFileSelector.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
    if (fileInfo.getFile().getType() == FileType.FOLDER && fileInfo.getDepth() == 0) {
        return true;
    } else if (this.directoryFilter != null) {
        return this.directoryFilter.accept(fileInfo);
    } else {
        return this.traverseDescendents;
    }
}
 
Example #11
Source File: ZipWorkflowEntryPatternFileSelectorTest.java    From hop with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws FileSystemException {
  fileSelectInfoMock = Mockito.mock( FileSelectInfo.class );
  fileSelector = new ActionZipFile
    .ZipJobEntryPatternFileSelector( Pattern.compile( PATTERN ), Pattern.compile( EXCLUDE_PATTERN ) );
  fileObjectMock = Mockito.mock( FileObject.class );
  fileNameMock = Mockito.mock( FileName.class );

  Mockito.when( fileSelectInfoMock.getFile() ).thenReturn( fileObjectMock );
  Mockito.when( fileObjectMock.getType() ).thenReturn( FileType.FILE );
  Mockito.when( fileObjectMock.getName() ).thenReturn( fileNameMock );
  Mockito.when( fileNameMock.getBaseName() ).thenReturn( PATTERN_FILE_NAME );

}
 
Example #12
Source File: ActionFoldersCompare.java    From hop with Apache License 2.0 5 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {
    if ( !info.getFile().toString().equals( source_folder ) ) {
      // Pass over the Base folder itself
      String short_filename = info.getFile().getName().getBaseName();

      if ( info.getFile().getParent().equals( info.getBaseFolder() ) ) {
        // In the Base Folder...
        if ( ( info.getFile().getType() == FileType.FILE && compareonly.equals( "only_files" ) )
          || ( info.getFile().getType() == FileType.FOLDER && compareonly.equals( "only_folders" ) )
          || ( GetFileWildcard( short_filename ) && compareonly.equals( "specify" ) )
          || ( compareonly.equals( "all" ) ) ) {
          returncode = true;
        }
      } else {
        // Not in the Base Folder...Only if include sub folders
        if ( includesubfolders ) {
          if ( ( info.getFile().getType() == FileType.FILE && compareonly.equals( "only_files" ) )
            || ( info.getFile().getType() == FileType.FOLDER && compareonly.equals( "only_folders" ) )
            || ( GetFileWildcard( short_filename ) && compareonly.equals( "specify" ) )
            || ( compareonly.equals( "all" ) ) ) {
            returncode = true;
          }
        }
      }

    }
  } catch ( Exception e ) {

    logError( "Error while finding files ... in ["
      + info.getFile().toString() + "]. Exception :" + e.getMessage() );
    returncode = false;
  }
  return returncode;
}
 
Example #13
Source File: OrFileFilter.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException {
    for (final FileFilter fileFilter : fileFilters) {
        if (fileFilter.accept(fileInfo)) {
            return true;
        }
    }
    return false;
}
 
Example #14
Source File: JobEntryDeleteFiles.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean doReturnCode = false;
  try {

    if ( !info.getFile().toString().equals( sourceFolder ) && !parentjob.isStopped() ) {
      // Pass over the Base folder itself
      String shortFilename = info.getFile().getName().getBaseName();

      if ( !info.getFile().getParent().equals( info.getBaseFolder() ) ) {
        // Not in the Base Folder..Only if include sub folders
        if ( includeSubfolders
          && ( info.getFile().getType() == FileType.FILE ) && GetFileWildcard( shortFilename, fileWildcard ) ) {
          if ( log.isDetailed() ) {
            logDetailed( BaseMessages.getString( PKG, "JobEntryDeleteFiles.DeletingFile", info
              .getFile().toString() ) );
          }
          doReturnCode = true;
        }
      } else {
        // In the Base Folder...
        if ( ( info.getFile().getType() == FileType.FILE ) && GetFileWildcard( shortFilename, fileWildcard ) ) {
          if ( log.isDetailed() ) {
            logDetailed( BaseMessages.getString( PKG, "JobEntryDeleteFiles.DeletingFile", info
              .getFile().toString() ) );
          }
          doReturnCode = true;
        }
      }
    }
  } catch ( Exception e ) {
    log.logError(
      BaseMessages.getString( PKG, "JobDeleteFiles.Error.Exception.DeleteProcessError" ), BaseMessages
        .getString( PKG, "JobDeleteFiles.Error.Exception.DeleteProcess", info.getFile().toString(), e
          .getMessage() ) );

    doReturnCode = false;
  }

  return doReturnCode;
}
 
Example #15
Source File: JobEntryFoldersCompare.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {
    if ( !info.getFile().toString().equals( source_folder ) ) {
      // Pass over the Base folder itself
      String short_filename = info.getFile().getName().getBaseName();

      if ( info.getFile().getParent().equals( info.getBaseFolder() ) ) {
        // In the Base Folder...
        if ( ( info.getFile().getType() == FileType.FILE && compareonly.equals( "only_files" ) )
          || ( info.getFile().getType() == FileType.FOLDER && compareonly.equals( "only_folders" ) )
          || ( GetFileWildcard( short_filename ) && compareonly.equals( "specify" ) )
          || ( compareonly.equals( "all" ) ) ) {
          returncode = true;
        }
      } else {
        // Not in the Base Folder...Only if include sub folders
        if ( includesubfolders ) {
          if ( ( info.getFile().getType() == FileType.FILE && compareonly.equals( "only_files" ) )
            || ( info.getFile().getType() == FileType.FOLDER && compareonly.equals( "only_folders" ) )
            || ( GetFileWildcard( short_filename ) && compareonly.equals( "specify" ) )
            || ( compareonly.equals( "all" ) ) ) {
            returncode = true;
          }
        }
      }

    }
  } catch ( Exception e ) {

    logError( "Error while finding files ... in ["
      + info.getFile().toString() + "]. Exception :" + e.getMessage() );
    returncode = false;
  }
  return returncode;
}
 
Example #16
Source File: JobEntryCheckFilesLocked.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean returncode = false;
  try {

    if ( !info.getFile().toString().equals( sourceFolder ) ) {
      // Pass over the Base folder itself

      String shortFilename = info.getFile().getName().getBaseName();

      if ( !info.getFile().getParent().equals( info.getBaseFolder() ) ) {
        // Not in the Base Folder..Only if include sub folders
        if ( includeSubfolders ) {
          returncode = includeFileCheck( info, shortFilename );
        }
      } else {
        // In the Base Folder...
        returncode = includeFileCheck( info, shortFilename );
      }
    }

  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "JobCheckFilesLocked.Error.Exception.ProcessError" ), BaseMessages
      .getString( PKG, "JobCheckFilesLocked.Error.Exception.Process", info.getFile().toString(), e
        .getMessage() ) );
  }

  return returncode;
}
 
Example #17
Source File: ActionDeleteFiles.java    From hop with Apache License 2.0 5 votes vote down vote up
public boolean includeFile( FileSelectInfo info ) {
  boolean doReturnCode = false;
  try {

    if ( !info.getFile().toString().equals( sourceFolder ) && !parentjob.isStopped() ) {
      // Pass over the Base folder itself
      String shortFilename = info.getFile().getName().getBaseName();

      if ( !info.getFile().getParent().equals( info.getBaseFolder() ) ) {
        // Not in the Base Folder..Only if include sub folders
        if ( includeSubfolders
          && ( info.getFile().getType() == FileType.FILE ) && getFileWildcard( shortFilename, fileWildcard ) ) {
          if ( log.isDetailed() ) {
            logDetailed( BaseMessages.getString( PKG, "ActionDeleteFiles.DeletingFile", info
              .getFile().toString() ) );
          }
          doReturnCode = true;
        }
      } else {
        // In the Base Folder...
        if ( ( info.getFile().getType() == FileType.FILE ) && getFileWildcard( shortFilename, fileWildcard ) ) {
          if ( log.isDetailed() ) {
            logDetailed( BaseMessages.getString( PKG, "ActionDeleteFiles.DeletingFile", info
              .getFile().toString() ) );
          }
          doReturnCode = true;
        }
      }
    }
  } catch ( Exception e ) {
    log.logError(
      BaseMessages.getString( PKG, "JobDeleteFiles.Error.Exception.DeleteProcessError" ), BaseMessages
        .getString( PKG, "JobDeleteFiles.Error.Exception.DeleteProcess", info.getFile().toString(), e
          .getMessage() ) );

    doReturnCode = false;
  }

  return doReturnCode;
}
 
Example #18
Source File: DirectoryFileFilter.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(FileSelectInfo fileInfo) {
    try {
        return fileInfo.getFile().getType() == FileType.FOLDER;
    } catch (FileSystemException e) {
        throw new RuntimeException(e);
    }
}
 
Example #19
Source File: OrFileFilter.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(FileSelectInfo fileInfo) {
    for (FileFilter f : this.filters) {
        if (f.accept(fileInfo)) {
            return true;
        }
    }
    return false;
}
 
Example #20
Source File: ZipJobEntryPatternFileSelectorTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws FileSystemException {
  fileSelectInfoMock = Mockito.mock( FileSelectInfo.class );
  fileSelector = new JobEntryZipFile
    .ZipJobEntryPatternFileSelector( Pattern.compile( PATTERN ), Pattern.compile( EXCLUDE_PATTERN ) );
  fileObjectMock = Mockito.mock( FileObject.class );
  fileNameMock = Mockito.mock( FileName.class );

  Mockito.when( fileSelectInfoMock.getFile() ).thenReturn( fileObjectMock );
  Mockito.when( fileObjectMock.getType() ).thenReturn( FileType.FILE );
  Mockito.when( fileObjectMock.getName() ).thenReturn( fileNameMock );
  Mockito.when( fileNameMock.getBaseName() ).thenReturn( PATTERN_FILE_NAME );

}
 
Example #21
Source File: FileFilter.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
  if (fileInfo.getFile().getType() == FileType.FILE) {
    Matcher matcher = regex.matcher(fileInfo.getFile().getName().getBaseName());
    if (matcher.matches()) {
      return true;
    }
  }
  LOG.trace("{} was not included", fileInfo.getFile().getName().getPath());
  return false;
}
 
Example #22
Source File: TestFileFilter.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private FileSelectInfo createFileSelectInfo(String fileName, boolean isFile) throws Exception {
  FileSelectInfo fileSelectInfo = Mockito.mock(FileSelectInfo.class);
  FileObject fileObject = Mockito.mock(FileObject.class);
  Mockito.when(fileSelectInfo.getFile()).thenReturn(fileObject);
  if (isFile) {
    Mockito.when(fileObject.getType()).thenReturn(FileType.FILE);
  } else {
    Mockito.when(fileObject.getType()).thenReturn(FileType.FOLDER);
  }
  FileName fName = Mockito.mock(FileName.class);
  Mockito.when(fileObject.getName()).thenReturn(fName);
  Mockito.when(fName.getBaseName()).thenReturn(fileName);
  return fileSelectInfo;
}
 
Example #23
Source File: DistributedCacheUtilImpl.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
@Override
public boolean includeFile( FileSelectInfo fileSelectInfo ) throws Exception {
  if ( fileSelectInfo.getFile().equals( fileSelectInfo.getBaseFolder() ) ) {
    // Do not consider the base folders
    return false;
  }
  // Determine relative name to compare
  int baseNameLength = fileSelectInfo.getBaseFolder().getName().getPath().length() + 1;
  String relativeName = fileSelectInfo.getFile().getName().getPath().substring( baseNameLength );
  // Compare plugin folder name with the relative name
  return pluginFolderName.equals( relativeName );
}
 
Example #24
Source File: SuffixFileFilter.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if the file name ends with the suffix.
 *
 * @param fileInfo the File to check
 *
 * @return true if the file name ends with one of our suffixes
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) {
    final String name = fileInfo.getFile().getName().getBaseName();
    for (final String suffix : this.suffixes) {
        if (caseSensitivity.checkEndsWith(name, suffix)) {
            return true;
        }
    }
    return false;
}
 
Example #25
Source File: WildcardFileFilter.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if the file name matches one of the wildcards.
 *
 * @param fileInfo the file to check
 *
 * @return true if the file name matches one of the wildcards
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) {
    final String name = fileInfo.getFile().getName().getBaseName();
    for (final String wildcard : wildcards) {
        if (wildcardMatch(name, wildcard, caseSensitivity)) {
            return true;
        }
    }
    return false;
}
 
Example #26
Source File: AndFileFilter.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException {
    if (this.fileFilters.isEmpty()) {
        return false;
    }
    for (final FileFilter fileFilter : fileFilters) {
        if (!fileFilter.accept(fileInfo)) {
            return false;
        }
    }
    return true;
}
 
Example #27
Source File: PrefixFileFilter.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if the file name starts with the prefix.
 *
 * @param fileInfo the File to check
 *
 * @return true if the file name starts with one of our prefixes
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) {
    final String name = fileInfo.getFile().getName().getBaseName();
    for (final String prefix : this.prefixes) {
        if (caseSensitivity.checkStartsWith(name, prefix)) {
            return true;
        }
    }
    return false;
}
 
Example #28
Source File: ProcessFiles.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean traverseDescendents( FileSelectInfo info ) {
  return false;
}
 
Example #29
Source File: JobEntryCopyFiles.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean traverseDescendents( FileSelectInfo info ) {
  return ( traverseCount++ == 0 || include_subfolders );
}
 
Example #30
Source File: JobEntryFolderIsEmpty.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean traverseDescendents( FileSelectInfo info ) {
  return true;
}