Hi Felix, I'm sorry for my misleading explanation.
I start with a list of resourceTypes. Each resourceType represents a single component in terms of our application (despite of their inheritance). Now I query my repository for all resources with one of the resourceTypes and get a list of resources. (sling:resourceType equals to one of the resourceTypes in the list). For each of these selected resources I want to get the right implementation of its resourceType. Therefore I thought that it would be necessary to resolve the servlet that is used to render the resource (like it is done when the browser requests the resource). Finally the task is to count all occurrences of each implementation. Thanks for your help, Dirk -----Ursprüngliche Nachricht----- Von: Felix Meschberger [mailto:[email protected]] Gesendet: Donnerstag, 12. Januar 2012 10:02 An: [email protected] Betreff: Re: Servlet Resoultion based only on a resource path Hi Dirk, Am 05.01.2012 um 16:11 schrieb Dirk Rudolph: > my task is to write a Servlet that should be used to get a list of all > components, their inheritance and how often they occur in the content tree. What is a component (in terms of Sling) ? > So the first issue wasnt a problem but now I have to search for all > nodes that are instances of one of the collected components. At first > I search my JCR repository using SQL and the sling:resourceType in the where clause. > Afterwards I want to resolve for each Node/Resource found by the query > the right Servlet because it is possible that one resourceType exists > twice like in this example: > > > > /apps/foundation/components/test => resourceType = > foundation/components/test > > /libs/foundation/components/test => resourceType = > foundation/components/test Actually, the resource type only exists once. Since it is "foundation/components/test". But there are multiple "implementations" of it; one in /apps and one in /libs. And depending on the ResourceResolver.getSearchPath setup, there may be even more. This is in line with a single interface (or abstract class) in Java (which is somewhat comparable to resource types) and implementations thereof (which is somewhat comparable to the resource tree locations where scripts and servlets reside). This is where the question raises: What exactly do you try to find ? If you try to find all scripts and servlets replying to a content of a certain resource type ? If so, this can "easily" be implemented using something like this: while (resourceType != null) { if (resourceType.startsWith("/")) { enumerateContentsOf(resourceType); } else { for (String path: resourceResolver.getSearchPath()) { enumerateContentsOf(path + resourceType); } } resourceType = ResourceUtil.getResourceSuperType(resourceResolver, resourceType); } where enumerateContentsOf(String absPath) would just walk down the resource tree (using ResourceResolver.listChildren()) starting from absPath and collect all servlets and scripts (which can be detected by whether a Resource adapts to Servlet.class). (This is not tested, just off the top of my head) Regards Felix
