Search in sources :

Example 6 with NavigationItem

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

the class LanguageNavigationImpl method getItems.

private List<NavigationItem> getItems(Page root) {
    List<NavigationItem> pages = new ArrayList<>();
    if (root.getDepth() < structureDepth) {
        Iterator<Page> it = root.listChildren(new PageFilter());
        while (it.hasNext()) {
            Page page = it.next();
            boolean active = currentPage.getPath().equals(page.getPath()) || currentPage.getPath().startsWith(page.getPath() + "/");
            String title = page.getNavigationTitle();
            if (title == null) {
                title = page.getTitle();
            }
            List<NavigationItem> children = getItems(page);
            int level = page.getDepth() - startLevel;
            Page localizedPage = getLocalizedPage(currentPage, page);
            if (localizedPage != null) {
                page = localizedPage;
            }
            boolean current = currentPage.getPath().equals(page.getPath());
            pages.add(newLanguageNavigationItem(page, active, current, linkHandler, level, children, title, getId(), component));
        }
    }
    return pages;
}
Also used : NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem) LanguageNavigationItem(com.adobe.cq.wcm.core.components.models.LanguageNavigationItem) ArrayList(java.util.ArrayList) Page(com.day.cq.wcm.api.Page) PageFilter(com.day.cq.wcm.api.PageFilter)

Example 7 with NavigationItem

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

the class BreadcrumbImpl method createItems.

private List<NavigationItem> createItems() {
    List<NavigationItem> items = new ArrayList<>();
    int currentLevel = currentPage.getDepth();
    while (startLevel < currentLevel) {
        Page page = currentPage.getAbsoluteParent(startLevel);
        if (page != null && page.getContentResource() != null) {
            boolean isActivePage = page.equals(currentPage);
            if (isActivePage && hideCurrent) {
                break;
            }
            if (checkIfNotHidden(page)) {
                NavigationItem navigationItem = newBreadcrumbItem(page, isActivePage, linkHandler, currentLevel, Collections.emptyList(), getId(), component);
                items.add(navigationItem);
            }
        }
        startLevel++;
    }
    return items;
}
Also used : NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem) ArrayList(java.util.ArrayList) Page(com.day.cq.wcm.api.Page)

Example 8 with NavigationItem

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

the class BreadcrumbImplTest method checkBreadcrumbConsistency.

protected void checkBreadcrumbConsistency(Breadcrumb breadcrumb, String[] expectedPages) {
    assertEquals(breadcrumb.getItems().size(), expectedPages.length, "Expected that the returned breadcrumb will contain " + expectedPages.length + " items");
    int index = 0;
    for (NavigationItem item : breadcrumb.getItems()) {
        assertEquals(expectedPages[index++], item.getTitle());
    }
}
Also used : NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem)

Example 9 with NavigationItem

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

the class NavigationImplTest method verifyNavigationItems.

protected void verifyNavigationItems(Object[][] expectedPages, List<NavigationItem> items) {
    assertEquals(expectedPages.length, items.size(), "The navigation tree contains a different number of pages than expected.");
    int index = 0;
    for (NavigationItem item : items) {
        assertEquals(expectedPages[index][0], item.getPath(), "The navigation tree doesn't seem to have the correct order.");
        assertEquals(expectedPages[index][1], item.getLevel(), "The navigation item's level is not what was expected: " + item.getPath());
        assertEquals(expectedPages[index][2], item.isActive(), "The navigation item's active state is not what was expected: " + item.getPath());
        String expectedURL = expectedPages[index][3].toString();
        if (!expectedURL.startsWith("http")) {
            expectedURL = CONTEXT_PATH + expectedURL;
        }
        assertEquals(expectedURL, item.getURL(), "The navigation item's URL is not what was expected: " + item.getPath());
        verifyNavigationItem(expectedPages[index], item);
        index++;
    }
}
Also used : NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem)

Example 10 with NavigationItem

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

the class LanguageNavigationImplTest method testLanguageNavigationItems.

@Test
protected void testLanguageNavigationItems() {
    LanguageNavigation languageNavigation = getLanguageNavigationUnderTest(NAVIGATION_ROOT + "/LOCALE-1/LOCALE-5/about/jcr:content/root/languagenavigation-component-1");
    List<NavigationItem> items = getLanguageNavigationItems(languageNavigation);
    verifyLanguageNavigationItems(EXPECTED_PAGES_DEPTH_1, items);
    Utils.testJSONExport(languageNavigation, Utils.getTestExporterJSONPath(testBase, "languagenavigation1"));
}
Also used : LanguageNavigation(com.adobe.cq.wcm.core.components.models.LanguageNavigation) LanguageNavigationItem(com.adobe.cq.wcm.core.components.models.LanguageNavigationItem) NavigationItem(com.adobe.cq.wcm.core.components.models.NavigationItem) Test(org.junit.jupiter.api.Test)

Aggregations

NavigationItem (com.adobe.cq.wcm.core.components.models.NavigationItem)12 Test (org.junit.jupiter.api.Test)6 LanguageNavigationItem (com.adobe.cq.wcm.core.components.models.LanguageNavigationItem)5 LanguageNavigation (com.adobe.cq.wcm.core.components.models.LanguageNavigation)4 Page (com.day.cq.wcm.api.Page)3 Page (com.adobe.cq.wcm.core.components.models.Page)2 ArrayList (java.util.ArrayList)2 PageFilter (com.day.cq.wcm.api.PageFilter)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1