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 wasn’t 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