Created
March 27, 2016 18:54
-
-
Save nateyolles/1741a2e5d7125eb4bf94 to your computer and use it in GitHub Desktop.
AEM com.adobe.granite.confmgr.Conf examples of getting a specific configuration and getting it's list of inherited settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nateyolles.aem.slashconf.core.models; | |
import java.util.List; | |
import javax.annotation.PostConstruct; | |
import javax.inject.Inject; | |
import org.apache.sling.api.SlingHttpServletRequest; | |
import org.apache.sling.api.resource.ResourceResolver; | |
import org.apache.sling.api.resource.ValueMap; | |
import org.apache.sling.models.annotations.Model; | |
import com.adobe.granite.confmgr.Conf; | |
/** | |
* AEM com.adobe.granite.confmgr.Conf examples of getting a specific | |
* configuration using a Resource Resolver as well as getting a List inherited | |
* configurations using the getList method. | |
*/ | |
@Model(adaptables = SlingHttpServletRequest.class) | |
public class ConfOtherModel { | |
@Inject | |
ResourceResolver resolver; | |
@PostConstruct | |
protected void init() { | |
/* Get a specific configuration */ | |
final Conf conf = resolver.getResource("/conf/tenants/hooli/hoolixyz").adaptTo(Conf.class); | |
final ValueMap fooSettings = conf.getItem("socialmedia/foo"); | |
final String fooName = fooSettings.get("name", String.class); | |
/* Get a list of configurations including all confs in the inheritance tree. */ | |
final List<ValueMap> fooSettingsList = conf.getList("socialmedia/foo"); | |
for (ValueMap properties : fooSettingsList) { | |
properties.get("name", String.class); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment