You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Ulrich Schmidt <Ul...@gombers.de> on 2013/01/25 18:16:54 UTC

Resource Resolving

Being new with Sling, I need to get familiar with it. Until now I understand
that there is no comprehensive reference describing the Sling architecture and
methods in detail. Until now I saw some CQ5-samples which don't work for me and
I don't understand how one comes to expect that they should work.

So I'm looking for a document, source, ruleset or anything else where I can
extract the way how resolving is done. I found the Interface "ResourceResolver"
supplied by Sling but have no clue which class is implementing it. Maybe such a
class would help. I'm astonished anyway, why this interface is mentioned in all
the websites I found until now instead of the implementing class. As if it was
users responsibilty to do the resolving.

This is what I understand so far (source: Sling
cheatsheet(http://dev.day.com/content/ddc/blog/2008/07/cheatsheet.html)   and CQ
Basics (http://dev.day.com/docs/en/cq/current/developing/the_basics.html):

(1) Sling splts the URI in different parts and maps them to the resources.
(2) The path is either mapped according to the sling:resourceType or the
sling:resourceSuperType (both attributes either specified to the path-node or
inherited from parents) or to the node (specified by the path) itself; in this
case the node must be  of type nt:file or contain a subnode of type nt:file.
(3) In either case (resolved by sling:resourceType, sling:resourceSuperType or
using the node itself) Sling looks for scripts contained in the resolved node.
(4) There are four ScriptTypes supported: est (ECMAScript), java (Java Source
becomes compiled), jsp (Java Server Pages) and jst (Java Script Templates).  The
type "js" is not mentioned in "The Basics".
(5) For HTTP-GET requests there is a best match sequence for looking up the
script name; for HTTP-PUT-requests an exact-match is required.

Is this ok so far?

These are some of the samples I don't understand:

see also "How to Create a Fully Featured Internet Website"
(http://dev.day.com/docs/en/cq/current/howto/website.html) and the discussion at
the bottom. Ulrich, thats me.
(a) the node /content/mywebsite/en/products is of type cq:Page and the subnode
jcr:content has an attribute
sling:resourceType=mywebsite/components/contentpage.
The path /apps/mywebsite/components/contentpage contains a node body.jsp (and
some others referenced by body.jsp).
The request http://localhost:4502//content/mywebsite/en/products.html renders
the node /apps/mywebsite/components/contentpage/body.jsp.
This is the first thing I don't understand. Why is body.jsp looked up for
rendering; why does it belong to the best match sequence showed in (5).

(b) One of the jsps included by body.jsp displays an image. The image is also a
node in /apps/mywebsite/components/contentpage/
Within the jsp the string /content/mywebsite/en/products/navimage.png is
specified. But the image does not show up in the browser. When I specify
/apps/mywebsite/components/contentpage/navimage.png instead all works fine. So
if resolving for the website
http://localhost:4502//content/mywebsite/en/products.html works, why doesn't it
work for the image.

(c) In the screencast "TheServerSide,com in 15 minutes
(http://dev.day.com/content/ddc/blog/2008/04/firststeps2.html)" a static html is
converted to dynamic. They create a node /apps/tss/posts/html.jst and invoke it
with "localhost:4502/content/tss/posts/*.post.html". (As this screencast was
recorded in 2008 they recommend to change the node to /apps/tss/post.jst, but no
recommendation for the HTTP-Request). The node /content/tss isn't there when the
URL is invoked first; the post.jst POST-request creates it.
So there cannot be a sling:requestTyppe anywhere - how can we expect that Sling
will correctly map the HTTP-request generated by typing the URL.

As resource resolving is very basic for developing on CQ5, I urgently need to
understand the logic here, Any help is appreciated.

Ulrich

Re: Resource Resolving

Posted by Paul McMahon <or...@yahoo.com>.
Well I am not sure I'd call it a book but have checked the Apache Sling Website (http://sling.apache.org). 

Specifically these pages:
	* http://sling.apache.org/documentation/the-sling-engine/architecture.html

	* http://sling.apache.org/documentation/the-sling-engine/resources.html


I added some response to your CQ questions below, however you might want to consider submitting the CQ questions to the Adobe Community Message boards site rather than here. 

Paul McMahon
Acquity Group


________________________________
 From: Ulrich Schmidt <Ul...@gombers.de>
To: Apache Sling Users Group <us...@sling.apache.org> 
Sent: Friday, January 25, 2013 9:16 AM
Subject: Resource Resolving
 
Being new with Sling, I need to get familiar with it. Until now I understand
that there is no comprehensive reference describing the Sling architecture and
methods in detail. Until now I saw some CQ5-samples which don't work for me and
I don't understand how one comes to expect that they should work.

So I'm looking for a document, source, ruleset or anything else where I can
extract the way how resolving is done. I found the Interface "ResourceResolver"
supplied by Sling but have no clue which class is implementing it. Maybe such a
class would help. I'm astonished anyway, why this interface is mentioned in all
the websites I found until now instead of the implementing class. As if it was
users responsibilty to do the resolving.

This is what I understand so far (source: Sling
cheatsheet(http://dev.day.com/content/ddc/blog/2008/07/cheatsheet.html)   and CQ
Basics (http://dev.day.com/docs/en/cq/current/developing/the_basics.html):

(1) Sling splts the URI in different parts and maps them to the resources.
(2) The path is either mapped according to the sling:resourceType or the
sling:resourceSuperType (both attributes either specified to the path-node or
inherited from parents) or to the node (specified by the path) itself; in this
case the node must be  of type nt:file or contain a subnode of type nt:file.
(3) In either case (resolved by sling:resourceType, sling:resourceSuperType or
using the node itself) Sling looks for scripts contained in the resolved node.
(4) There are four ScriptTypes supported: est (ECMAScript), java (Java Source
becomes compiled), jsp (Java Server Pages) and jst (Java Script Templates).  The
type "js" is not mentioned in "The Basics".
(5) For HTTP-GET requests there is a best match sequence for looking up the
script name; for HTTP-PUT-requests an exact-match is required.

Is this ok so far?

These are some of the samples I don't understand:

see also "How to Create a Fully Featured Internet Website"
(http://dev.day.com/docs/en/cq/current/howto/website.html) and the discussion at
the bottom. Ulrich, thats me.
(a) the node /content/mywebsite/en/products is of type cq:Page and the subnode
jcr:content has an attribute
sling:resourceType=mywebsite/components/contentpage.
The path /apps/mywebsite/components/contentpage contains a node body.jsp (and
some others referenced by body.jsp).
The request http://localhost:4502//content/mywebsite/en/products.html renders
the node /apps/mywebsite/components/contentpage/body.jsp.
This is the first thing I don't understand. Why is body.jsp looked up for
rendering; why does it belong to the best match sequence showed in (5).

/apps/mywebsite/components/contentpage/body.jsp isn't the first script getting called in this situation. I am sure you are referencing foundation/components/page as the sling:superResourceType of /apps/mywebsite/components/contentpage. So what's actually getting executed first is /libs/foundation/components/page.jsp which includes body.jsp using cq:include tag - this is a CQ tag, not a sling tag so the functioning of it isn't really relevant here, however check out http://dev.day.com/docs/en/cq/current/howto/taglib.html for an explanation of its inheritance structure and why your body.jsp gets called. 

(b) One of the jsps included by body.jsp displays an image. The image is also a
node in /apps/mywebsite/components/contentpage/
Within the jsp the string /content/mywebsite/en/products/navimage.png is
specified. But the image does not show up in the browser. When I specify
/apps/mywebsite/components/contentpage/navimage.png instead all works fine. So
if resolving for the website
http://localhost:4502//content/mywebsite/en/products.html works, why doesn't it
work for the image.

Its not resolving because you don't have a resource in your repository at /content/mywebsite/en/products/navimage.png.

(c) In the screencast "TheServerSide,com in 15 minutes
(http://dev.day.com/content/ddc/blog/2008/04/firststeps2.html)" a static html is
converted to dynamic. They create a node /apps/tss/posts/html.jst and invoke it
with "localhost:4502/content/tss/posts/*.post.html". (As this screencast was
recorded in 2008 they recommend to change the node to /apps/tss/post.jst, but no
recommendation for the HTTP-Request). The node /content/tss isn't there when the
URL is invoked first; the post.jst POST-request creates it.
So there cannot be a sling:requestTyppe anywhere - how can we expect that Sling
will correctly map the HTTP-request generated by typing the URL.

As resource resolving is very basic for developing on CQ5, I urgently need to
understand the logic here, Any help is appreciated.

Ulrich

Re: Resource Resolving

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Ulrich,

On Fri, Jan 25, 2013 at 6:16 PM, Ulrich Schmidt
<Ul...@gombers.de> wrote:
> ...So I'm looking for a document, source, ruleset or anything else where I can
> extract the way how resolving is done. I found the Interface "ResourceResolver"
> supplied by Sling but have no clue which class is implementing it. Maybe such a
> class would help. I'm astonished anyway, why this interface is mentioned in all
> the websites I found until now instead of the implementing class. As if it was
> users responsibilty to do the resolving....

It's not, but IIUC what you want to understand should be split in two things

a) Given an incoming request, how does Sling select which Resource to process

b) Once that Resource is found, how does Sling select a script or
servlet to process the request

As Paul indicates, the Sling website does explain those things:

a) is mostly explained in
http://sling.apache.org/documentation/the-sling-engine/resources.html

b) is explained in
http://sling.apache.org/documentation/the-sling-engine/servlets.html

And useful additional details can be found in the automated tests that
these pages point to, and which you might want to expand if you're
unsure of something.

One useful debugging tool is the "recent requests" OSGi console plugin
that you'll find at /system/console/requests in a default Sling setup
and is described at
http://sling.apache.org/site/monitoring-requests.html

As Paul says, CQ5 does add a small layer on top of this, so once you
understand the Sling basics you might need to ask on CQ forums for
things that are not directly handled by Sling.

HTH,
-Bertrand