Node.getNodes and Node.hasNodes for a specific nodeType

View: New views
4 Messages — Rating Filter:   Alert me  

Node.getNodes and Node.hasNodes for a specific nodeType

by Matthijs Wensveen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Is it possible to ask a Node whether it has child nodes of a specific
nodeType? Currently I'm able to do this with an XPath query, but it
would be a lot easier, and possibly faster, when I could ask this to the
node directly.
Also, is it possible to mark a child node definition that is also marked
as 'multiple' with 'primary'? If that is the case, maybe I could use
getPrimaryItem.

My node type is defined as:
[eb:ContentTreeItem]
    - eb:friendlyName
    + eb:specialPage = eb:SpecialPage
        multiple
    + * = eb:ContentTreeItem
        multiple

In my application a ContentTreeItem is a leaf node when there are no
eb:ContentTreeItem child nodes.

Thanks in advance,
Matthijs

--
Matthijs Wensveen
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500


Re: Node.getNodes and Node.hasNodes for a specific nodeType

by Alexander Klimetschek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jul 8, 2008 at 2:49 PM, Matthijs Wensveen <m.wensveen@...> wrote:
> Is it possible to ask a Node whether it has child nodes of a specific
> nodeType? Currently I'm able to do this with an XPath query, but it would be
> a lot easier, and possibly faster, when I could ask this to the node
> directly.

No, this is not possible, but you can easily filter the nodes in the
iterator returned by Node.getNodes(). This would not be a performance
difference if it would be implemented directly in JCR.

> Also, is it possible to mark a child node definition that is also marked as
> 'multiple' with 'primary'? If that is the case, maybe I could use
> getPrimaryItem.

Node.getPrimaryItem() simple does a getProperty() or getNode() (if
property exists, it is preferred) with the exact name defined in the
primaryItem setting of the node type. So if you have same name
siblings, you can only get one of them (eg. "mychildnode" or
"mychildnode[2]").

Regards,
Alex

--
Alexander Klimetschek
alexander.klimetschek@...

Re: Node.getNodes and Node.hasNodes for a specific nodeType

by Tobias Bocanegra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 7/8/08, Matthijs Wensveen <m.wensveen@...> wrote:
> Hi,
>
>  Is it possible to ask a Node whether it has child nodes of a specific
> nodeType? Currently I'm able to do this with an XPath query, but it would be
> a lot easier, and possibly faster, when I could ask this to the node
> directly.
yes, you can pass a filter for the Node.getNodes() call where you can
for example test the node.isNodeType().

>  Also, is it possible to mark a child node definition that is also marked as
> 'multiple' with 'primary'? If that is the case, maybe I could use
> getPrimaryItem.
>
>  My node type is defined as:
>  [eb:ContentTreeItem]
>    - eb:friendlyName
>    + eb:specialPage = eb:SpecialPage
>        multiple
>    + * = eb:ContentTreeItem
>        multiple
no, a primary item can't be a SNS node def. Do you really need SNS for
your content tree items? SNS usually cause more problems than distinct
node names. especially in a tree, i would name the nodes according to
the name of the tree node.

>  In my application a ContentTreeItem is a leaf node when there are no
> eb:ContentTreeItem child nodes.

regards, toby

Re: Node.getNodes and Node.hasNodes for a specific nodeType

by Matthijs Wensveen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tobias Bocanegra wrote:

> On 7/8/08, Matthijs Wensveen <m.wensveen@...> wrote:
>  
>> Hi,
>>
>>  Is it possible to ask a Node whether it has child nodes of a specific
>> nodeType? Currently I'm able to do this with an XPath query, but it would be
>> a lot easier, and possibly faster, when I could ask this to the node
>> directly.
>>    
> yes, you can pass a filter for the Node.getNodes() call where you can
> for example test the node.isNodeType().
>
>  
>>  Also, is it possible to mark a child node definition that is also marked as
>> 'multiple' with 'primary'? If that is the case, maybe I could use
>> getPrimaryItem.
>>
>>  My node type is defined as:
>>  [eb:ContentTreeItem]
>>    - eb:friendlyName
>>    + eb:specialPage = eb:SpecialPage
>>        multiple
>>    + * = eb:ContentTreeItem
>>        multiple
>>    
> no, a primary item can't be a SNS node def. Do you really need SNS for
> your content tree items? SNS usually cause more problems than distinct
> node names. especially in a tree, i would name the nodes according to
> the name of the tree node.
>  

Ah, sorry, the the definition is incorrect, the '*' item does not have
multiple on it. But I think the same answer applies to wildcard
children? The problem is that I don't know the name in advance, so I
can't test for a specific child. The node.isNodeType suggestion is a
good one though. I'll implement that.

Thanks (also Alexander),
Matthijs

--
Matthijs Wensveen
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500

LightInTheBox - Buy quality products at wholesale price