Apache Sling Context Aware Configuration: get the effective node where configuration is defined



Given a hierarchy of CAC configurations defined at multiple levels, for example:




Suppose that I have the resource for `bloodhound` and then I do:

ConfigurationBuilder builder = resource.adaptTo(ConfigurationBuilder.class);
myConfig = builder.as(MyConfig.class);

I can access the configuration properties as needed, but how to get the path where the actual configuration is defined which in this case would be path of CAC2 i.e. /content/en/animals/dogs?

I tried something like:

private ConfigurationResourceResolver configResourceResolver;
contextPath = configResourceResolver.getContextPath(resource);

but contextPath always returns /content/en/animals/dogs/hound/bloodhound and NOT  /content/en/animals/dogs which is what is required for my use case.

I have also tried

realContextPath = configResourceResolver.getResource(resource, "sling:configs", MyConfig.class.getName())

but this always returns null.
Is there a way to do it via the API?

Note: I'm using caconfig with the wcm.io editor and extras.

Answers (0)