Example usage for org.apache.commons.vfs Selectors SELECT_ALL

List of usage examples for org.apache.commons.vfs Selectors SELECT_ALL

Introduction

In this page you can find the example usage for org.apache.commons.vfs Selectors SELECT_ALL.

Prototype

FileSelector SELECT_ALL

To view the source code for org.apache.commons.vfs Selectors SELECT_ALL.

Click Source Link

Document

A FileSelector that selects the base file/folder, plus all its descendents.

Usage

From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java

public void testFolders() throws Exception {
    // root object
    FileObject rootObject = testRootObject();

    // create folder
    FileObject testFolder = testCreateTestFolder(rootObject);

    // create sub-folders
    FileObject subFolder = testFolder.resolveFile("abc/def/ghi");
    assertFalse(subFolder.exists());//from  w w w .  j  av a2  s.  c o m
    subFolder.createFolder();
    assertFolder(subFolder);
    assertSubFolders(testFolder, new String[] { "abc/def/ghi", "abc/def", "abc" });
    assertEntity(rootObject);

    // rename
    FileObject srcFolder = testFolder.resolveFile("abc/def");
    FileObject destFolder = testFolder.resolveFile("abc/xyz");
    assertTrue(testFolder.canRenameTo(destFolder));
    srcFolder.moveTo(destFolder);
    assertFolder(destFolder);
    assertFalse(srcFolder.exists());
    assertSubFolders(testFolder, new String[] { "abc/xyz/ghi", "abc/xyz", "abc" });

    // TODO: test moving a folder to a different parent

    // delete
    assertTrue(testFolder.exists());
    testFolder.delete(Selectors.SELECT_ALL);
    assertFalse(testFolder.exists());
}

From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java

/**
 * <p>//from  w w w. j  a  v  a 2  s.  c o  m
 *  ? ?? ?  .
 * </p>
 * @param source
 *        <code>String</code>
 * @param target
 *        <code>String</code>
 * @throws Exception
 */
public static void cp(String source, String target) throws Exception {

    try {
        final FileObject src = manager.resolveFile(basefile, source);
        FileObject dest = manager.resolveFile(basefile, target);

        if (dest.exists() && dest.getType() == FileType.FOLDER) {
            dest = dest.resolveFile(src.getName().getBaseName());
        }

        dest.copyFrom(src, Selectors.SELECT_ALL);
    } catch (FileSystemException fse) {
        log.error(fse.toString());
        ;
        throw new FileSystemException(fse);
    }
}

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.apache.commons.vfs.example.Shell.java

/**
 * Does a 'cp' command.//from   ww w .  j av  a  2  s  .co m
 */
private void cp(final String[] cmd) throws Exception {
    if (cmd.length < 3) {
        throw new Exception("USAGE: cp <src> <dest>");
    }

    final FileObject src = mgr.resolveFile(cwd, cmd[1]);
    FileObject dest = mgr.resolveFile(cwd, cmd[2]);
    if (dest.exists() && dest.getType() == FileType.FOLDER) {
        dest = dest.resolveFile(src.getName().getBaseName());
    }

    dest.copyFrom(src, Selectors.SELECT_ALL);
}

From source file:org.codehaus.mojo.unix.maven.sysvpkg.PkgUnixPackage.java

public FileObject fromFile(final FileObject fromFile, UnixFsObject.RegularFile file)
        throws FileSystemException {
    // If it is a file on the local file system, just point the entry in the prototype file to it
    if (fromFile.getFileSystem() instanceof LocalFileSystem) {
        return fromFile;
    }/*from   w w  w  .  jav  a 2s .  c  o  m*/

    // Creates a file under the working directory that should match the destination path
    final FileObject tmpFile = workingDirectory.resolveFile(file.path.string);

    operations = operations.cons(new Callable() {
        public Object call() throws Exception {
            OutputStream outputStream = null;
            try {
                tmpFile.getParent().createFolder();
                tmpFile.copyFrom(fromFile, Selectors.SELECT_ALL);
                tmpFile.getContent().setLastModifiedTime(fromFile.getContent().getLastModifiedTime());
            } finally {
                IOUtil.close(outputStream);
            }

            return Unit.unit();
        }
    });

    return tmpFile;
}

From source file:org.jahia.services.content.impl.vfs.VFSNodeImpl.java

public void remove() throws VersionException, LockException, ConstraintViolationException, RepositoryException {
    try {/*from ww  w.  ja v  a 2 s.  c o  m*/
        fileObject.delete(Selectors.SELECT_ALL);
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    }
}

From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java

/**
 * Does a 'cp' command.//from   w w w  .  j  a v  a 2  s  .c o m
 */
private void cp(final String[] cmd) throws Exception {
    if (cmd.length < 3) {
        throw new Exception("USAGE: cp <src> <dest>");
    }

    FileObject src = remoteMgr.resolveFile(remoteCwd, cmd[1]);
    FileObject dest = remoteMgr.resolveFile(remoteCwd, cmd[2]);
    if (dest.exists() && dest.getType() == FileType.FOLDER) {
        dest = dest.resolveFile(src.getName().getBaseName());
    }

    dest.copyFrom(src, Selectors.SELECT_ALL);
}

From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java

/**
 * Does a 'get' command.//w  w  w.  j  a  v a2s  .c o  m
 */
private void get(final String[] cmd) throws Exception {
    if (cmd.length < 3) {
        throw new Exception("USAGE: get <src> <dest>");
    }

    FileObject src = remoteMgr.resolveFile(remoteCwd, cmd[1]);
    FileObject dest = mgr.resolveFile(cwd, cmd[2]);
    if (dest.exists() && dest.getType() == FileType.FOLDER) {
        dest = dest.resolveFile(src.getName().getBaseName());
    }

    dest.copyFrom(src, Selectors.SELECT_ALL);
}

From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java

/**
 * Does a 'put' command.//from www  .  j  ava 2s. c o m
 */
private void put(final String[] cmd) throws Exception {
    if (cmd.length < 3) {
        throw new Exception("USAGE: put <src> <dest>");
    }

    FileObject src = mgr.resolveFile(cwd, cmd[2]);
    FileObject dest = remoteMgr.resolveFile(remoteCwd, cmd[1]);
    if (dest.exists() && dest.getType() == FileType.FOLDER) {
        dest = dest.resolveFile(src.getName().getBaseName());
    }

    dest.copyFrom(src, Selectors.SELECT_ALL);
}

From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java

/**
 * @param srcFolder//from ww  w. j av  a  2  s.co  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());
}