Search in sources :

Example 1 with PageFilter

use of com.day.cq.wcm.api.PageFilter in project acs-aem-commons by Adobe-Consulting-Services.

the class SiteMapServlet method doGet.

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    response.setContentType(request.getResponseContentType());
    if (StringUtils.isNotEmpty(this.characterEncoding)) {
        response.setCharacterEncoding(characterEncoding);
    }
    ResourceResolver resourceResolver = request.getResourceResolver();
    PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    Page page = pageManager.getContainingPage(request.getResource());
    XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
    try {
        XMLStreamWriter stream = outputFactory.createXMLStreamWriter(response.getWriter());
        stream.writeStartDocument("1.0");
        stream.writeStartElement("", "urlset", NS);
        stream.writeNamespace("", NS);
        // first do the current page
        write(page, stream, resourceResolver);
        for (Iterator<Page> children = page.listChildren(new PageFilter(false, true), true); children.hasNext(); ) {
            write(children.next(), stream, resourceResolver);
        }
        if (damAssetTypes.size() > 0 && damAssetProperty.length() > 0) {
            for (Resource assetFolder : getAssetFolders(page, resourceResolver)) {
                writeAssets(stream, assetFolder, resourceResolver);
            }
        }
        stream.writeEndElement();
        stream.writeEndDocument();
    } catch (XMLStreamException e) {
        throw new IOException(e);
    }
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) PageFilter(com.day.cq.wcm.api.PageFilter) IOException(java.io.IOException)

Example 2 with PageFilter

use of com.day.cq.wcm.api.PageFilter 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)

Aggregations

Page (com.day.cq.wcm.api.Page)2 PageFilter (com.day.cq.wcm.api.PageFilter)2 LanguageNavigationItem (com.adobe.cq.wcm.core.components.models.LanguageNavigationItem)1 NavigationItem (com.adobe.cq.wcm.core.components.models.NavigationItem)1 PageManager (com.day.cq.wcm.api.PageManager)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1