Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the star resource path?

Adobe AEM parsys component renders all children resources and if the WCM mode is set to the appropriate value, it displays Drop component section, which can be used to add new paragraphs. Implementation of the Drop component section is quite strange - it's embedded as a separate component with <cq:include> tag, but the path parameter is set to * (star):

<cq:include path="*" resourceType="<%= newType %>"/>

(newType is a Java variable set before this line).

What happens here? What is the purpose of this star?

like image 507
Tomek Rękawek Avatar asked Mar 17 '23 20:03

Tomek Rękawek


1 Answers

Sling provides a way to automatically create a resource name. If you send a POST request to an URL ending with a /*, Sling will generate the resource name, using a number of rules described in the documentation.

If you intercept the request sent to the /* resource in servlet or filter and invoke the request.getResource() method, you'll get a StarResource object. It extends the SyntheticResource type, representing resources that doesn't have appropriate node in the JCR. Its resource type is sling:syntheticStarResource, you can call its getParent() method, but generally it isn't very useful. An attempt to adapting it to ValueMap will fail. Sling provides a helper method that checks if the given Resource is a StarResource.

In case of the paragraph system implementation mentioned in the question, the author of the code probably wanted to display the Drop component using a synthetic resource and providing * as the path is the easiest way to do it. You can also be sure that the resource will always be synthetic, as it's impossible to create a node with this name.

like image 95
Tomek Rękawek Avatar answered Apr 08 '23 19:04

Tomek Rękawek