Example usage for org.apache.commons.vfs2 FileSelectInfo getFile

List of usage examples for org.apache.commons.vfs2 FileSelectInfo getFile

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileSelectInfo getFile.

Prototype

FileObject getFile();

Source Link

Document

Returns the file (or folder) to be considered.

Usage

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);
        }//  ww  w. ja v  a2  s .  c  o  m

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

From source file:com.gs.obevo.impl.DisabledOnboardingStrategy.java

@Override
public void validateSourceDirs(RichIterable<FileObject> sourceDirs, final ImmutableSet<String> schemaNames) {
    for (FileObject sourceDir : sourceDirs) {
        // Only check for the schema folders under the source dirs to minimize any noise in this check.
        // This logic matches DbDirectoryChangesetReader - ideally we should try to share this code logic
        MutableList<FileObject> schemaDirs = ArrayAdapter
                .adapt(sourceDir.findFiles(new BasicFileSelector(new FileFilter() {
                    @Override// w w  w. j  a  v  a  2  s .co  m
                    public boolean accept(final FileSelectInfo fileInfo) {
                        return schemaNames.anySatisfy(new Predicate<String>() {
                            @Override
                            public boolean accept(String schemaName) {
                                return fileInfo.getFile().getName().getBaseName().equalsIgnoreCase(schemaName);
                            }
                        });
                    }
                })));

        MutableList<FileObject> onboardFiles = schemaDirs
                .flatCollect(new Function<FileObject, List<FileObject>>() {
                    @Override
                    public List<FileObject> valueOf(FileObject schemaDir) {
                        return ArrayAdapter.adapt(schemaDir.findFiles(new BasicFileSelector(new FileFilter() {
                            @Override
                            public boolean accept(FileSelectInfo fileInfo) {
                                return fileInfo.getFile().getName().getBaseName()
                                        .equalsIgnoreCase(EXCEPTION_DIR)
                                        || fileInfo.getFile().getName().getBaseName()
                                                .equalsIgnoreCase(DEPENDENT_EXCEPTION_DIR)
                                        || fileInfo.getFile().getName().getBaseName()
                                                .endsWith(DaConstants.ANALYZE_FOLDER_SUFFIX);
                            }
                        }, true)));
                    }
                });

        if (onboardFiles.notEmpty()) {
            throw new IllegalArgumentException("Directory " + sourceDir
                    + " has the exception folders in it that need to get removed before doing regular deployments: "
                    + onboardFiles);
        }
    }
}

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 ww  .ja va 2  s.  com*/
        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:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtility.java

/**
 * Creates File filter that matches file names to given regex
 *
 * @param regex//from ww  w . ja  v  a2s.  co  m
 * @return
 */
private FileFilter initFileFilter(final String regex) {
    FileFilter ff = new FileFilter() {
        public boolean accept(FileSelectInfo fileInfo) {
            FileObject fo = fileInfo.getFile();
            return fo.getName().getBaseName().matches(regex);
        }

    };
    return ff;
}

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

@Override
public void initialize() throws InitializationException {

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

    FileObject listendir;/*from  w  ww .ja  v a  2 s.c o  m*/

    try {

        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;

}

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 .j a  v  a 2  s  . co m
    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: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 w  w  . j  av  a  2s. 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();// w  w w.ja  v a2s  .co  m
    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:org.aludratest.service.file.impl.FilePathSelector.java

/** Includes only the file with the expected {@link #absolutePath}. */
public boolean includeFile(FileSelectInfo fileInfo) {
    return absolutePath.equals(fileInfo.getFile().getName().getPath());
}

From source file:org.apache.olingo.fit.utils.FSManager.java

public final FileObject[] find(final FileObject fo, final String ext) throws FileSystemException {
    return fo.findFiles(new FileSelector() {
        @Override//from ww  w  .j ava 2 s.  c o m
        public boolean includeFile(final FileSelectInfo fileInfo) throws Exception {
            return ext == null ? true : fileInfo.getFile().getName().getExtension().equals(ext);
        }

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