Java Code Examples for org.openide.filesystems.FileObject#getFolders()

The following examples show how to use org.openide.filesystems.FileObject#getFolders() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   File: FolderObjTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test of getInputStream method, of class org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj.
 */
public void testGetInputStream() {
    File f = testFile;
    FileSystem fs = FileBasedFileSystem.getInstance();
    
    FileObject root = fs.getRoot();
    assertNotNull(root);
    
    Enumeration<? extends FileObject> en = root.getFolders(true);
    for (int i = 0; i < 10 && en.hasMoreElements(); i++) {
        FileObject fo = (FileObject) en.nextElement();
        assertTrue(fo.isFolder());
        assertFalse(fo.isData());
        try {
            fo.getInputStream();
            fail ();
        } catch (FileNotFoundException e) {
            
        }

    }
}
 
Example 2
Source Project: netbeans   File: FolderObjTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test of getOutputStream method, of class org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj.
 */
public void testGetOutputStream() {
    File f = testFile;
    FileSystem fs = FileBasedFileSystem.getInstance();
    
    FileObject root = fs.getRoot();
    assertNotNull(root);
    
    Enumeration<? extends FileObject> en = root.getFolders(true);
    for (int i = 0; i < 10 && en.hasMoreElements(); i++) {
        FileObject fo = (FileObject) en.nextElement();
        assertTrue(fo.isFolder());
        assertFalse(fo.isData());
        try {
            fo.getOutputStream(fo.lock());
            fail ();
        } catch (IOException e) {
            
        } finally {
            
        }

    }
}
 
Example 3
private void findFilesWithEndPath(String[] endPath, FileObject folder, Collection<FileObject> collected) {
    FileObject root = folder;
    boolean wasFound = true;
    for (int i = 0; i < endPath.length; i++) {
        root = root.getFileObject(endPath[i]);
        if (root == null) {
            wasFound = false;
            break;
        }
    }
    if (wasFound) {
        collected.add(root);
    }
    Enumeration<? extends FileObject> folders = folder.getFolders(false);
    while (folders.hasMoreElements()) {
        FileObject subFolder = folders.nextElement();
        findFilesWithEndPath(endPath, subFolder, collected);
    }
}
 
Example 4
Source Project: netbeans   File: NodeJsDataProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @return collection of local modules, that are obtained from the first node_modules folder
 */
public Collection<FileObject> getLocalModules(FileObject forFile) {
    HashSet<FileObject> modules = new HashSet<FileObject>();
    Project project = FileOwnerQuery.getOwner(forFile);
    FileObject nodeModulesFolder = null;
    FileObject parent = forFile.getParent();
    if (project != null) {
        FileObject projectDirectory = project.getProjectDirectory();
        String pathToProject = projectDirectory.getPath();
        while (parent.getPath().startsWith(pathToProject) && nodeModulesFolder == null) {
            nodeModulesFolder = parent.getFileObject(NodeJsUtils.NODE_MODULES_NAME);
            parent = parent.getParent();
        }
    }
    if (nodeModulesFolder != null) {
        Enumeration<? extends FileObject> moduleFolders = nodeModulesFolder.getFolders(false);
        while (moduleFolders.hasMoreElements()) {
            FileObject moduleFolder = moduleFolders.nextElement();
            if (moduleFolder.getFileObject(NodeJsUtils.PACKAGE_NAME, NodeJsUtils.JSON_EXT) != null) {
                modules.add(moduleFolder);
            }
        }
    }
    return modules;
}
 
Example 5
Source Project: netbeans   File: ApisupportAntUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Scan recursively through all folders in the given <code>dir</code> and
 * add every directory/package, which contains at least one file with the
 * given extension (probably class or java), into the given
 * <code>validPkgs</code> set. Added entries are in the form of regular java
 * package (x.y.z)
 */
private static void scanForPackages(final Set<FileObject> validPkgs, final FileObject dir, final String ext) {
    if (dir == null) {
        return;
    }
    for (Enumeration en1 = dir.getFolders(false); en1.hasMoreElements(); ) {
        FileObject subDir = (FileObject) en1.nextElement();
        if (VisibilityQuery.getDefault().isVisible(subDir)) {
            scanForPackages(validPkgs, subDir, ext);
        }
    }
    for (Enumeration en2 = dir.getData(false); en2.hasMoreElements(); ) {
        FileObject kid = (FileObject) en2.nextElement();
        if (kid.hasExt(ext) && Utilities.isJavaIdentifier(kid.getName())) {
            // at least one class inside directory -> valid package
            validPkgs.add(dir);
            break;
        }
    }
}
 
