Detecting a virtual node

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Detecting a virtual node

marnixkok
Hi,

I'm not sure if this is the correct place to ask, but since there's so much knowledge regarding the jackrabbit layer contained within the users of this forum I'm going to try anyway.  

For a tool I'm writing, using the JCR core libraries, I need to be able to identify if a node is a "virtual" node or not. From tiny pieces of information I have been led to believe that these are called shared nodes. However, when I try to retrieve them using the API call it reports that it has not yet been implemented.

Is there a clean way to get these nodes? Maybe I'm just missing something very obvious.

Currently my implementation is able to detect them, but it's a really silly piece of code that's probably not very performant -- it exports a node (without recursion), if it's a virtual node there is no node output otherwise it's a normal node.

I understand it's a little bit off-topic, but any help would be very much appreciated.

With kind regards,

Marnix Kok
Reply | Threaded
Open this post in threaded view
|

Re: Detecting a virtual node

Jeroen Reijn
Administrator
Hi Marnix,



On Thu, Aug 11, 2011 at 10:17 AM, marnixkok <[hidden email]> wrote:
> Hi,
>
> I'm not sure if this is the correct place to ask, but since there's so much
> knowledge regarding the jackrabbit layer contained within the users of this
> forum I'm going to try anyway.

Sure there should be plenty of people here with solid knowledge.

>
> For a tool I'm writing, using the JCR core libraries, I need to be able to
> identify if a node is a "virtual" node or not. From tiny pieces of
> information I have been led to believe that these are called shared nodes.
> However, when I try to retrieve them using the API call it reports that it
> has not yet been implemented.

I'm a bit confused with what you mean with JCR code libraries. Are you
writing a tool against hippo repository or just plain jackrabbit?
It's also very important for us to know against which version of
Hippo/Jackkrabbit you are trying this.

>
> Is there a clean way to get these nodes? Maybe I'm just missing something
> very obvious.

If you doing this with Hippo you might want to take a look at the
class org.hippoecm.frontend.widgets.JcrTree . It has method isVirtual
which checks exactly what you want.

>
> Currently my implementation is able to detect them, but it's a really silly
> piece of code that's probably not very performant -- it exports a node
> (without recursion), if it's a virtual node there is no node output
> otherwise it's a normal node.

Ah yes that does not sounds like the way to go :-)

>
> I understand it's a little bit off-topic, but any help would be very much
> appreciated.

Don't worry feel free to ask.

>
> With kind regards,
>
> Marnix Kok
>
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/Detecting-a-virtual-node-tp6675474p6675474.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html
>



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Detecting a virtual node

b.vanderschans@onehippo.com
In reply to this post by marnixkok
Hi Marnix,

Have a look at the method isVirtual() in:

https://forge.onehippo.org/svn/jcr-runner/trunk/src/main/java/org/onehippo/forge/jcrrunner/JcrHelper.java

I'm not sure if there is a "clean" way to check for virtual nodes
without casting to a HippoNode.

Regards,
Bart



On Thu, Aug 11, 2011 at 10:17 AM, marnixkok <[hidden email]> wrote:

> Hi,
>
> I'm not sure if this is the correct place to ask, but since there's so much
> knowledge regarding the jackrabbit layer contained within the users of this
> forum I'm going to try anyway.
>
> For a tool I'm writing, using the JCR core libraries, I need to be able to
> identify if a node is a "virtual" node or not. From tiny pieces of
> information I have been led to believe that these are called shared nodes.
> However, when I try to retrieve them using the API call it reports that it
> has not yet been implemented.
>
> Is there a clean way to get these nodes? Maybe I'm just missing something
> very obvious.
>
> Currently my implementation is able to detect them, but it's a really silly
> piece of code that's probably not very performant -- it exports a node
> (without recursion), if it's a virtual node there is no node output
> otherwise it's a normal node.
>
> I understand it's a little bit off-topic, but any help would be very much
> appreciated.
>
> With kind regards,
>
> Marnix Kok
>
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/Detecting-a-virtual-node-tp6675474p6675474.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html
>



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Detecting a virtual node

marnixkok
Hello,

I'd like to thank you both for your swift responses!

The code really helped. It's quite an expensive check isn't it?

This allows me to move on with the rest of code.

Thanks again!

Cheers,

Marnix

On Thu, Aug 11, 2011 at 10:37 AM, Bart van der Schans <[hidden email]> wrote:
Hi Marnix,

Have a look at the method isVirtual() in:

https://forge.onehippo.org/svn/jcr-runner/trunk/src/main/java/org/onehippo/forge/jcrrunner/JcrHelper.java

I'm not sure if there is a "clean" way to check for virtual nodes
without casting to a HippoNode.

Regards,
Bart



