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

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

Introduction

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

Prototype

public FileName getName();

Source Link

Document

Returns the name of this file.

Usage

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

/**
 * Does a 'cp' command./* w ww.j  a  va 2s  . 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  ava  2s.  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 a va 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.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>./*w  ww  . j ava2s  .c  o m*/
 */
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>.// ww  w . j  a  v  a2 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());
}

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

private void ls(FileSystemManager mg, FileObject wd, final String[] cmd) throws FileSystemException {
    int pos = 1;//from  ww w . ja  v  a 2  s. c  o m
    final boolean recursive;
    if (cmd.length > pos && cmd[pos].equals("-R")) {
        recursive = true;
        pos++;
    } else {
        recursive = false;
    }

    final FileObject file;
    if (cmd.length > pos) {
        file = mg.resolveFile(wd, cmd[pos]);
    } else {
        file = wd;
    }

    if (file.getType() == FileType.FOLDER) {
        // List the contents
        System.out.println("Contents of " + file.getName().getFriendlyURI());
        listChildren(file, recursive, "");
    } else {
        // Stat the file
        System.out.println(file.getName());
        final FileContent content = file.getContent();
        System.out.println("Size: " + content.getSize() + " bytes.");
        final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime()));
        System.out.println("Last modified: " + lastMod);
    }
}

From source file:org.josso.tooling.gshell.install.commands.InstallJavaAgentCommand.java

private void processDir(FileObject dir, boolean recursive) throws Exception { //recursively traverse directories
    FileObject[] children = dir.getChildren();
    for (FileObject subfile : children) {
        if (subfile.getType() == FileType.FOLDER) {
            if (recursive)
                processDir(subfile, recursive);
        } else {//  w  ww.  j  a v  a  2 s.c o  m
            getInstaller().installComponent(createArtifact(subfile.getParent().getURL().toString(),
                    JOSSOScope.AGENT, subfile.getName().getBaseName()), true);
        }
    }
}

From source file:org.josso.tooling.gshell.install.commands.InstallJavaAgentCommand.java

protected void installJOSSOAgentJarsFromSrc() throws Exception {

    if (!srcsDir.exists())
        return;// ww  w  .  j ava 2 s .  c  om

    FileObject[] agentBins = srcsDir.getChildren();
    for (int i = 0; i < agentBins.length; i++) {
        FileObject agentBin = agentBins[i];
        getInstaller().installComponentFromSrc(
                createArtifact(srcsDir.getURL().toString(), JOSSOScope.AGENT, agentBin.getName().getBaseName()),
                true);
    }
}

From source file:org.josso.tooling.gshell.install.commands.InstallJavaAgentCommand.java

protected void installJOSSOAgentConfig() throws Exception {
    FileObject[] libs = confDir.getChildren();
    for (int i = 0; i < confDir.getChildren().length; i++) {
        FileObject trdPartyFile = libs[i];
        String fileName = trdPartyFile.getName().getBaseName();
        getInstaller().installConfiguration(
                createArtifact(confDir.getURL().toString(), JOSSOScope.AGENT, fileName), isReplaceConfig());
    }/*from w w w .  j a va2  s  .  c o m*/
    getInstaller().updateAgentConfiguration(getIdpHostName(), getIdpPort(), getIdpType());
}

From source file:org.josso.tooling.gshell.install.commands.InstallJavaAgentCommand.java

public void install3rdParty() throws Exception {
    FileObject[] libs = trdpartyDir.getChildren();
    for (int i = 0; i < trdpartyDir.getChildren().length; i++) {
        FileObject trdPartyFile = libs[i];
        String fileName = trdPartyFile.getName().getBaseName();
        getInstaller().install3rdPartyComponent(
                createArtifact(trdpartyDir.getURL().toString(), JOSSOScope.AGENT, fileName), isReplaceConfig());
    }/* w ww . j  a  v  a 2s .c  om*/
}