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

FileObject[] findFiles(FileSelector selector) throws FileSystemException;

Source Link

Document

Finds the set of matching descendants of this file, in depthwise order.

Usage

From source file:com.msopentech.odatajclient.testservice.utils.FSManager.java

public FileObject[] findByExtension(final FileObject fo, final String ext) throws FileSystemException {
    return fo.findFiles(new FileSelector() {

        @Override/* w  w  w .java 2  s .  c  om*/
        public boolean includeFile(final FileSelectInfo fileInfo) throws Exception {
            return fileInfo.getFile().getName().getExtension().equals(ext);
        }

        @Override
        public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception {
            return true;
        }
    });
}

From source file:com.anrisoftware.sscontrol.filesystem.FileSystem.java

private FileObject[] listFiles(FileObject location, final Pattern pattern)
        throws org.apache.commons.vfs2.FileSystemException {
    return location.findFiles(new FileSelector() {

        @Override/*w  w w .  j av  a 2  s  . c  o m*/
        public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
            return true;
        }

        @Override
        public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
            String name = fileInfo.getFile().getName().getBaseName();
            Matcher matcher = pattern.matcher(name);
            return matcher.matches();
        }
    });
}

From source file:de.unioninvestment.portal.explorer.view.vfs.VFSMainView.java

public void scanDirectory(FileSystemManager fsManager, FileSystemOptions opts, String ftpconn)
        throws IOException {
    try {/*from  ww w .j  a  v a2  s .c o m*/
        FileObject fileObject = fsManager.resolveFile(ftpconn, opts);
        FileObject[] files = fileObject.findFiles(new FileTypeSelector(FileType.FOLDER));
        HashMap<String, String> parentMap = new HashMap<String, String>();
        for (FileObject fo : files) {
            String objectName = fo.getName().toString();
            tree.addItem(objectName);
            tree.setItemIcon(objectName, FOLDER);
            if (fo.getParent() != null) {
                String parentName = fo.getParent().getName().toString();
                parentMap.put(objectName, parentName);
            } else
                tree.setItemCaption(objectName, "/");
        }

        // set parents
        logger.log(Level.INFO, "parentMap " + parentMap.size());
        if (parentMap.size() > 0) {
            Iterator<Map.Entry<String, String>> it = parentMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> pairs = it.next();
                tree.setParent(pairs.getKey(), pairs.getValue());
                String caption = pairs.getKey().toString().substring(pairs.getValue().toString().length());

                tree.setItemCaption(pairs.getKey(), removeSlash(caption));
                it.remove();
            }
        }
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
}

From source file:architecture.ee.jdbc.sqlquery.factory.impl.AbstractSqlQueryFactory.java

private FileObject[] findSqlFiles(FileObject fo) throws FileSystemException {
    return fo.findFiles(new FileSelector() {
        public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
            FileObject f = fileInfo.getFile();
            log.debug("varifing : " + f.getName());
            return StringUtils.endsWith(f.getName().getBaseName(), DEFAULT_FILE_SUFFIX);
        }/*from w w w  .ja  va2 s  .c  o  m*/

        public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
            return VFSUtils.isFolder(fileInfo.getFile());
        }
    });
}

From source file:de.innovationgate.utils.DirComparer.java

private void addFileHashes(Map<String, String> hashes, FileObject file, FileObject root)
        throws NoSuchAlgorithmException, IOException {
    if (file == null || !file.exists()) {
        return;//from ww  w  . j  av  a  2 s  . c o m
    }
    for (FileObject child : file.findFiles(_fileSelector)) {
        addFileHash(hashes, child, root);
    }
}

From source file:com.app.server.SARDeployer.java

public CopyOnWriteArrayList<String> unpack(final FileObject unpackFileObject, final File outputDir,
        StandardFileSystemManager fileSystemManager) throws IOException {
    outputDir.mkdirs();/*from  w ww  .  ja  v a2  s .com*/
    URLClassLoader webClassLoader;
    CopyOnWriteArrayList<String> classPath = new CopyOnWriteArrayList<String>();
    final FileObject packFileObject = fileSystemManager
            .resolveFile("jar:" + unpackFileObject.toString() + "!/");
    try {
        FileObject outputDirFileObject = fileSystemManager.toFileObject(outputDir);
        outputDirFileObject.copyFrom(packFileObject, new AllFileSelector());
        FileObject[] libs = outputDirFileObject.findFiles(new FileSelector() {

            public boolean includeFile(FileSelectInfo arg0) throws Exception {
                return arg0.getFile().getName().getBaseName().toLowerCase().endsWith(".jar");
            }

            public boolean traverseDescendents(FileSelectInfo arg0) throws Exception {
                // TODO Auto-generated method stub
                return true;
            }

        });
        /*String replaceString="file:///"+outputDir.getAbsolutePath().replace("\\","/");
        replaceString=replaceString.endsWith("/")?replaceString:replaceString+"/";*/
        // System.out.println(replaceString);
        for (FileObject lib : libs) {
            // System.out.println(outputDir.getAbsolutePath());
            // System.out.println(jsp.getName().getFriendlyURI());
            classPath.add(lib.getName().getFriendlyURI());
            // System.out.println(relJspName);
        }
    } finally {
        packFileObject.close();
    }
    return classPath;
}

From source file:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtility.java

/**
 * Helper method for file listing./*from   w w w .j a  v  a  2 s .  c om*/
 * 
 * @param sourceDirectoryPath
 *            Source directory path to list files from
 * @param filePatternRegex
 *            File pattern regex for file listing
 * @return Array containing file object listed by given file pattern regex
 * @throws FileSystemException
 *             If file listing fails
 */
