Example usage for org.apache.commons.vfs FileObject exists

List of usage examples for org.apache.commons.vfs FileObject exists

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileObject exists.

Prototype

public boolean exists() throws FileSystemException;

Source Link

Document

Determines if this file exists.

Usage

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

public boolean itemExists(String path) throws RepositoryException {
    try {//from  www  .  ja  v  a2  s .  c  o m
        FileObject object = repository.getFile(path);
        if (object.exists()) {
            return true;
        }
    } catch (FileSystemException fse) {
        return false;
    }
    return false;
}

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

public void move(String source, String dest) throws ItemExistsException, PathNotFoundException,
        VersionException, ConstraintViolationException, LockException, RepositoryException {
    try {/*  w  w w. j  a  v  a 2 s  .  co  m*/
        FileObject object1 = repository.getFile(source);
        if (!object1.exists()) {
            throw new PathNotFoundException(source);
        }
        FileObject object2 = repository.getFile(dest);
        if (object2.exists()) {
            throw new ItemExistsException(dest);
        }
        object1.moveTo(object2);
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    }

}

From source file:org.jboss.dashboard.ui.components.FileNavigationHandler.java

public void calculateStartingPath() {
    startingPath = getBaseDirPath();/*from   w ww . j  a v a  2s .com*/
    String login = "";
    if (UserStatus.lookup().isAnonymous())
        login = UserStatus.lookup().getUserLogin();
    startingPath = StringUtils.replace(startingPath, "{login}", login);

    if (!StringUtils.isEmpty(startingPath)) {
        try {
            FileObject fileObject = getFilesystemManager().getFileSystem().resolveFile(startingPath);
            if (!fileObject.exists()) {
                fileObject.createFolder();
            }
        } catch (FileSystemException e) {
            log.error("Error: ", e);
        }
    }
}

From source file:org.jboss.dashboard.ui.components.FileNavigationHandler.java

public CommandResponse actionCreateFolder(CommandRequest request) throws FileSystemException {
    if (createFolderAllowed || getUserStatus().isRootUser()) {
        FileObject currentDir = getCurrentDir();
        if (currentDir != null && currentDir.isWriteable()) {
            String folderName = request.getRequestObject().getParameter("folderName");
            FileObject fileObject = getCurrentDir().resolveFile(folderName);
            if (!fileObject.exists()) {
                fileObject.createFolder();
                openPaths.add(currentPath);
                currentPath = fileObject.getName().getPath();
                selectedFile = null;/*from   ww w.j a v  a  2  s.c o m*/
                return getCommonResponse(request);
            } else {
                //TODO: Deal with errors
            }
        }
    }
    //TODO: Deal with permission error
    return getCommonResponse(request);
}

From source file:org.jboss.dashboard.ui.components.FileNavigationHandler.java

public CommandResponse actionUploadFile(CommandRequest request) throws IOException {
    if (uploadFileAllowed || getUserStatus().isRootUser()) {
        FileObject currentDir = getCurrentDir();
        if (currentDir != null && currentDir.isWriteable()) {
            File file = (File) request.getFilesByParamName().get("file");
            if (file != null) {
                String fileName = file.getName();
                FileObject fileObject = currentDir.resolveFile(fileName);
                if (!fileObject.exists()) {
                    fileObject.createFile();
                    OutputStream os = fileObject.getContent().getOutputStream(true);
                    InputStream is = new BufferedInputStream(new FileInputStream(file));
                    IOUtils.copy(is, os);
                    is.close();//from   ww w  .j  ava  2s  .  c om
                    os.close();
                    currentFilePath = fileObject.getName().getPath();
                    return getCommonResponse(request);
                } else {
                    //TODO: Deal with errors
                }
            }
        }
    }
    //TODO: Deal with permission error
    return getCommonResponse(request);
}

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

/**
 * Does a 'cp' command.//from w w w.  ja  v  a2  s  . co 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.//from   w w  w. j a va2 s .co  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./*w w w. j  a  v a2  s .com*/
 */
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.jclouds.vfs.tools.blobstore.BlobStoreShell.java

/**
 * Does a 'cd' command. If the target directory does not exist, a message is printed to
 * <code>System.err</code>./*from  ww  w .j a  v a  2s.  c  om*/
 */
private void cd(final String[] cmd) throws Exception {
    final String path;
    if (cmd.length > 1) {
        path = cmd[1];
    } else {
        path = System.getProperty("user.home");
    }

    // Locate and validate the folder
    FileObject tmp = remoteMgr.resolveFile(remoteCwd, path);
    if (tmp.exists()) {
        remoteCwd = tmp;
    } else {
        System.out.println("Folder does not exist: " + tmp.getName().getFriendlyURI());
    }
    System.out.println("Current remote folder is " + remoteCwd.getName().getFriendlyURI());
}

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

/**
 * Does a 'lcd' command. If the target directory does not exist, a message is printed to
 * <code>System.err</code>./*from w  ww. j av a 2 s .c  o m*/
 */
private void lcd(final String[] cmd) throws Exception {
    final String path;
    if (cmd.length > 1) {
        path = cmd[1];
    } else {
        path = System.getProperty("user.home");
    }

    // Locate and validate the folder
    FileObject tmp = mgr.resolveFile(cwd, path);
    if (tmp.exists()) {
        cwd = tmp;
    } else {
        System.out.println("Folder does not exist: " + tmp.getName().getFriendlyURI());
    }
    System.out.println("Current local folder is " + cwd.getName().getFriendlyURI());
}