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

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

Introduction

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

Prototype

public FileObject[] getChildren() throws FileSystemException;

Source Link

Document

Lists the children of this file.

Usage

From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java

public String[] getJobNames(ObjectId id_directory, boolean includeDeleted) throws KettleException {
    try {//from w ww. j a va 2 s. c o m
        List<String> list = new ArrayList<String>();

        RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface directory = tree.findDirectory(id_directory);

        String folderName = calcDirectoryName(directory);
        FileObject folder = KettleVFS.getFileObject(folderName);

        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    String name = child.getName().getBaseName();

                    if (name.endsWith(EXT_JOB)) {

                        String jobName = name.substring(0, name.length() - 4);
                        list.add(jobName);
                    }
                }
            }
        }

        return list.toArray(new String[list.size()]);
    } catch (Exception e) {
        throw new KettleException(
                "Unable to get list of transformations names in folder with id : " + id_directory, e);
    }
}

From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java

private ObjectId[] getRootObjectIDs(String extension) throws KettleException {
    try {//from  w  ww. jav  a 2 s .co m
        // Get all the files in the root directory with a certain extension...
        //
        List<ObjectId> list = new ArrayList<ObjectId>();

        String folderName = repositoryMeta.getBaseDirectory();
        FileObject folder = KettleVFS.getFileObject(folderName);

        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    String name = child.getName().getBaseName();

                    if (name.endsWith(extension)) {
                        list.add(new StringObjectId(name));
                    }
                }
            }
        }

        return list.toArray(new ObjectId[list.size()]);
    } catch (Exception e) {
        throw new KettleException("Unable to get root object ids for extension [" + extension + "]", e);
    }
}

From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java

public String[] getTransformationNames(ObjectId id_directory, boolean includeDeleted) throws KettleException {
    try {//ww w.  j av a 2  s  . c o m
        List<String> list = new ArrayList<String>();

        RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface directory = tree.findDirectory(id_directory);

        String folderName = calcDirectoryName(directory);
        FileObject folder = KettleVFS.getFileObject(folderName);

        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    String name = child.getName().getBaseName();

                    if (name.endsWith(EXT_TRANSFORMATION)) {

                        String transName = name.substring(0, name.length() - 4);
                        list.add(transName);
                    }
                }
            }
        }

        return list.toArray(new String[list.size()]);
    } catch (Exception e) {
        throw new KettleException(
                "Unable to get list of transformations names in folder with id : " + id_directory, e);
    }
}

From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java

public RepositoryDirectoryInterface loadRepositoryDirectoryTree(RepositoryDirectoryInterface dir)
        throws KettleException {
    try {//from w  w  w .  j a v a2 s.co  m
        String folderName = calcDirectoryName(dir);
        FileObject folder = KettleVFS.getFileObject(folderName);

        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FOLDER)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    if (!".meta".equals(child.getName().getBaseName())) {
                        RepositoryDirectory subDir = new RepositoryDirectory(dir,
                                child.getName().getBaseName());
                        subDir.setObjectId(new StringObjectId(calcObjectId(subDir)));
                        dir.addSubdirectory(subDir);

                        loadRepositoryDirectoryTree(subDir);
                    }
                }
            }
        }

        return dir;
    } catch (Exception e) {
        throw new KettleException("Unable to load the directory tree from this file repository", e);
    }
}

From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java

public List<RepositoryElementMetaInterface> getTransformationObjects(ObjectId idDirectory,
        boolean includeDeleted) throws KettleException {

    try {/*from  ww  w  .ja va2 s .c  om*/
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();

        RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface directory = tree.findDirectory(idDirectory);

        String folderName = calcDirectoryName(directory);
        FileObject folder = KettleVFS.getFileObject(folderName);

        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {

                    String name = child.getName().getBaseName();

                    if (name.endsWith(EXT_TRANSFORMATION)) {

                        String transName = name.substring(0, name.length() - 4);

                        ObjectId id = new StringObjectId(
                                calcObjectId(directory, transName, EXT_TRANSFORMATION));
                        Date date = new Date(child.getContent().getLastModifiedTime());
                        list.add(new RepositoryObject(id, transName, directory, "-", date,
                                RepositoryObjectType.TRANSFORMATION, "", false));
                    }
                }
            }
        }

        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get list of transformations in folder with id : " + idDirectory,
                e);
    }
}

From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java

public List<RepositoryElementMetaInterface> getJobObjects(ObjectId id_directory, boolean includeDeleted)
        throws KettleException {

    try {//  ww  w.ja  v a  2  s. com
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();

        RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree();
        RepositoryDirectoryInterface directory = tree.findDirectory(id_directory);

        String folderName = calcDirectoryName(directory);
        FileObject folder = KettleVFS.getFileObject(folderName);

        for (FileObject child : folder.getChildren()) {
            if (child.getType().equals(FileType.FILE)) {
                if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) {
                    String name = child.getName().getBaseName();

                    if (name.endsWith(EXT_JOB)) {

                        String jobName = name.substring(0, name.length() - 4);

                        ObjectId id = new StringObjectId(calcObjectId(directory, jobName, EXT_JOB));
                        Date date = new Date(child.getContent().getLastModifiedTime());
                        list.add(new RepositoryObject(id, jobName, directory, "-", date,
                                RepositoryObjectType.JOB, "", false));
                    }
                }
            }
        }

        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get list of jobs in folder with id : " + id_directory, e);
    }
}

From source file:org.pentaho.hdfs.vfs.test.HDFSVFSTest.java

