use of com.adobe.cq.wcm.core.components.models.HtmlPageItem 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;
}
use of com.adobe.cq.wcm.core.components.models.HtmlPageItem in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testHtmlPageItemsConfig.
@Test
void testHtmlPageItemsConfig() {
loadHtmlPageItemsConfig(true);
Page page = getPageUnderTest(PAGE);
assertNotNull(page.getHtmlPageItems());
assertEquals(3, page.getHtmlPageItems().size(), "Unexpected number of HTML page items");
Map<String, Object> cssAttributes = new HashMap<>();
Map<String, Object> jsAttributes = new HashMap<>();
Map<String, Object> metaAttributes = new HashMap<>();
cssAttributes.put("href", "/_theme/theme.css");
cssAttributes.put("rel", "preload");
cssAttributes.put("as", "style");
jsAttributes.put("async", true);
jsAttributes.put("defer", false);
jsAttributes.put("src", "/_theme/theme.js");
metaAttributes.put("charset", "UTF-8");
Object[] attributes = { cssAttributes, jsAttributes, metaAttributes };
int index = 0;
for (HtmlPageItem item : page.getHtmlPageItems()) {
assertEquals(attributes[index], item.getAttributes(), "Wrong attributes");
index++;
}
}
use of com.adobe.cq.wcm.core.components.models.HtmlPageItem in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testHtmlPageItemsConfigWithDeprecatedCaconfig.
@Test
void testHtmlPageItemsConfigWithDeprecatedCaconfig() throws Exception {
Page page = getPageUnderTest(PAGE);
loadHtmlPageItemsConfig(false);
assertNotNull(page.getHtmlPageItems());
assertEquals(3, page.getHtmlPageItems().size(), "Unexpected number of HTML page items");
int[] attributeCounts = { 3, 3, 1 };
int index = 0;
for (HtmlPageItem item : page.getHtmlPageItems()) {
assertEquals(attributeCounts[index], item.getAttributes().size());
index++;
}
}
Aggregations