On Thu, Aug 11, 2011 at 10:17 AM, marnixkok <[hidden email]> wrote:
> Hi,
>
> I'm not sure if this is the correct place to ask, but since there's so much
> knowledge regarding the jackrabbit layer contained within the users of this
> forum I'm going to try anyway.
>
> For a tool I'm writing, using the JCR core libraries, I need to be able to
> identify if a node is a "virtual" node or not. From tiny pieces of
> information I have been led to believe that these are called shared nodes.
> However, when I try to retrieve them using the API call it reports that it
> has not yet been implemented.
>
> Is there a clean way to get these nodes? Maybe I'm just missing something
> very obvious.
>
> Currently my implementation is able to detect them, but it's a really silly
> piece of code that's probably not very performant -- it exports a node
> (without recursion), if it's a virtual node there is no node output
> otherwise it's a normal node.
>
> I understand it's a little bit off-topic, but any help would be very much
> appreciated.
>
> With kind regards,
>
> Marnix Kok
>
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/Detecting-a-virtual-node-tp6675474p6675474.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html
>



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US <a href="tel:%2B1%20877%20414%204776" value="+18774144776">+1 877 414 4776 (toll free)
Europe <a href="tel:%2B31%280%2920%20522%204466" value="+31205224466">+31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Detecting a virtual node

Berry van Halderen
In reply to this post by b.vanderschans@onehippo.com


On Thu, Aug 11, 2011 at 10:37 AM, Bart van der Schans <[hidden email]> wrote:
Hi Marnix,

Have a look at the method isVirtual() in:

https://forge.onehippo.org/svn/jcr-runner/trunk/src/main/java/org/onehippo/forge/jcrrunner/JcrHelper.java

I'm not sure if there is a "clean" way to check for virtual nodes
without casting to a HippoNode.


No, you need a cast to HippoNode.  The code in that method is a but verbose, because the ("if cannonical == null") is unnecessary if you reverse the check.
So instead
        HippoNode hippoNode = (HippoNode) jcrNode;
 Node canonical = hippoNode.getCanonicalNode(); if (canonical == null) { return true; } return !hippoNode.getCanonicalNode().isSame(hippoNode);
You can write the check as:
  boolean isVirtual = (node instanceof HippoNode ? !node.isSame(((HippoNode)node).getCanonicalNode()) : false);

Btw, catching the RepositoryException is not a good idea in general, it indicates a generic, often connection-related, problem with the repository, where continuing to operate is often not the way to continue, but handling the exception (such as a repository that has shut down) at a high level is cleared.  This is for generic RepositoryExceptions, not specific instances of it (such as PathNotFoundException, but this is not the case here).
 
\Berry

Regards,
Bart



On Thu, Aug 11, 2011 at 10:17 AM, marnixkok <[hidden email]> wrote:
> Hi,
>
> I'm not sure if this is the correct place to ask, but since there's so much
> knowledge regarding the jackrabbit layer contained within the users of this
> forum I'm going to try anyway.
>
> For a tool I'm writing, using the JCR core libraries, I need to be able to
> identify if a node is a "virtual" node or not. From tiny pieces of
> information I have been led to believe that these are called shared nodes.
> However, when I try to retrieve them using the API call it reports that it
> has not yet been implemented.
>
> Is there a clean way to get these nodes? Maybe I'm just missing something
> very obvious.
>
> Currently my implementation is able to detect them, but it's a really silly
> piece of code that's probably not very performant -- it exports a node
> (without recursion), if it's a virtual node there is no node output
> otherwise it's a normal node.
>
> I understand it's a little bit off-topic, but any help would be very much
> appreciated.
>
> With kind regards,
>
> Marnix Kok
>
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/Detecting-a-virtual-node-tp6675474p6675474.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html
>



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US <a href="tel:%2B1%20877%20414%204776" value="+18774144776">+1 877 414 4776 (toll free)
Europe <a href="tel:%2B31%280%2920%20522%204466" value="+31205224466">+31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Ard
Reply | Threaded
Open this post in threaded view
|

Re: Detecting a virtual node

Ard
On Thu, Aug 11, 2011 at 11:08 AM, Berry van Halderen
<[hidden email]> wrote:

>
>
> On Thu, Aug 11, 2011 at 10:37 AM, Bart van der Schans
> <[hidden email]> wrote:
>>
>> Hi Marnix,
>>
>> Have a look at the method isVirtual() in:
>>
>>
>> https://forge.onehippo.org/svn/jcr-runner/trunk/src/main/java/org/onehippo/forge/jcrrunner/JcrHelper.java
>>
>> I'm not sure if there is a "clean" way to check for virtual nodes
>> without casting to a HippoNode.
>>
>
> No, you need a cast to HippoNode.  The code in that method is a but verbose,
> because the ("if cannonical == null") is unnecessary if you reverse the
> check.
> So instead
>
>         HippoNode hippoNode = (HippoNode) jcrNode;
>
>         Node canonical = hippoNode.getCanonicalNode();
>             if (canonical == null) {
>                 return true;
>             }
>             return !hippoNode.getCanonicalNode().isSame(hippoNode);
>
> You can write the check as:
>   boolean isVirtual = (node instanceof HippoNode ?
> !node.isSame(((HippoNode)node).getCanonicalNode()) : false);

