Apache Sling Context Aware Configuration: get the effective node where configuration is defined | Community
Skip to main content
May 22, 2020
Solved

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

  • May 22, 2020
  • 1 reply
  • 1059 views

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

 

/content /en +{CAC1} /animals /dogs +{CAC2} /hound /bloodhound /dachshund /poodle /cats /de

 

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:

@Reference
private ConfigurationResourceResolver configResourceResolver;
...
String
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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.