private void prepare()

in vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java [698:780]


    private void prepare(Node node, boolean descend)
            throws RepositoryException {
        if (log.isDebugEnabled()) {
            log.trace("descending into {} (descend={})", node.getPath(), descend);
        }
        final WorkspaceFilter filter = mgr.getWorkspaceFilter();
        // add "our" properties to the include set
        PropertyIterator pIter = node.getProperties();
        while (pIter.hasNext()) {
            Property p = pIter.nextProperty();
            String path = p.getPath();
            if (aggregator.includes(getNode(), node, p, path) && filter.includesProperty(path)) {
                include(node, p, path);
            }
        }

        // get a node iterator suitable for the current node and the applicable filters
        NodeIterator nIter = getNodeIteratorFor(node, filter);

        // include "our" nodes to the include set and delegate the others to the
        // respective aggregator building sub aggregates
        while (nIter.hasNext()) {
            Node n = nIter.nextNode();
            String path = n.getPath();
            log.trace("checking {}", path);

            PathFilterSet coverSet = filter.getCoveringFilterSet(path);
            boolean isAncestor = filter.isAncestor(path);
            log.trace("coverSet for {} is {}, isAncestor: {}", path, coverSet, isAncestor);

            if (coverSet == null && !isAncestor) {
                continue;
            }

            boolean isIncluded = filter.contains(path);

            // check if another aggregator can handle this node
            Aggregator a = mgr.getAggregator(n, path);
            // - if the aggregator is null
            // - or the aggregator is the same as ours or the default
            // - and if we include the content as well
            // - then don't use the matched aggregator
            if ((a == null)
                    || ((a == aggregator || a.isDefault())
                        && (aggregator.includes(getNode(), n, path)))) {
                // if workspace does not include this node, ignore it
                if (!isIncluded && !isAncestor) {
                    continue;
                }
                include(n, path);
                prepare(n, true);
            } else {
                // otherwise create sub node and collect items if needed
                // but only if the node is either an ancestor or is included
                // or if the workspace filter set contains relative pattern (ACL export case).
                boolean onlyRelativePatterns = coverSet !=null && coverSet.hasOnlyRelativePatterns();
                if (isAncestor || isIncluded || onlyRelativePatterns) {
                    AggregateImpl sub = new AggregateImpl(this, path, a);
                    sub.filterArtifacts = !isIncluded && onlyRelativePatterns;
                    if (leaves == null) {
                        leaves = new LinkedList<AggregateImpl>();
                    }
                    if (descend) {
                        try {
                            sub.collect();
                        } catch (RepositoryException e) {
                            // in some weird cases, the jcr2spi layer reports
                            // wrong nodes. in this case, just remove it again
                            // as leave
                            log.warn("Alleged node is gone: {}", path, e);
                            sub.invalidate();
                            sub = null;
                        }
                    } else {
                        log.trace("adding pending leaf {}", path);
                    }
                    if (sub != null) {
                        leaves.add(sub);
                    }
                }
            }
        }
    }