Example usage for org.apache.commons.vfs2 FileObject findFiles

List of usage examples for org.apache.commons.vfs2 FileObject findFiles

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject findFiles.

Prototype

void findFiles(FileSelector selector, boolean depthwise, List<FileObject> selected) throws FileSystemException;

Source Link

Document

Finds the set of matching descendants of this file.

Usage

From source file:com.nesscomputing.velocity.VelocityGuiceModule.java

protected void walk(Set<String> foundTemplates, final String prefix, FileObject root)
        throws FileSystemException, URISyntaxException {
    List<FileObject> foundFiles = Lists.newArrayList();
    root.findFiles(new MacroFileSelector(), true, foundFiles);

    for (FileObject file : foundFiles) {
        String templateName = StringUtils.removeEndIgnoreCase(root.getName().getRelativeName(file.getName()),
                ".vm");
        String bindName = prefix + "." + templateName;

        if (!foundTemplates.add(bindName)) {
            continue;
        }//from   w  w w  . ja  va  2  s .c om

        UriTemplateProvider provider = new UriTemplateProvider(file.getURL().toURI());
        bind(Template.class).annotatedWith(Names.named(bindName)).toProvider(provider).in(Scopes.SINGLETON);
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.dataspace.FileSystem.java

public static ListFile list(FileObject fo, List<String> includes, List<String> excludes)
        throws FileSystemException {
    fo.refresh();/*from w ww .j  a v a 2s  .  c  om*/
    ListFile answer = new ListFile();
    List<String> dirList = Lists.newArrayList();
    List<String> fileList = Lists.newArrayList();
    List<String> fullList = Lists.newArrayList();
    List<FileObject> foundFileObjects = new LinkedList<>();
    if (isNullOrEmpty(includes) && isNullOrEmpty(excludes)) {
        fo.findFiles(Selectors.SELECT_CHILDREN, false, foundFileObjects);
    } else {
        FileSelector selector = new org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector(
                includes, excludes);
        fo.findFiles(selector, false, foundFileObjects);
    }

    for (FileObject child : foundFileObjects) {
        FileType type = child.getType();
        FileName childName = child.getName();
        switch (type) {
        case FOLDER:
            if (!child.equals(fo)) {
                // exclude root directory from the list
                String relativePath = fo.getName().getRelativeName(childName);
                dirList.add(relativePath);
                fullList.add(relativePath);
            }
            break;
        case FILE:
            String relativePath = fo.getName().getRelativeName(childName);
            fileList.add(relativePath);
            fullList.add(relativePath);
            break;
        default:
            throw new RuntimeException("Unknown : " + type);
        }
    }
    Collections.sort(dirList);
    Collections.sort(fileList);
    Collections.sort(fullList);
    answer.setDirectoryListing(dirList);
    answer.setFileListing(fileList);
    answer.setFullListing(fullList);
    return answer;
}

From source file:org.ow2.proactive_grid_cloud_portal.dataspace.FileSystem.java

public static List<FileObject> findFiles(FileObject root, List<String> includes, List<String> excludes)
        throws FileSystemException {
    root.refresh();//ww w . j a  va2s  . c  o  m
    List<FileObject> files = Lists.newArrayList();
    FileSelector selector = (isNullOrEmpty(includes) && isNullOrEmpty(excludes)) ? new AllFilesSelector()
            : new org.objectweb.proactive.extensions.dataspaces.vfs.selector.FileSelector(includes, excludes);
    root.findFiles(selector, true, files);
    return files;
}