Content Policy Sling Models Injector

Available since version 6.6.0

Purpose

Allows for Sling Models to inject ValueMap values or perform adaptions from the content policy ValueMap into your sling model.

Injections are available when adapting either a Resource or SlingHttpServletRequest object.

Example - inject “linkDisabled” into the sling model, from the content policy set on the component level

import com.adobe.acs.commons.models.injectors.annotation.ContentPolicyValue;

@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
public class TestModel {

        @ContentPolicyValue
        private boolean linkDisabled;
}

Example - inject “clientlibsAsync” into the sling model, from the content policy set on the page level

@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
public class TestModel {

       @ContentPolicyValue(usePagePolicy= true)
       private boolean clientlibsAsync;
}

Example - inject “linkDisabled” into the sling model, from the content policy set on the component level

import com.adobe.acs.commons.models.via.annotations.ContentPolicyViaType;

@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
public class TestModel {

        // use @Via to get the ContentPolicyValueMap object, then @ValueMapValue to get the value from the object
        @ValueMapValue
        @Via(type = ContentPolicyViaType.class)
        private boolean linkDisabled;
    
}

Example - inject “clientlibsAsync” into the sling model, from the content policy set on the page level

import com.adobe.acs.commons.models.via.annotations.ContentPolicyViaType;

@Model(adaptables = { SlingHttpServletRequest.class, Resource.class })
public class TestModel
{

        // in this case, use VIA_RESOURCE_PAGE to get the content policy from the page
        @ValueMapValue
        @Via(value=ContentPolicyViaType.VIA_RESOURCE_PAGE, type = ContentPolicyViaType.class)
        @Optional
        private boolean clientlibsAsync;
}