jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Guggisberg <stefan.guggisb...@gmail.com>
Subject Re: sibling and basic understanding of jsr 170
Date Mon, 13 Dec 2004 17:27:10 GMT
hi markus,
you're right, there's no easy solution for your particular use case,

you could write a short utility method though, something like

Node getSiblingOf(Node n, int index)

that method would 

1. extract the current subscript from the path of n (n.getPath()), 
    e.g. 99
2. compute new subscript (99-1=98)
3. get sibling with
    n.getParent().getNode(n.getName() + "[" + subscript + "]")

not very elegant but more efficient than iterating over all children...

cheers
stefan


On Mon, 13 Dec 2004 18:04:46 +0100, jocsch <jocsch@freaquac.de> wrote:
> Hi,
> 
> sorry for posting a more jcr related question than a jackrabbit one, but I'm
> not in the expert group ;-)
> 
> I have a problem finding a sibling related to a given Node.
> I set up a container node which has an undetermined number of children. The
> order of the children matters. So it looks like:
> 
> RN
>  |
>  tst:container
>     |-...
>     |-tst:child[98]
>     |-tst:child[99]
>     |-....
> 
> Now I have a use case where tst:child[99] is given and I need to show its
> preceding sibling tst:child[98].
> I found no possibility to get this node other than iterating over all children
> (comparing to the given node and remembering the preceding node), because it
> seems that there is no getPosition() or something like that on the Node type.
> 
> I think this solution is far from optimal. Is there a better solution?
> OK, I guess I can implement a kind of a linked list functionality into the
> child node types, but if possible, I want to avoid this.
> I know that there are xpath functions like following-sibling but I read
> somewhere that xpath queries are not yet implemented in jackrabbit.
> 
> Thanks,
>  Markus
>

Mime
View raw message