Example 6
Source Project: netbeans   File: Worker.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
private Collection<FileObject> searchSources(
        @NonNull final FileObject root,
        @NonNull final Collection<FileObject> result,
        @NonNull final Request  request,
        @NonNull final List<SearchFilter> filters) {
    if (isCancelled() ||
        root.getChildren().length == 0 ||
        request.isExcluded(root) ||
        !checkAgainstFilters(root, filters)) {
        return result;
    } else {
            result.add(root);
            final Enumeration<? extends FileObject> subFolders = root.getFolders(false);
            while (subFolders.hasMoreElements()) {
                searchSources(subFolders.nextElement(), result, request, filters);
            }
    }
    return result;
}
 
Example 7
Source Project: netbeans   File: FileUtilities.java    License: Apache License 2.0 5 votes vote down vote up
private static void processFolder(FileObject file, NameObtainer nameObtainer, SortedSet<String> result, boolean onlyRoots) {
    Enumeration<? extends FileObject> dataFiles = file.getData(false);
    Enumeration<? extends FileObject> folders = file.getFolders(false);

    if (dataFiles.hasMoreElements()) {
        while (dataFiles.hasMoreElements()) {
            FileObject kid = dataFiles.nextElement();
            if ((kid.hasExt("java") || kid.hasExt("class")) && Utilities.isJavaIdentifier(kid.getName())) {
                // at least one java or class inside directory -> valid package
                String packageName = nameObtainer.getPackageName(file);
                if (packageName == null) {
                    continue;
                }
                result.add(packageName);
                if (onlyRoots) {
                    // don't recurse into subfolders
                    return;
                } else {
                    // recurse inot subfolders
                    break;
                }
            }
        }
    }

    while (folders.hasMoreElements()) {
        processFolder(folders.nextElement(), nameObtainer, result, onlyRoots);
    }
}
 
Example 8
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 9
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 10
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 11
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 12
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 13
public static void loadPartnerServices() {
    FileObject f = FileUtil.getConfigFile("RestComponents"); // NOI18N

    if (f != null && f.isFolder()) {
        Enumeration<? extends FileObject> en = f.getFolders(false);
        while (en.hasMoreElements()) {
            FileObject nextFolder = en.nextElement();
            String groupName = ManagerUtil.getLocalizedName(nextFolder);
            loadPartnerFromFolder(nextFolder, groupName, false);
        }
    }
}
 
Example 14
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 15
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 16
Source Project: netbeans   File: DirectoryGroup.java    License: Apache License 2.0 5 votes vote down vote up
private void processFolderChildren(FileObject fo, Set<Project> projects, ProgressHandle h, Counter counter, boolean checkShare) throws IllegalArgumentException {
    Enumeration<? extends FileObject> e = fo.getFolders(false);
    while (e.hasMoreElements()) {
        try {
            FileObject em = e.nextElement();
            SharabilityQuery.Sharability share = SharabilityQuery.Sharability.UNKNOWN;
            if (checkShare) {
                share = SharabilityQuery.getSharability(fo);
                if (share == SharabilityQuery.Sharability.NOT_SHARABLE) {
                    continue;
                }
            }
            Project p = ProjectManager.getDefault().findProject(em);
            if (p != null && !ProjectConvertors.isConvertorProject(p)) {
                projects.add(p);
                if (h != null) {
                    h.progress(progressMessage(p), Math.min(++counter.start, counter.end));
                }
            }
            checkShare = share != SharabilityQuery.Sharability.SHARABLE;
            // don't need to check the sharability if the current folder is marked as recursively sharable
            
            processFolderChildren(em, projects, h, counter, checkShare);
        } catch (IOException x) {
            Exceptions.printStackTrace(x);
        }
    }
}
 
Example 17
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 18
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 19
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirF = FileUtil.normalizeFile((File) wiz.getProperty("projdir"));
    dirF.mkdirs();

    FileObject template = Templates.getTemplate(wiz);
    FileObject dir = FileUtil.toFileObject(dirF);
    unZipFile(template.getInputStream(), dir);

    // Always open top dir as a project:
    resultSet.add(dir);
    // Look for nested projects to open as well:
    Enumeration<? extends FileObject> e = dir.getFolders(true);
    while (e.hasMoreElements()) {
        FileObject subfolder = e.nextElement();
        if (ProjectManager.getDefault().isProject(subfolder)) {
            resultSet.add(subfolder);
        }
    }

    File parent = dirF.getParentFile();
    if (parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }

    return resultSet;
}
 
Example 20
private void processSubfolders(FileObject dtdFolder) {
    for (Enumeration en = dtdFolder.getFolders(false); en.hasMoreElements();) {
        FileObject folder = (FileObject) en.nextElement();
        addFolder(folder);
    }
}