Example usage for org.apache.commons.vfs2 FileType hasChildren

List of usage examples for org.apache.commons.vfs2 FileType hasChildren

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileType hasChildren.

Prototype

boolean hasChildren

To view the source code for org.apache.commons.vfs2 FileType hasChildren.

Click Source Link

Document

true if the FileType can have children

Usage

From source file:org.pentaho.di.plugins.fileopensave.providers.vfs.VFSFileProvider.java

/**
 * @param file//from   ww w . ja  v a 2  s .com
 * @param filters
 * @return
 */
@Override
public List<VFSFile> getFiles(VFSFile file, String filters) {
    if (file.getPath() == null) {
        return getRoot(file);
    }
    List<VFSFile> files = new ArrayList<>();
    try {
        FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(),
                VFSHelper.getOpts(file.getPath(), file.getConnection()));
        FileType fileType = fileObject.getType();
        if (fileType.hasChildren()) {
            FileObject[] children = fileObject.getChildren();
            for (FileObject child : children) {
                FileType fileType1 = child.getType();
                if (fileType1.hasChildren()) {
                    files.add(VFSDirectory.create(file.getPath(), child, file.getConnection()));
                } else {
                    if (Utils.matches(child.getName().getBaseName(), filters)) {
                        files.add(VFSFile.create(file.getPath(), child, file.getConnection()));
                    }
                }
            }
        }
    } catch (KettleFileException | FileSystemException ignored) {
        // File does not exist
    }
    return files;
}