private boolean addTypes(final ExplorerNode parent,
                             final UnmodifiableTreeModel treeModel,
                             final Set<String> types,
                             final Set<DocumentPermission> requiredPermissions) {
        boolean added = false;

        final List<ExplorerNode> children = treeModel.getChildren(parent);
        if (children != null) {
            for (final ExplorerNode child : children) {
                // Recurse right down to find out if a descendant is being added and therefore if we need to
                // include this type as it is an ancestor.
                // Even if you have no permission on a folder, you can see descendants of it if you have permission
                // on them, hence we have to recurse all the way.
                final boolean hasChildren = addTypes(child, treeModel, types, requiredPermissions);
                final String type = child.getType();
                if (hasChildren) {
                    // We added one or more descendants of child, so add child's type
                    types.add(type);
                    added = true;
                } else if (!types.contains(type)
                           && NodeInclusionChecker.hasPermission(securityContext, child, requiredPermissions)) {
                    types.add(type);
                    added = true;
                }
            }
        }

        return added;
    }
Create a map of folders and their child items.
stroom-explorer/stroom-explorer-impl/src/main/java/stroom/explorer/impl/ExplorerServiceImpl.java