我的要求是在JCR中迭代8000多个节点,并使用PageManager API为每个节点用Java创建一个Page对象。
首先,我使用PageManager获取页面的标题,如下所示。
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();
}
这里我将页面对象设为null,当我尝试传递Geometrixx页面URL以获取其标题时,它正在抛出“页面不存在:/content/geometrixx/fr.html”。
答案 0 :(得分:0)
删除扩展名(.html)和Execute.It将正常工作。 对于超过80000页的迭代,使用递归函数。
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);
}
}
}