List of usage examples for org.apache.commons.vfs FileSelector FileSelector
FileSelector
From source file:com.thinkberg.webdav.CopyHandler.java
protected void copyOrMove(FileObject object, FileObject target, final int depth) throws FileSystemException { target.copyFrom(object, new FileSelector() { public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { return fileSelectInfo.getDepth() <= depth; }//from w w w .java 2s . co m public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { return fileSelectInfo.getDepth() < depth; } }); }
From source file:com.thinkberg.moxo.vfs.s3.S3FileProviderTest.java
public void testDeleteFolder() throws FileSystemException { FileObject object = VFS.getManager().resolveFile(ROOT + "/newfolder"); object.delete(new FileSelector() { public boolean includeFile(FileSelectInfo fileInfo) throws Exception { return true; }// ww w .j av a2s . c o m public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception { return true; } }); }
From source file:com.sonatype.nexus.plugin.groovyconsole.DefaultScriptStorage.java
public void initialize() throws InitializationException { scripts = new LinkedHashMap<String, String>(); FileObject listendir;//from www . j av a 2 s. c o m try { FileSystemManager fsManager = VFS.getManager(); scriptDir = applicationConfiguration.getWorkingDirectory("scripts"); if (!scriptDir.exists()) { scriptDir.mkdirs(); try { new File(scriptDir, "place your .groovy files here.txt").createNewFile(); } catch (IOException e) { throw new InitializationException(e.getMessage(), e); } } listendir = fsManager.resolveFile(scriptDir.getAbsolutePath()); } catch (FileSystemException e) { throw new InitializationException(e.getMessage(), e); } FileSelector selector = new FileSelector() { public boolean traverseDescendents(FileSelectInfo arg0) throws Exception { return true; } public boolean includeFile(FileSelectInfo arg0) throws Exception { return isScriptFile(arg0.getFile()); } }; try { FileObject[] availableScripts = listendir.findFiles(selector); for (FileObject fileObject : availableScripts) { updateScript(fileObject); } } catch (FileSystemException e) { getLogger().warn("Unable to perform initial directory scan.", e); } DefaultFileMonitor fm = new DefaultFileMonitor(this); fm.setRecursive(true); fm.addFile(listendir); fm.start(); this.fileMonitor = fm; }
From source file:org.efaps.webdav4vfs.handler.CopyHandler.java
@Override() protected void copyOrMove(final FileObject object, final FileObject target, final int depth) throws FileSystemException { target.copyFrom(object, new FileSelector() { public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { return fileSelectInfo.getDepth() <= depth; }/*from www. jav a2 s. co m*/ public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { return fileSelectInfo.getDepth() < depth; } }); }
From source file:org.geoserver.importer.VFSWorker.java
/** * /*w w w.ja va2s . co m*/ * @param archiveFile * @param filter * * @return */ public List<String> listFiles(final File archiveFile, final FilenameFilter filter) { FileSystemManager fsManager; try { fsManager = VFS.getManager(); String absolutePath = resolveArchiveURI(archiveFile); FileObject resolvedFile = fsManager.resolveFile(absolutePath); FileSelector fileSelector = new FileSelector() { /** * @see org.apache.commons.vfs.FileSelector#traverseDescendents(org.apache.commons.vfs.FileSelectInfo) */ public boolean traverseDescendents(FileSelectInfo folderInfo) throws Exception { return true; } /** * @see org.apache.commons.vfs.FileSelector#includeFile(org.apache.commons.vfs.FileSelectInfo) */ public boolean includeFile(FileSelectInfo fileInfo) throws Exception { File folder = archiveFile.getParentFile(); String name = fileInfo.getFile().getName().getFriendlyURI(); return filter.accept(folder, name); } }; FileObject fileSystem; if (fsManager.canCreateFileSystem(resolvedFile)) { fileSystem = fsManager.createFileSystem(resolvedFile); } else { fileSystem = resolvedFile; } LOGGER.fine("Listing spatial data files archived in " + archiveFile.getName()); FileObject[] containedFiles = fileSystem.findFiles(fileSelector); List<String> names = new ArrayList<String>(containedFiles.length); for (FileObject fo : containedFiles) { // path relative to its filesystem (ie, to the archive file) String pathDecoded = fo.getName().getPathDecoded(); names.add(pathDecoded); } LOGGER.fine("Found " + names.size() + " spatial data files in " + archiveFile.getName() + ": " + names); return names; } catch (FileSystemException e) { e.printStackTrace(); } finally { // fsManager.closeFileSystem(fileSystem.getFileSystem()); } return Collections.emptyList(); }
From source file:org.mule.transports.vfs.VFSReceiver.java
public void poll() { try {//www .ja v a 2 s . c o m dirObject.refresh(); if (dirObject.exists()) { if (dirObject.getType() == FileType.FOLDER) { FileObject[] files = null; files = dirObject.findFiles(new FileSelector() { public boolean includeFile(FileSelectInfo fileInfo) throws java.lang.Exception { if ((!fileInfo.getFile().isHidden()) && (fileInfo.getFile().getType() != FileType.FOLDER)) { if (fileExtension.equals("*")) { return true; } else { return (fileInfo.getFile().getName().getPath().endsWith(fileExtension)); } } else { return false; } } public boolean traverseDescendents(FileSelectInfo fileInfo) throws java.lang.Exception { if (includeSubfolders) { return (!fileInfo.getFile().isHidden()); } else { return ((!fileInfo.getFile().isHidden()) && fileInfo.getDepth() < 2); } } }); boolean autoDelete = ((VFSConnector) connector).isAutoDelete(); for (int i = 0; i < files.length; i++) { if (autoDelete) { processFile(files[i]); if (!files[i].delete()) { throw new MuleException(new Message("vfs", 3, files[i].getName())); } } else if (hasChanged(files[i])) { processFile(files[i]); } } } } } catch (Exception e) { Exception handled = e; if (e instanceof FileSystemException) { handled = new ConnectException(e, this); } handleException(handled); } }
From source file:org.nanocontainer.deployer.NanoContainerDeployer.java
private FileObject getDeploymentScript(FileObject applicationFolder) throws FileSystemException { final FileObject metaInf = applicationFolder.getChild("META-INF"); if (metaInf == null) { throw new FileSystemException("Missing META-INF folder in " + applicationFolder.getName().getPath()); }//from www . j a v a 2 s. co m final FileObject[] nanocontainerScripts = metaInf.findFiles(new FileSelector() { public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { return fileSelectInfo.getFile().getName().getBaseName().startsWith("nanocontainer"); } public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { return true; } }); if (nanocontainerScripts == null || nanocontainerScripts.length < 1) { throw new FileSystemException("No deployment script (nanocontainer.[groovy|bsh|js|py|xml]) in " + applicationFolder.getName().getPath() + "/META-INF"); } return nanocontainerScripts[0]; }
From source file:org.pentaho.di.core.plugins.BasePluginType.java
protected List<FileObject> findPluginFiles(String folder, final String regex) { List<FileObject> list = new ArrayList<FileObject>(); try {/*from ww w . j av a 2 s .c om*/ FileObject folderObject = KettleVFS.getFileObject(folder); FileObject[] files = folderObject.findFiles(new FileSelector() { @Override public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { return true; } @Override public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { return fileSelectInfo.getFile().toString().matches(regex); } }); if (files != null) { for (FileObject file : files) { list.add(file); } } } catch (Exception e) { // ignore this: unknown folder, insufficient permissions, etc } return list; }
From source file:org.pentaho.di.core.plugins.PluginFolder.java
public FileObject[] findJarFiles(final boolean includeLibJars) throws KettleFileException { try {/*from w w w . j ava 2s . c om*/ // Find all the jar files in this folder... // FileObject folderObject = KettleVFS.getFileObject(this.getFolder()); FileObject[] fileObjects = folderObject.findFiles(new FileSelector() { @Override public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { FileObject fileObject = fileSelectInfo.getFile(); String folder = fileObject.getName().getBaseName(); FileObject kettleIgnore = fileObject.getChild(".kettle-ignore"); return includeLibJars || (kettleIgnore == null && !"lib".equals(folder)); } @Override public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { return fileSelectInfo.getFile().toString().endsWith(".jar"); } }); return fileObjects; } catch (Exception e) { throw new KettleFileException("Unable to list jar files in plugin folder '" + toString() + "'", e); } }
From source file:org.pentaho.di.job.entries.hadooptransjobexecutor.DistributedCacheUtil.java
/** * Recursively searches for all files starting at the directory provided with the extension provided. If no extension * is provided all files will be returned. * * @param root Directory to start the search for files in * @param extension File extension to search for. If null all files will be returned. * @return List of absolute path names to all files found in {@code dir} and its subdirectories. * @throws KettleFileException//w ww. j a va 2 s. c o m * @throws FileSystemException */ public List<String> findFiles(FileObject root, final String extension) throws FileSystemException { FileObject[] files = root.findFiles(new FileSelector() { @Override public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { return extension == null || extension.equals(fileSelectInfo.getFile().getName().getExtension()); } @Override public boolean traverseDescendents(FileSelectInfo fileSelectInfo) throws Exception { return FileType.FOLDER.equals(fileSelectInfo.getFile().getType()); } }); if (files == null) { return Collections.EMPTY_LIST; } List<String> paths = new ArrayList<String>(); for (FileObject file : files) { try { paths.add(file.getURL().toURI().getPath()); } catch (URISyntaxException ex) { throw new FileSystemException("Error getting URI of file: " + file.getURL().getPath()); } } return paths; }