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

The following are Jave code examples for showing how to use getFolders() of the org.openide.filesystems.FileObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: ApisupportAntUtils.java   View Source Code Vote up 6 votes
/**
 * 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 2
Project: incubator-netbeans   File: FolderObjTest.java   View Source Code Vote up 6 votes
/**
 * 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 3
Project: incubator-netbeans   File: FolderObjTest.java   View Source Code Vote up 6 votes
/**
 * 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 4
Project: incubator-netbeans   File: SaasServicesModel.java   View Source Code Vote up 6 votes
private void loadFromDefaultFileSystem() {
    FileObject f = FileUtil.getConfigFile("SaaSServices"); // NOI18N

    if (f != null && f.isFolder()) {
        Enumeration<? extends FileObject> en = f.getFolders(false);
        while (en.hasMoreElements()) {
            FileObject groupFolder = en.nextElement();
            for (FileObject fo : groupFolder.getChildren()) {
                if (fo.isFolder()) {
                    continue;
                }
                if (PROFILE_PROPERTIES_FILE.equals(fo.getNameExt())) {
                    continue;
                }
                loadSaasServiceFile(fo, false);
            }
            SaasGroup g = rootGroup.getChildGroup(groupFolder.getName());
            if (g != null) {
                g.setIcon16Path((String) groupFolder.getAttribute("icon16"));
                g.setIcon32Path((String) groupFolder.getAttribute("icon32"));
            }
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: Worker.java   View Source Code Vote up 6 votes
@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 6
Project: incubator-netbeans   File: DirectoryGroup.java   View Source Code Vote up 5 votes
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 7
Project: incubator-netbeans   File: FileUtilities.java   View Source Code Vote up 5 votes
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
Project: Pogamut3   File: ExampleBotProjectWizardIterator.java   View Source Code Vote up 5 votes
public Set/*<FileObject>*/ instantiateNEW(/*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);
    substituteFiles(dirF);
    // 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
Project: Pogamut3   File: ExampleBotProjectWizardIterator.java   View Source Code Vote up 5 votes
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);
    substituteFiles(dirF);
    // 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
Project: nb-clojure   File: ClojureTemplateWizardIterator.java   View Source Code Vote up 5 votes
@Override
public Set/*<FileObject>*/ instantiate(/*ProgressHandle handle*/) throws IOException {
    Set<FileObject> resultSet = new LinkedHashSet<>();
    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
Project: incubator-netbeans   File: NbReaderProviderFactory.java   View Source Code Vote up 4 votes
private void processSubfolders(FileObject dtdFolder) {
    for (Enumeration en = dtdFolder.getFolders(false); en.hasMoreElements();) {
        FileObject folder = (FileObject) en.nextElement();
        addFolder(folder);
    }
}