Hi Jason,

That’s true and mentioned, albeit a bit short on words if you will at [1]:

Returns true if the resource type or any of the resource's super type(s) equals 
the given resource type.

So basically, Sling deals with Resource objects which have a Resource Type 
which form a hierarchy much like the Java class hierarchy. The implicit root 
resource type is called „sling/servlet/default“ (not the best of all names, I 
agree, but this is historical :-) ). The Resource.isResourceType(String) and 
ResourceUtil.isA(Resource, String) methods basically mimick the Java instanceof 
operator.

And yes, this might better described on [2] (should show up shortly)

Hope this helps.

Regards
Felix

[1] 
http://sling.apache.org/apidocs/sling6/org/apache/sling/api/resource/Resource.html#isResourceType(java.lang.String)
[2] http://sling.apache.org/documentation/the-sling-engine/resources.html

Am 11.09.2014 um 15:54 schrieb Jason E Bailey 
<[email protected]<mailto:[email protected]>>:

I understand the difference between the Sling Resource Type and the JCR
Node type. However the resource.isResourceType is not specifically
dealing with one or the other. If I had a resource of a node with a
primaryNodeType of nt:file then doing resource.isResourceType("nt:file")
would return true.

I had to dig through the code to see what was going on.

The basic idea is that calling resource.getResourceType() will return
the sling:resourceType and if that's not there then it will return the
jcr:primaryType. When calling "isResourceType" it will compare against
the resource.getResourceType() and if that's not a match will march of
the chain of getSuperResourceType looking for a match, and that matches
only against the sling:resourceType.

I can sorta see where that's useful from a script resolution point of
view. I find it odd overall as it's missing out on a section of
inheritance. It's like having a java instanceof operator ignoring
interfaces.

--
 Jason

On Wed, Sep 10, 2014, at 01:13 PM, Paul McMahon wrote:
There isn't necessarily a mapping between Sling Resource Type and the JCR
Node type. The sling resource type is determined based on the value or
the sling:resourceType property on the node, where as the JCR Node type
is determined based on jcr:primaryType value. In most cases nodes of
sling:resourceType will always be the same jcr:primaryType, but technical
that isn't a requirement. In  reality there are most jcr:primaryTypes map
to many different sling:resourceType (or no sling resource type).


Paul McMahon
Acquity Group, Part of Accenture Interactive


On Wednesday, September 10, 2014 9:56 AM, Jason E Bailey
<[email protected]<mailto:[email protected]>> wrote:



Lets say I have a node of type sling:Folder.



Calling

node.isNodeType("nt:folder")

will return true, since sling:Folder extends nt:folder



However

resource.isResourceType("nt:folder")

will return false. I'm assuming since it's attempting to
resolve up the resource heirarchy(?)



My question, is there a Foo utility to determine if a given
resource is of a particular type via the node definition?



TIA.

--
Jason E Bailey

Reply via email to