Example usage for org.apache.commons.vfs FileType FOLDER

List of usage examples for org.apache.commons.vfs FileType FOLDER

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileType FOLDER.

Prototype

FileType FOLDER

To view the source code for org.apache.commons.vfs FileType FOLDER.

Click Source Link

Document

A folder.

Usage

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

public ExtendedNodeType getExtendedPrimaryNodeType() throws RepositoryException {
    try {/*  w w w.j  a va  2  s .com*/
        FileType fileType = fileObject.getType();
        if (fileType == FileType.FILE) {
            return NodeTypeRegistry.getInstance().getNodeType(Constants.JAHIANT_FILE);
        } else if (fileType == FileType.FOLDER) {
            return NodeTypeRegistry.getInstance().getNodeType(Constants.JAHIANT_FOLDER);
        }
    } catch (FileSystemException e) {
        throw new RepositoryException(e);
    }
    return NodeTypeRegistry.getInstance().getNodeType(Constants.JAHIANT_FILE);
}

From source file:org.jboss.dashboard.ui.formatters.FileNavigationTreeFormatter.java

protected void renderDirectory(FileObject currentDir) throws FileSystemException {
    String dirName = currentDir.getName().getBaseName();
    setAttribute("dirName", StringUtils.defaultIfEmpty(dirName, "/"));
    setAttribute("path", currentDir.getName().getPath());
    FileObject[] children = currentDir.getChildren();
    List childDirectories = new ArrayList();
    boolean hasChildDirectories = false;
    if (children != null)
        for (int i = 0; i < children.length; i++) {
            FileObject child = children[i];
            if (child.getType().equals(FileType.FOLDER) && !child.isHidden() && child.isReadable()) {
                hasChildDirectories = true;
                childDirectories.add(child);
            }/*from  w ww.  java  2 s . c o m*/
        }
    setAttribute("hasChildrenDirectories", hasChildDirectories);
    String directoryPath = currentDir.getName().getPath();
    boolean isOpen = getFileNavigationHandler().getOpenPaths().contains(directoryPath);
    setAttribute("isOpen", isOpen);
    setAttribute("isCurrent", getFileNavigationHandler().getCurrentPath().equals(directoryPath));
    renderFragment("outputDirectory");
    if (childDirectories.size() > 0) {
        sortDirectories(childDirectories);
        if (isOpen) {
            renderFragment("beforeChildren");
            for (int i = 0; i < childDirectories.size(); i++) {
                FileObject child = (FileObject) childDirectories.get(i);
                renderDirectory(child);
            }
            renderFragment("afterChildren");
        }
    }
}

From source file:org.jclouds.vfs.provider.blobstore.BlobStoreFileObject.java

@Override
protected FileType doGetType() throws Exception {
    if (metadata == null)
        return FileType.IMAGINARY;
    if (getNameTrimLeadingSlashes().equals("") || getName().getParent() == null)
        return FileType.FOLDER;
    return (metadata.getType() == StorageType.BLOB) ? FileType.FILE : FileType.FOLDER;
}

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

/**
 * Does a 'cp' command.//from  w  ww  .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.//from w ww  .j  a  v a  2s  . com
 */
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 ava2  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

private void ls(FileSystemManager mg, FileObject wd, final String[] cmd) throws FileSystemException {
    int pos = 1;//from  w ww.jav  a2s .  co  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  w  w  . ja  va2s .c o m
            getInstaller().installComponent(createArtifact(subfile.getParent().getURL().toString(),
                    JOSSOScope.AGENT, subfile.getName().getBaseName()), true);
        }
    }
}

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

public void installApplication(JOSSOArtifact artifact, boolean replace) throws InstallException {
    try {//from w w w.j av  a  2s. c o m
        // If the war is already expanded, copy it with a new name.
        FileObject srcFile = getFileSystemManager().resolveFile(artifact.getLocation());

        // Is this the josso gateaway ?
        String name = artifact.getBaseName();
        boolean isFolder = srcFile.getType().equals(FileType.FOLDER);

        if (artifact.getType().equals("war") && name.startsWith("josso-gateway-web")) {
            // INSTALL GWY
            String newName = "josso.war";

            // Do we have to explode the war ?
            if (getTargetPlatform().isJOSSOWarExploded() && !isFolder) {
                installJar(srcFile, this.targetDeployDir, newName, true, replace);

                if (getTargetPlatform().getVersion().startsWith("6")) {
                    // Under JBoss 6 remove commons logging JAR files which conflict with slf4j replacement
                    FileObject webInfLibFolder = targetDeployDir.resolveFile(newName + "/WEB-INF/lib");

                    boolean exists = webInfLibFolder.exists();

                    if (exists) {
                        FileObject[] sharedLibs = webInfLibFolder.getChildren();
                        for (int i = 0; i < sharedLibs.length; i++) {
                            FileObject jarFile = sharedLibs[i];

                            if (!jarFile.getType().getName().equals(FileType.FILE.getName())) {
                                // ignore folders
                                continue;
                            }
                            if (jarFile.getName().getBaseName().startsWith("commons-logging")
                                    && jarFile.getName().getBaseName().endsWith(".jar")) {
                                jarFile.delete();
                            }
                        }
                    }
                }
            } else {
                installFile(srcFile, this.targetDeployDir, replace);
            }
            return;
        }

        if ((getTargetPlatform().getVersion().startsWith("5")
                || getTargetPlatform().getVersion().startsWith("6")) && artifact.getType().equals("ear")
                && artifact.getBaseName().startsWith("josso-partner-jboss5")) {
            installFile(srcFile, this.targetDeployDir, replace);
            return;
        } else if (!(getTargetPlatform().getVersion().startsWith("5")
                || getTargetPlatform().getVersion().startsWith("6")) && artifact.getType().equals("ear")
                && artifact.getBaseName().startsWith("josso-partner-jboss-app")) {
            installFile(srcFile, this.targetDeployDir, replace);
            return;
        }

        log.debug("Skipping partner application : " + srcFile.getName().getFriendlyURI());

    } catch (IOException e) {
        throw new InstallException(e.getMessage(), e);
    }
}

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

@Override
public void validatePlatform() throws InstallException {
    boolean valid = true;

    try {// w ww  . ja  va 2s  . c  om

        if (!targetDir.exists() || !targetDir.getType().getName().equals(FileType.FOLDER.getName())) {
            getPrinter().printErrStatus("Target",
                    "folder does not exist or is not a directory:" + targetDir.getName().getFriendlyURI());
            valid = false;
        }
        if (!valid)
            throw new InstallException("Invalid Target Platform");

        getPrinter().printOkStatus(getTargetPlatform().getDescription(), "Directory Layout");

    } catch (FileSystemException e) {
        log.error(e.getMessage(), e);
        throw new InstallException("Invalid Target Platform");
    }

}