hi guys,

>   var node = resource.adaptTo(Packages.javax.jcr.Node)

i personally think this sucks since it is going to be a
cryptic part in the beginning of all my esp scripts...
in my view this really should be hidden. the point of
using scripting is to hide all the unnecessary detail of whats
going on underneith...

as a matter of fact i would like to see a "currentNode" variable
in all the scripting environments, so i don't have to deal with the
resource to begin with...

regards,
david

On 2/15/08, Felix Meschberger <[EMAIL PROTECTED]> wrote:
> Hi,
>
>  Am Freitag, den 15.02.2008, 11:43 +0100 schrieb Michael Marth:
>
> > Hi Felix,
>  >
>  > >
>  > > > But if I try to access something like $resource.node (which I would 
> have
>  > > > expected) Velocity does not recognize the expression. How do I get to
>  > > the
>  > > > node? Do I have the wrong syntax? I looked at the src of 
> JcrNodeResource
>  > > and
>  > > > expected to be able to use something like .node, .getNode() or similar.
>  > >
>  > >
>  > > I do not exactly know, how velocity maps Java objects. But a resource is
>  > > definitely a Resource and by conincidence a JcrNodeResource. In
>  > > addition, the JcrNodeResource.getNode() method is not public and not
>  > > part of the API.
>  > >
>  > > When you want to access the node of a resource you will have to adapt
>  > > the Resource to the Node class, something like:
>  > >
>  > >      $resource.adaptTo(Node.class);
>  > >
>  > > But I am not exactly sure about the exact syntax.
>  >
>  >
>  > I am not exactly a velocity expert, but I tried this and had no success so
>  > far. But I also think that having to "cast" (sort of) a resource into a 
> node
>  > in a script is a bit weird.
>
>
> This is not a cast its an adaption to another "view" of the same
>  resource.
>
>
>  >  Especially, if you consider that
>  > resource.nodeworks in esp's. Could we not just get the node as an
>  > object right away?
>
>
> Which is probably an error as it introduces an API in JavaScript which
>  is not paralelled by the other APIs, we should probably remove that ....
>
>
>  >
>  > I am aware that this has been discussed before, but I do not see any
>  > advantages of abstraction lost if the node object is available to the
>  > scripts if the resource in question is actually a node.
>
>
> I do not quite understand this sentence. Do you want to say, the node is
>  lost due to the abstraction ? This is not the case as you can adapt the
>  resource to the node.
>
>
>  >  The script needs to
>  > "know" it handles nodes anyway.
>
>
> Yes, your particular script might now, but a script in general might not
>  care ... So we have the resource and that's it. You get the node by
>  adapting the resource. The question is how to use this API in your
>  favourite scripting language.
>
>  E.g. in JavaScript you can do
>
>    var node = resource.adaptTo(Packages.javax.jcr.Node)
>
>  maybe in Velocity the equivalent might be
>
>    #set( $node = $resource.adaptTo(javax.jcr.Node) )
>
>  Regards
>  Felix
>
>  >
>  > WDYT?
>  > Michael
>
>

Reply via email to