Hey,

When I get to write a generic one that others can be used, I 'll submit to
jira.

I'm not sure how useful this is though.. almost verbatim tree traversal:
http://en.wikipedia.org/wiki/Tree_traversal#Iterative_Traversal

And of course, if there are many immediate children, memory might blow up
(Queue will get large)..

Probably proper way would be to spawn a thread and implement proper
producer/consumer..



On Thu, Jun 16, 2011 at 12:28 PM, Justin Edelson
<jus...@justinedelson.com>wrote:

> Sam-
> Care you supply a patch to include this?
>
> On Thu, Jun 16, 2011 at 7:35 AM, sam lee <skyn...@gmail.com> wrote:
> > I ended up walking resource myself:
> >
> >    private void visit(Resource resource) {
> >          //actually do something.. like, adding to sitemap.
> >    }
> >
> >
> >    public void walkBreathFirst(Resource resource) {
> >        final Queue<Resource> toVisit = new
> > ConcurrentLinkedQueue<Resource>();
> >        try {
> >            toVisit.add(resource);
> >            while (!toVisit.isEmpty()) {
> >                final Resource visitedResource = toVisit.remove();
> >                visit(visitedResource);
> >
> >                final Iterator<Resource> iter =
> > visitedResource.listChildren();
> >                while (iter.hasNext()) {
> >                    toVisit.add(iter.next());
> >                }
> >            }
> >        } catch (SitemapException e) {
> >
> >        }
> >    }
> >
> > On Thu, Jun 16, 2011 at 9:47 AM, sam lee <skyn...@gmail.com> wrote:
> >
> >> Hey,
> >>
> >> I need to walk a large resource tree (for sitemap generation, for
> example).
> >>
> >> I'm aware of javax.jcr.ItemVisitor .. But I want to visit Resources
> >> instead, not Nodes.
> >> I could use ItemVisitor and elevate Nodes to Resources using
> >> ResourceResolver:
> >>
> >>     @Override
> >>     public void visit(Node node) throws RepositoryException {
> >>         resolver.getResource(node.getPath());
> >>     }
> >>
> >>
> >> Is there a better way?   I want to implement   void visit(Resource
> >> resource);  if possible.
> >>
> >> If I were to write my own ResourceVisitor, I would use recursion. But is
> >> recursion safe for a large tree?
> >> Looking at source code of javax.jcr.util.TraversingItemVisitor,  it uses
> >> simple recursion too (with a queue for breathfirst traversal).
> >>
> >> What is a recommended way of walking a large resource tree?
> >>
> >>
> >>
> >
>

Reply via email to