Example usage for org.apache.commons.vfs NameScope CHILD

List of usage examples for org.apache.commons.vfs NameScope CHILD

Introduction

In this page you can find the example usage for org.apache.commons.vfs NameScope CHILD.

Prototype

NameScope CHILD

To view the source code for org.apache.commons.vfs NameScope CHILD.

Click Source Link

Document

Resolve against the children of the base file.

Usage

From source file:com.pongasoft.kiwidoc.builder.doclet.SourceCodeParser.java

/**
 * Parses the sources using a doclet. It is ok to provide a big number of files, since it will
 * automatically be split in chunks.//from w w  w  .  ja  v  a  2  s. com
 *
 * @param library the library to store the results
 * @param sources the sources
 * @return the number of processed files
 * @throws IOException if there is an issue reading the files
 */
public int parseSources(LibraryModelBuilder library, FileObject sources, String overviewFilename,
        FileObject javadoc, Collection<FileObject> dependencies) throws IOException, InternalException {
    DefaultFileSystemManager dfs = new DefaultFileSystemManager();
    dfs.addProvider("file", new DefaultLocalFileProvider());
    dfs.setReplicator(new DefaultFileReplicator(IOUtils.createTempDirectory("SourceCodeParser", "")));
    dfs.init();
    try {
        File localSources = dfs.getReplicator().replicateFile(sources, SourcesSelector.INSTANCE);

        sources = dfs.toFileObject(localSources);

        FileObject[] allSources = sources.findFiles(JavaSelector.INSTANCE);

        if (allSources == null || allSources.length == 0)
            return 0;

        List<String> sourcePath = new ArrayList<String>();

        for (FileObject sourceFile : allSources) {
            //        if(javadoc != null)
            //        {
            //          String name = sources.getName().getRelativeName(sourceFile.getName());
            //          name = name.substring(0, name.length() - JAVA_EXTENSION.length());
            //          name += HTML_EXTENSION;
            //          if(javadoc.resolveFile(name, NameScope.DESCENDENT).exists())
            //            sourcePath.add(sourceFile.getName().getPath());
            //        }
            //        else
            //        {
            //          sourcePath.add(sourceFile.getName().getPath());
            //        }
            sourcePath.add(sourceFile.getName().getPath());
        }

        List<String> deps = new ArrayList<String>();

        if (dependencies != null) {
            for (FileObject dependency : dependencies) {
                if (dependency.exists()) {
                    File localDependency = dfs.getReplicator().replicateFile(dependency,
                            DependenciesSelector.INSTANCE);
                    deps.add(localDependency.getCanonicalPath());
                }
            }
        }

        FileObject overviewFile = sources.resolveFile(overviewFilename, NameScope.CHILD);

        String overviewPath = null;
        if (overviewFile.exists())
            overviewPath = overviewFile.getName().getPath();

        parseSources(library, overviewPath, sourcePath, deps);

        return sourcePath.size();
    } finally {
        dfs.close();
    }
}

From source file:com.pongasoft.kiwidoc.builder.JSONContentHandler.java

private FileObject getContentFile(FileObject contentFile) throws FileSystemException {
    return contentFile.resolveFile(CONTENT_FILENAME, NameScope.CHILD);
}

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

@Override
protected FileObject[] doListChildrenResolved() throws Exception {
    // if metadata is null, then the path does not exist, as doAttach would have certainly set
    // this./*from ww  w.  jav  a  2  s .c  o m*/
    doAttach();
    if (metadata == null)
        throw new FileNotFolderException(getName());
    ListContainerOptions options = new ListContainerOptions();
    String name = getNameTrimLeadingSlashes();
    if (!name.equals("") && !name.equals("/")) {
        options.inDirectory(name + "/");
        logger.info(String.format(">> list: %s[%s]", getContainer(), name));
    } else {
        logger.info(String.format(">> list: %s", getContainer()));
    }
    Iterable<? extends StorageMetadata> list = lister.execute(getContainer(), options);
    Set<BlobStoreFileObject> children = Sets.newHashSet();
    loop: for (StorageMetadata md : list) {
        if (!md.getName().equals("")) {
            if (name.equals(md.getName()) && md.getType() != StorageType.BLOB) {
                continue loop;
            }
            String childName = Utils.replaceAll(md.getName(), UNDESCRIBED, "");
            BlobStoreFileObject fo = (BlobStoreFileObject) FileObjectUtils
                    .getAbstractFileObject(getFileSystem().resolveFile(getFileSystem().getFileSystemManager()
                            .resolveName(getName(), childName, NameScope.CHILD)));
            children.add(fo);
        }
    }
    logger.info(String.format("<< list: %s", children));
    return children.toArray(new BlobStoreFileObject[] {});
}

From source file:unitTests.dataspaces.AbstractLimitingFileObjectTest.java

@Test
public void testReadOnlyResolveFileStringNameScope() throws FileSystemException {
    createRealFileChild();//from   w  w  w  .j a  v  a 2  s . c  o m

    final FileObject childFile = readOnlyFile.resolveFile(CHILD_NAME, NameScope.CHILD);
    assertNotNull(childFile);
    assertFalse(childFile.isWriteable());
}

From source file:unitTests.dataspaces.AbstractLimitingFileObjectTest.java

@Test
public void testReadWriteResolveFileStringNameScope() throws FileSystemException {
    createRealFileChild();//from w ww  .  ja  v a  2s .co  m

    final FileObject childFile = readWriteFile.resolveFile(CHILD_NAME, NameScope.CHILD);
    assertNotNull(childFile);
    assertTrue(childFile.isWriteable());
}