Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

ccpiizz
Level 1
Level 1

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.

1 Accepted Solution
Arun_Patidar
Correct answer by
Community Advisor
Community Advisor
1 Reply
Arun_Patidar
Correct answer by
Community Advisor
Community Advisor