Search in sources :

Example 1 with HtmlPageItemConfig

use of com.adobe.cq.wcm.core.components.config.HtmlPageItemConfig in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImpl method getHtmlPageItems.

@Override
@NotNull
public List<HtmlPageItem> getHtmlPageItems() {
    if (htmlPageItems == null) {
        htmlPageItems = new LinkedList<>();
        ConfigurationBuilder configurationBuilder = configurationResolver.get(resource);
        HtmlPageItemsConfig config = configurationBuilder.as(HtmlPageItemsConfig.class);
        for (HtmlPageItemConfig itemConfig : config.items()) {
            HtmlPageItem item = new HtmlPageItemImpl(StringUtils.defaultString(config.prefixPath()), itemConfig);
            if (item.getElement() != null) {
                htmlPageItems.add(item);
            }
        }
        // Support the former node structure: see com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig
        if (htmlPageItems.isEmpty()) {
            Resource configResource = configurationResourceResolver.getResource(resource, "sling:configs", HtmlPageItemsConfig.class.getName());
            if (configResource != null) {
                ValueMap properties = configResource.getValueMap();
                for (Resource child : configResource.getChildren()) {
                    HtmlPageItem item = new HtmlPageItemImpl(properties.get(HtmlPageItemsConfig.PN_PREFIX_PATH, StringUtils.EMPTY), child);
                    if (item.getElement() != null) {
                        htmlPageItems.add(item);
                    }
                }
            }
        }
    }
    return htmlPageItems;
}
Also used : ConfigurationBuilder(org.apache.sling.caconfig.ConfigurationBuilder) HtmlPageItemsConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig) HtmlPageItemConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemConfig) HtmlPageItem(com.adobe.cq.wcm.core.components.models.HtmlPageItem) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HtmlPageItemConfig (com.adobe.cq.wcm.core.components.config.HtmlPageItemConfig)1 HtmlPageItemsConfig (com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig)1 HtmlPageItem (com.adobe.cq.wcm.core.components.models.HtmlPageItem)1 Resource (org.apache.sling.api.resource.Resource)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 ConfigurationBuilder (org.apache.sling.caconfig.ConfigurationBuilder)1 NotNull (org.jetbrains.annotations.NotNull)1