You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by jocsch <jo...@freaquac.de> on 2004/12/13 18:04:46 UTC

sibling and basic understanding of jsr 170

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

Re: sibling and basic understanding of jsr 170

Posted by jocsch <jo...@freaquac.de>.
Thanks for the anwser. That's for sure not elegant. 
Hopefully some day I can replace this string manipulation with something 
cleaner ;-)

Greetings,
 Markus


Am Montag, 13. Dezember 2004 18:27 schrieb Stefan Guggisberg:
> 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 <jo...@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

Re: sibling and basic understanding of jsr 170

Posted by Peeter Piegaze <pe...@gmail.com>.
Hi Markus,

Just wanted to point out also that this info hasn't got anything to do
with NodeType, this is on the Node instance. So, as Stefan suggests,
the relevant method is Item.getPath (Item being a supclass of Node).

Cheers,
Peeter


On Mon, 13 Dec 2004 18:27:10 +0100, Stefan Guggisberg
<st...@gmail.com> wrote:
> 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 <jo...@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
> >
>

Re: sibling and basic understanding of jsr 170

Posted by Stefan Guggisberg <st...@gmail.com>.
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 <jo...@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
>