List of usage examples for org.apache.commons.vfs Selectors EXCLUDE_SELF
FileSelector EXCLUDE_SELF
To view the source code for org.apache.commons.vfs Selectors EXCLUDE_SELF.
Click Source Link
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java
private static void assertSubFolders(FileObject testFolder, String[] subFolderNames) throws Exception { FileName rootName = testFolder.getFileSystem().getRootName(); FileObject[] subFolders = testFolder.findFiles(Selectors.EXCLUDE_SELF); assertEquals(subFolders.length, subFolderNames.length); for (int i = 0; i < subFolders.length; i++) { FileObject subObject = subFolders[i]; assertTrue(subObject.getName().getPath().endsWith(subFolderNames[i])); assertFolder(subObject);/* ww w . j a v a 2 s . c o m*/ assertEquals(subObject.getParent(), i == subFolders.length - 1 ? testFolder : subFolders[i + 1]); assertTrue(rootName.isDescendent(subObject.getName())); assertTrue(subObject.getName().isAncestor(rootName)); } }
From source file:egovframework.rte.fdl.filehandling.FilehandlingServiceTest.java
/** * ? ? , ? ?? ?? ?/* w w w. j av a2 s .c o m*/ * ? ? ? ? . * @throws Exception */ @Test public void testCaching() throws Exception { String testFolder = "d:/workspace/java/e-gov/eGovFramework/RTE/DEV/trunk/Foundation/egovframework.rte.fdl.filehandling/testfolder"; FileSystemManager manager = VFS.getManager(); FileObject scratchFolder = manager.resolveFile(testFolder); // testfolder ? ? scratchFolder.delete(Selectors.EXCLUDE_SELF); // ? Manager ? DefaultFileSystemManager fs = new DefaultFileSystemManager(); fs.setFilesCache(manager.getFilesCache()); // zip, jar, tgz, tar, tbz2, file if (!fs.hasProvider("file")) { fs.addProvider("file", new DefaultLocalFileProvider()); } fs.setCacheStrategy(CacheStrategy.ON_RESOLVE); fs.init(); // ? ? ? FileObject foBase2 = fs.resolveFile(testFolder); log.debug("## scratchFolder.getName().getPath() : " + scratchFolder.getName().getPath()); FileObject cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath()); // ?? ? FileObject[] fos = cachedFolder.getChildren(); assertFalse(contains(fos, "file1.txt")); // ?? scratchFolder.resolveFile("file1.txt").createFile(); // ? // BUT cachedFolder ? ?? ? fos = cachedFolder.getChildren(); assertFalse(contains(fos, "file1.txt")); // cachedFolder.refresh(); // ?? fos = cachedFolder.getChildren(); assertTrue(contains(fos, "file1.txt")); }
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java
private void testFindFiles(FileObject rootObject) throws Exception { FileObject[] findFiles = rootObject.findFiles(Selectors.EXCLUDE_SELF); findFiles = rootObject.findFiles(Selectors.SELECT_ALL); findFiles = rootObject.findFiles(Selectors.SELECT_CHILDREN); findFiles = rootObject.findFiles(Selectors.SELECT_FILES); findFiles = rootObject.findFiles(Selectors.SELECT_FOLDERS); findFiles = rootObject.findFiles(Selectors.SELECT_SELF); findFiles = rootObject.findFiles(Selectors.SELECT_SELF_AND_CHILDREN); }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
/** * @param srcFolder/*from w ww . ja v a 2 s . c o m*/ * @param destDir * @param replace * @throws java.io.IOException */ protected void installFolder(FileObject srcFolder, FileObject destDir, String newName, boolean replace) throws IOException { // Check destination folder if (!destDir.exists()) { printInstallErrStatus(srcFolder.getName().getBaseName(), "Target directory not found " + destDir.getName().getBaseName()); throw new IOException("Target directory not found " + destDir.getName().getBaseName()); } // This is the new folder we're creating in destination. FileObject newFolder = destDir.resolveFile(newName); boolean exists = newFolder.exists(); if (!replace && exists) { printInstallWarnStatus(newFolder.getName().getBaseName(), "Not replaced (see --replace option)"); return; } if (exists) { // remove all descendents (removes old jars and other files when upgrading josso gateway) newFolder.delete(Selectors.EXCLUDE_SELF); } newFolder.copyFrom(srcFolder, Selectors.SELECT_ALL); // Copy ALL descendats printInstallOkStatus(srcFolder.getName().getBaseName(), (exists ? "Replaced " : "Created ") + newFolder.getName().getFriendlyURI()); }
From source file:org.objectweb.proactive.extensions.dataspaces.vfs.adapter.VFSFileObjectAdapter.java
/** * @param selector// ww w. j a v a 2s . co m * may be null */ private static org.apache.commons.vfs.FileSelector buildFVSSelector(FileSelector selector) { switch (selector) { case EXCLUDE_SELF: return Selectors.EXCLUDE_SELF; case SELECT_ALL: return Selectors.SELECT_ALL; case SELECT_FILES: return Selectors.SELECT_FILES; case SELECT_FOLDERS: return Selectors.SELECT_FOLDERS; case SELECT_CHILDREN: return Selectors.SELECT_CHILDREN; case SELECT_SELF: return Selectors.SELECT_SELF; case SELECT_SELF_AND_CHILDREN: return Selectors.SELECT_SELF_AND_CHILDREN; default: return null; } }
From source file:org.objectweb.proactive.extensions.dataspaces.vfs.VFSNodeScratchSpaceImpl.java
public synchronized void init(Node node, BaseScratchSpaceConfiguration conf) throws FileSystemException, ConfigurationException, IllegalStateException { logger.debug("Initializing node scratch space"); if (configured) { logger.error("Attempting to configure already configured node scratch space"); throw new IllegalStateException("Instance already configured"); }/*from w w w. jav a2 s . c om*/ if (conf.getUrls() == null) { throw new ConfigurationException("No remote access URL defined in base scratch configuration"); } this.node = node; this.baseScratchConfiguration = conf; try { fileSystemManager = VFSFactory.createDefaultFileSystemManager(); } catch (org.apache.commons.vfs.FileSystemException x) { logger.error("Could not create and configure VFS manager", x); throw new FileSystemException(x); } try { final String nodeId = Utils.getNodeId(node); final String runtimeId = Utils.getRuntimeId(node); final String[] originalUrls = baseScratchConfiguration.getUrls(); // find the file url in the list (it should be the first one) URI fileUri = null; for (String url : originalUrls) { try { URI uri = new URI(url); if (uri.getScheme().equals("file")) { fileUri = uri; break; } } catch (URISyntaxException e) { logger.error("Could not initialize scratch space"); throw new FileSystemException(e); } } String localAccessUrl; if (fileUri != null) { // if a file url was among the list use it localAccessUrl = Utils.getLocalAccessURL((new File(fileUri)).getAbsolutePath(), baseScratchConfiguration.getPath(), Utils.getHostname()); } else { // otherwise compute a new url using the configuration root path localAccessUrl = Utils.getLocalAccessURL(originalUrls[0], baseScratchConfiguration.getPath(), Utils.getHostname()); } final String partialSpacePath = Utils.appendSubDirs(localAccessUrl, runtimeId, nodeId); logger.debug("Accessing scratch space location: " + partialSpacePath); try { partialSpaceFile = fileSystemManager.resolveFile(partialSpacePath); checkCapabilities(partialSpaceFile.getFileSystem()); partialSpaceFile.delete(Selectors.EXCLUDE_SELF); partialSpaceFile.createFolder(); if (!partialSpaceFile.isWriteable()) { throw new org.apache.commons.vfs.FileSystemException( "Created directory is unexpectedly not writable"); } // just a hint partialSpaceFile.close(); } catch (org.apache.commons.vfs.FileSystemException x) { logger.error("Could not initialize scratch space at: " + partialSpacePath); throw new FileSystemException(x); } configured = true; logger.debug("Initialized node scratch space at: " + partialSpacePath); } finally { if (!configured) fileSystemManager.close(); } }
From source file:org.objectweb.proactive.extensions.dataspaces.vfs.VFSNodeScratchSpaceImpl.java
private FileObject createEmptyDirectoryRelative(final FileObject parent, final String path) throws org.apache.commons.vfs.FileSystemException { FileObject f = parent.resolveFile(path); f.delete(Selectors.EXCLUDE_SELF); f.createFolder();/*from w w w. j a v a 2 s.c o m*/ return f; }
From source file:pt.webdetails.cpf.repository.VfsRepositoryTest.java
/** * Please do note this will remove the folder and all subfolders and files Used for testing purposes only * * @param file/* w w w .j a v a 2 s.co m*/ * @return */ public int removeUnsafe(String file) { try { if (file.equals(".")) { return repo.delete(Selectors.EXCLUDE_SELF); } FileObject f = resolveFile(repo, file); if (f.exists()) { return f.delete(Selectors.SELECT_ALL); } return -1; } catch (Exception e) { throw new RuntimeException("Cannot delete file: " + file, e); } }