@Test
public void listChildren() throws Exception {
    assertNotNull("FileSystemManager is null", fsManager);

    FileObject folder = fsManager.resolveFile(buildHDFSURL("/junit/folder"));
    assertNotNull("File is null (could not resolve?)", folder);
    assertEquals(FileType.IMAGINARY, folder.getType());
    folder.createFolder();//from   w  w  w .  ja va 2 s . co m

    folder = fsManager.resolveFile(buildHDFSURL("/junit/folder"));
    assertEquals(FileType.FOLDER, folder.getType());

    FileObject child1 = fsManager.resolveFile(buildHDFSURL("/junit/folder/child1.txt"));
    assertNotNull("File is null (could not resolve?)", child1);
    OutputStream output = child1.getContent().getOutputStream();
    IOUtils.write(HELLO_HADOOP_STR, output);
    IOUtils.closeQuietly(output);
    String fileStr = IOUtils.toString(child1.getContent().getInputStream(), "UTF-8");
    assertEquals(HELLO_HADOOP_STR, fileStr);

    FileObject child2 = fsManager.resolveFile(buildHDFSURL("/junit/folder/child2.txt"));
    assertNotNull("File is null (could not resolve?)", child2);
    output = child2.getContent().getOutputStream();
    IOUtils.write(HELLO_HADOOP_STR, output);
    IOUtils.closeQuietly(output);
    fileStr = IOUtils.toString(child2.getContent().getInputStream(), "UTF-8");
    assertEquals(HELLO_HADOOP_STR, fileStr);

    FileObject[] children = folder.getChildren();
    assertEquals(2, children.length);
    assertEquals("/junit/folder/child1.txt", children[0].getName().getPath());
    assertEquals("/junit/folder/child2.txt", children[1].getName().getPath());

    child1.delete();
    child2.delete();
    folder.delete();
}

From source file:org.pentaho.s3.S3Test.java

private void printFileObject(FileObject fileObject, int depth) throws Exception {
    for (int i = 0; i < depth; i++) {
        System.out.print("    ");
    }//  w ww .  j a v  a 2 s .c o  m
    System.out.println(fileObject.getName().getBaseName());

    if (fileObject.getType() == FileType.FOLDER) {
        FileObject[] children = fileObject.getChildren();
        for (FileObject child : children) {
            printFileObject(child, depth + 1);
        }
    }
}

From source file:org.richfaces.cdk.rd.JarResourceScanner.java

protected void walk(FileObject file) throws IOException {
    FileObject[] children = file.getChildren();
    for (FileObject child : children) {

        if (child.getType() != FileType.FILE) {
            walk(child);/*from   ww  w  .ja va2s  .  c om*/
        } else if (isAcceptable(child)) {
            result.add(child);
        }

    }
}

From source file:org.sonatype.gshell.commands.vfs.FileInfoCommand.java

public Object execute(final CommandContext context) throws Exception {
    assert context != null;
    IO io = context.getIo();//  www . ja  v  a 2s.  c  o m

    FileObject file = resolveFile(context, path);

    io.println("URL: {}", file.getURL());
    io.println("Name: {}", file.getName());
    io.println("BaseName: {}", file.getName().getBaseName());
    io.println("Extension: {}", file.getName().getExtension());
    io.println("Path: {}", file.getName().getPath());
    io.println("Scheme: {}", file.getName().getScheme());
    io.println("URI: {}", file.getName().getURI());
    io.println("Root URI: {}", file.getName().getRootURI());
    io.println("Parent: {}", file.getName().getParent());
    io.println("Type: {}", file.getType());
    io.println("Exists: {}", file.exists());
    io.println("Readable: {}", file.isReadable());
    io.println("Writeable: {}", file.isWriteable());
    io.println("Root path: {}", file.getFileSystem().getRoot().getName().getPath());

    if (file.exists()) {
        FileContent content = file.getContent();
        FileContentInfo contentInfo = content.getContentInfo();
        io.println("Content type: {}", contentInfo.getContentType());
        io.println("Content encoding: {}", contentInfo.getContentEncoding());

        try {
            // noinspection unchecked
            Map<String, Object> attrs = content.getAttributes();
            if (attrs != null && !attrs.isEmpty()) {
                io.println("Attributes:");
                for (Map.Entry<String, Object> entry : attrs.entrySet()) {
                    io.println("    {}='{}'", entry.getKey(), entry.getValue());
                }
            }
        } catch (FileSystemException e) {
            io.println("File attributes are NOT supported");
        }

        try {
            Certificate[] certs = content.getCertificates();
            if (certs != null && certs.length != 0) {
                io.println("Certificate:");
                for (Certificate cert : certs) {
                    io.println("    {}", cert);
                }
            }
        } catch (FileSystemException e) {
            io.println("File certificates are NOT supported");
        }

        if (file.getType().equals(FileType.FILE)) {
            io.println("Size: {} bytes", content.getSize());
        } else if (file.getType().hasChildren() && file.isReadable()) {
            FileObject[] children = file.getChildren();
            io.println("Directory with {} files", children.length);

            for (int iterChildren = 0; iterChildren < children.length; iterChildren++) {
                io.println("#{}:{}", iterChildren, children[iterChildren].getName());
                if (iterChildren > 5) {
                    break;
                }
            }
        }

        io.println("Last modified: {}",
                DateFormat.getInstance().format(new Date(content.getLastModifiedTime())));
    } else {
        io.println("The file does not exist");
    }

    FileObjects.close(file);

    return Result.SUCCESS;
}