Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Get path of actual resource if only given usage reference

Avatar

Level 3
Hi all,

Is it possible to get the actual path of a resource, if we only know where it was used?

For example, I have a policy being used on a template at:
/conf/we-retail/settings/wcm/templates/section-page/policies/jcr:content/root/responsivegrid/weretail/components/content/teaser/policy_1526037253202

Having the above path, I want to get the path of the actual policy, which is should be:
/conf/we-retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202

Is this possible? Thanks
1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @sean12341 ,

 

There are multiple ways to achieve it.

  1. You could use a JCR SQL2 query like below, using the policy name and executing in query editor of CRXDE

 

SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/conf/we-retail]) AND NAME() = 'policy_1526037253202'

 

 

   This will give you the path "/conf/we- retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202" in      the result.

 

2. Quite a manual approach, because if you look at the path there is a pattern

 /conf/we-retail/settings/wcm/templates/section-page/policies/jcr:content/root/responsivegrid/weretail/components/content/teaser/policy_1526037253202

/conf/we-retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202

 

All you need to do is pick the partial path and append "/conf/we-retail/settings/wcm/policies" and you will always end up into the same directory.

 

Hope that helps!

 

Regards,

Nitesh

 

View solution in original post

4 Replies

Avatar

Correct answer by
Employee Advisor

Hi @sean12341 ,

 

There are multiple ways to achieve it.

  1. You could use a JCR SQL2 query like below, using the policy name and executing in query editor of CRXDE

 

SELECT * FROM [nt:base] AS s WHERE ISDESCENDANTNODE([/conf/we-retail]) AND NAME() = 'policy_1526037253202'

 

 

   This will give you the path "/conf/we- retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202" in      the result.

 

2. Quite a manual approach, because if you look at the path there is a pattern

 /conf/we-retail/settings/wcm/templates/section-page/policies/jcr:content/root/responsivegrid/weretail/components/content/teaser/policy_1526037253202

/conf/we-retail/settings/wcm/policies/weretail/components/content/teaser/policy_1526037253202

 

All you need to do is pick the partial path and append "/conf/we-retail/settings/wcm/policies" and you will always end up into the same directory.

 

Hope that helps!

 

Regards,

Nitesh

 

Avatar

Community Advisor

where you wanted to get the actual path, in code?

If in code you just need to get property value for policy and get the resource object with the help of resource resolver for the path.

 

 

Avatar

Level 3

Yes I want to get the path programmatically. 

Could you provide an example or pseudo code of how it can be done? 

I have tried the following:

 

resourceResolver.getResource("/conf/we-retail/settings/wcm/templates/section-page/policies/jcr:content/root/responsivegrid/weretail/components/content/teaser").getValueMap().get("cq:policy")

 

But still only returns the relative path of the policy, which is:

"weretail/components/content/teaser/policy_1526037253202"

 

Thanks

Avatar

Employee Advisor

Why would you need that? Currently that is an implementation detail of AEM, and trying to rely on the implementation (although not specified) might work, but it could also break in interesting and unexpceted ways.