off topic : Stick to the verbose one I'd suggest....I so much dislike
this cramming of code into one unreadable line, but that might just be
because I have a very bad decompiler in my head. On a serious note: If
you are really good at reading these kind of code lines, just don't
use them to be friendly to other less gifted programmers like me.
Also, they are very error prone: The spec says nothing what happens
for node.isSame(null). Imo the spec should by the way say if null is
allowed or not

Ard

>
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Detecting a virtual node

Frank van Lankvelt
In reply to this post by Berry van Halderen
On Thu, Aug 11, 2011 at 11:08 AM, Berry van Halderen
<[hidden email]> wrote:

> On Thu, Aug 11, 2011 at 10:37 AM, Bart van der Schans
> <[hidden email]> wrote:
>>
>> Hi Marnix,
>>
>> Have a look at the method isVirtual() in:
>>
>>
>> https://forge.onehippo.org/svn/jcr-runner/trunk/src/main/java/org/onehippo/forge/jcrrunner/JcrHelper.java
>>
>> I'm not sure if there is a "clean" way to check for virtual nodes
>> without casting to a HippoNode.
>>
>
> No, you need a cast to HippoNode.  The code in that method is a but verbose,
> because the ("if cannonical == null") is unnecessary if you reverse the
> check.
> So instead
>
>         HippoNode hippoNode = (HippoNode) jcrNode;
>
>         Node canonical = hippoNode.getCanonicalNode();
>             if (canonical == null) {
>                 return true;
>             }
>             return !hippoNode.getCanonicalNode().isSame(hippoNode);
>
> You can write the check as:
>   boolean isVirtual = (node instanceof HippoNode ?
> !node.isSame(((HippoNode)node).getCanonicalNode()) : false);
>
I always still catch the ItemNotFoundException on the getCanonicalNode
invocation; IIRC that was thrown when the canonical node has been
removed after the virtual node referring to it was created, right?
(the node is indeed virtual if the exception is thrown)
Is this no longer necessary?

cheers, Frank

> Btw, catching the RepositoryException is not a good idea in general, it
> indicates a generic, often connection-related, problem with the repository,
> where continuing to operate is often not the way to continue, but handling
> the exception (such as a repository that has shut down) at a high level is
> cleared.  This is for generic RepositoryExceptions, not specific instances
> of it (such as PathNotFoundException, but this is not the case here).
>
> \Berry
>
>> Regards,
>> Bart
>>
>>
>>
>> On Thu, Aug 11, 2011 at 10:17 AM, marnixkok <[hidden email]> wrote:
>> > Hi,
>> >
>> > I'm not sure if this is the correct place to ask, but since there's so
>> > much
>> > knowledge regarding the jackrabbit layer contained within the users of
>> > this
>> > forum I'm going to try anyway.
>> >
>> > For a tool I'm writing, using the JCR core libraries, I need to be able
>> > to
>> > identify if a node is a "virtual" node or not. From tiny pieces of
>> > information I have been led to believe that these are called shared
>> > nodes.
>> > However, when I try to retrieve them using the API call it reports that
>> > it
>> > has not yet been implemented.
>> >
>> > Is there a clean way to get these nodes? Maybe I'm just missing
>> > something
>> > very obvious.
>> >
>> > Currently my implementation is able to detect them, but it's a really
>> > silly
>> > piece of code that's probably not very performant -- it exports a node
>> > (without recursion), if it's a virtual node there is no node output
>> > otherwise it's a normal node.
>> >
>> > I understand it's a little bit off-topic, but any help would be very
>> > much
>> > appreciated.
>> >
>> > With kind regards,
>> >
>> > Marnix Kok
>> >
>> > --
>> > View this message in context:
>> > http://hippo.2275632.n2.nabble.com/Detecting-a-virtual-node-tp6675474p6675474.html
>> > Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
>> > _______________________________________________
>> > Hippo-cms7-user mailing list and forums
>> > http://www.onehippo.org/cms7/support/forums.html
>> >
>>
>>
>>
>> --
>> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
>> Boston - 1 Broadway, Cambridge, MA 02142
>>
>> US +1 877 414 4776 (toll free)
>> Europe +31(0)20 522 4466
>> www.onehippo.com
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/forums.html
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html
>



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html