private FileObject[] listFiles(String sourceDirectoryPath, String filePatternRegex) throws FileSystemException {
    FileObject fromDirectory = resolveFile(sourceDirectoryPath);
    log.debug("Source directory: " + fileObjectNameForDebug(fromDirectory));
    // check that both of the parameters are folders
    isFolder(fromDirectory);

    FileObject[] fileList;
    // if file pattern exists, get files from folder according to that
    if (filePatternRegex != null) {
        log.debug("Applying file pattern " + filePatternRegex);
        FileFilter ff = initFileFilter(filePatternRegex);
        fileList = fromDirectory.findFiles(new FileFilterSelector(ff));
    } else {
        // List all the files in that directory and copy each
        fileList = fromDirectory.getChildren();
    }

    fromDirectory.close();
    log.debug("Found " + fileList.length + " files in source directory");
    return fileList;
}

From source file:com.app.server.EJBDeployer.java

public void scanJar(FileObject jarFile, HashSet<Class<?>>[] classanotwith, Class[] annot, ClassLoader cL)
        throws FileSystemException {
    //FileObject[] childs=jarFile.getChildren();
    //for(FileObject child:childs){
    FileObject[] classes = jarFile.findFiles(new FileSelector() {

        @Override/*from  w ww .  java  2 s  .c o  m*/
        public boolean includeFile(FileSelectInfo arg0) throws Exception {
            return arg0.getFile().getName().getBaseName().endsWith(".class");
        }

        @Override
        public boolean traverseDescendents(FileSelectInfo arg0) throws Exception {
            // TODO Auto-generated method stub
            return true;
        }

    });
    //}
    int index = 0;
    for (FileObject cls : classes) {
        try {
            Class<?> clz = cL.loadClass(cls.getURL().toURI().toString()
                    .replace(jarFile.getURL().toURI().toString(), "").replace("/", ".").replace(".class", ""));
            index = 0;
            for (Class annotclz : annot) {
                if (clz.getAnnotation(annotclz) != null) {
                    classanotwith[index].add(clz);
                }
                index++;
            }
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:com.app.server.WarDeployer.java

public Vector<URL> unpack(final FileObject unpackFileObject, final File outputDir,
        StandardFileSystemManager fileSystemManager, ConcurrentHashMap<String, String> jsps)
        throws IOException {
    outputDir.mkdirs();//from w  w w .j av a  2 s . com
    URLClassLoader webClassLoader;
    Vector<URL> libraries = new Vector<URL>();
    final FileObject packFileObject = fileSystemManager.resolveFile(unpackFileObject.toString());
    try {
        FileObject outputDirFileObject = fileSystemManager.toFileObject(outputDir);
        outputDirFileObject.copyFrom(packFileObject, new AllFileSelector());
        FileObject[] jspFiles = outputDirFileObject.findFiles(new FileSelector() {

            public boolean includeFile(FileSelectInfo arg0) throws Exception {
                return arg0.getFile().getName().getBaseName().toLowerCase().endsWith(".jsp")
                        || arg0.getFile().getName().getBaseName().toLowerCase().endsWith(".jar");
            }

            public boolean traverseDescendents(FileSelectInfo arg0) throws Exception {
                // TODO Auto-generated method stub
                return true;
            }

        });
        String replaceString = "file:///" + outputDir.getAbsolutePath().replace("\\", "/");
        replaceString = replaceString.endsWith("/") ? replaceString : replaceString + "/";
        // System.out.println(replaceString);
        for (FileObject jsplibs : jspFiles) {
            // System.out.println(outputDir.getAbsolutePath());
            // System.out.println(jsp.getName().getFriendlyURI());
            if (jsplibs.getName().getBaseName().endsWith(".jar")) {
                libraries.add(new URL(jsplibs.getName().getFriendlyURI()));
            } else {
                String relJspName = jsplibs.getName().getFriendlyURI().replace(replaceString, "");
                jsps.put(relJspName, relJspName);
            }
            // System.out.println(relJspName);
        }
    } finally {
        packFileObject.close();
    }
    return libraries;
}

From source file:com.carrotgarden.nexus.example.script.ScriptStorageImpl.java

@Override
public void initialize() throws InitializationException {

    scriptStore = new LinkedHashMap<String, String>();

    FileObject listendir;

    try {/*from   w  w  w .  j a  v  a 2s  .  c o  m*/

        final FileSystemManager fsManager = VFS.getManager();

        scriptDir = config.getWorkingDirectory("scripts");

        if (!scriptDir.exists()) {

            scriptDir.mkdirs();

            try {

                new File(scriptDir, "place your .groovy files here.txt").createNewFile();

            } catch (final IOException e) {

                throw new InitializationException(e.getMessage(), e);

            }

        }

        listendir = fsManager.resolveFile(scriptDir.getAbsolutePath());

    } catch (final FileSystemException e) {

        throw new InitializationException(e.getMessage(), e);

    }

    final FileSelector selector = new FileSelector() {

        @Override
        public boolean traverseDescendents(final FileSelectInfo arg0) throws Exception {
            return true;
        }

        @Override
        public boolean includeFile(final FileSelectInfo arg0) throws Exception {
            return isScriptFile(arg0.getFile());
        }

    };

    try {

        final FileObject[] availableScripts = listendir.findFiles(selector);

        for (final FileObject fileObject : availableScripts) {
            updateScript(fileObject);
        }

    } catch (final FileSystemException e) {

        log.warn("Unable to perform initial directory scan.", e);

    }

    final DefaultFileMonitor monitor = new DefaultFileMonitor(this);
    monitor.setRecursive(true);
    monitor.addFile(listendir);
    monitor.start();

    this.fileMonitor = monitor;

}