0

My requirement is to iterate over 8000 nodes in the JCR and create a Page object in Java for each node using PageManager API.

To start with I am using PageManager to get the title of a Page as below.

public String currentPageTitle(String pagePath) {
    Page page=null;
    ResourceResolver resourceResolver=null;
    PageManager pageManager=null;
    try {
        if (pagePath != null) {
            resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
            pageManager = resourceResolver.adaptTo(PageManager.class);
            **page = pageManager.getContainingPage(resourceResolver.getResource(pagePath));**
            LOGGER.error("Page $$$$"+page);
            if (page == null) {
                throw new IllegalArgumentException("Page does not exist: " + pagePath);
            }
        }
    } catch (LoginException e) {
        LOGGER.error("Login Exception");
        e.printStackTrace();
    }
    return page.getTitle();
}

Here I am getting page object as null, and it's throwing "Page does not exist: /content/geometrixx/fr.html" when i am trying to pass Geometrixx page URL to get its title.

anotherdave
  • 6,656
  • 4
  • 34
  • 65
Esha Ch
  • 13
  • 1
  • 5
  • 2
    Did you pass the path as `/content/geometrixx/fr.html` or `/content/geometrixx/fr` ? – rakhi4110 Jan 13 '15 at 06:58
  • 1. As rakhi mentioned for resource resolving, don't provide an extension, just the path. 2. You can directly use the path in getContainingPage method, as there is a version with a String as a parameter. – Thomas Jan 13 '15 at 07:22
  • Thanks rakhi4110 & Thomas ... It did work as per your suggetion. – Esha Ch Jan 13 '15 at 10:32

1 Answers1

0

Remove Extension(.html) and Execute.It will work Fine. For Iteration over 80000 pages use Recursive function .

public String currentPageTitle(String pagePath) {
    Page page=null;
    ResourceResolver resourceResolver=null;
    PageManager pageManager=null;
    try {
        if (pagePath != null) {
            resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
            pageManager = resourceResolver.adaptTo(PageManager.class);
            page = pageManager.getContainingPage(resourceResolver.getResource(pagePath));
            LOGGER.error("Page $$$$"+page);
            if (page == null) {
                throw new IllegalArgumentException("Page does not exist: " + pagePath);
            }else{
                buildLinkAndChildren_loop(page);
            }
        }
    } catch (LoginException e) {
        LOGGER.error("Login Exception");
        e.printStackTrace();
    }
    return page.getTitle();
}
public void buildLinkAndChildren_loop(Page page) {
    if (page != null) {
        Iterator<Page> children = page.listChildren();
        while (children.hasNext()) {
            Page child = children.next();
            buildLinkAndChildren_loop(child);

        }
    }
}