Hi Magnolians
I need to find out the page that the node belongs to. The node however can be
at any level under page (nested).
/page/mainColumn/0/
/page/mainColumn/leftTable/00/
I am after 'page' here and have collection of paragraph nodes ['0','00']
After some thinking I came up with this and was wondering if there is a better
way or approach....
/*
* article node is usually in a collection (or a collection of a collection)
* which in turn belongs to a page. To get the page that node belongs to
* we visit the node ancestors unitl we reach one that
* has note type of "mgnl:content".
* this method will work regardless of the nesting level
* for the node.
*/
public static Content getArticlePage(final Content pArticleNode) {
System.out.println("Resolving page for: " + pArticleNode.getHandle());
try {
Content ancestor = pArticleNode.getParent();
while (!ancestor.getHandle().equals("/")) {
if (ancestor.getNodeTypeName().equals("mgnl:content")) {
System.out.println("Page is: " + ancestor.getHandle());
return ancestor;
}
ancestor = ancestor.getParent();
}
} catch (AccessDeniedException e) {
e.printStackTrace();
} catch (PathNotFoundException e) {
e.printStackTrace();
} catch (RepositoryException e) {
e.printStackTrace();
}
//failsafe
return pArticleNode;
}
Any input is appreciated
----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/developer.html
----------------------------------------------------------------