Author: andre Date: 2009-11-26 21:15:12 +0100 (Thu, 26 Nov 2009) New Revision: 39993
Modified: openimages/trunk/mmsite/src/main/config/functions/mmsite.xml openimages/trunk/mmsite/src/main/java/org/mmbase/mmsite/UrlUtils.java Log: added function to find parent of node in hierarchy Modified: openimages/trunk/mmsite/src/main/config/functions/mmsite.xml =================================================================== --- openimages/trunk/mmsite/src/main/config/functions/mmsite.xml 2009-11-26 20:10:16 UTC (rev 39992) +++ openimages/trunk/mmsite/src/main/config/functions/mmsite.xml 2009-11-26 20:15:12 UTC (rev 39993) @@ -15,6 +15,17 @@ <return type="org.mmbase.bridge.Node" /> </function> + <function name="parent"> + <description> + The parent node in the hierarchy. + </description> + <type>class</type> + <class>org.mmbase.mmsite.UrlUtils</class> + <method>parent</method> + <param name="node" type="Node" description="A node f.e. of type page" /> + <return type="org.mmbase.bridge.Node" /> + </function> + <function name="crumbs"> <description> Returns a NodeList containing nodes of the same (!) type travelling the path to the 'root' Modified: openimages/trunk/mmsite/src/main/java/org/mmbase/mmsite/UrlUtils.java =================================================================== --- openimages/trunk/mmsite/src/main/java/org/mmbase/mmsite/UrlUtils.java 2009-11-26 20:10:16 UTC (rev 39992) +++ openimages/trunk/mmsite/src/main/java/org/mmbase/mmsite/UrlUtils.java 2009-11-26 20:15:12 UTC (rev 39993) @@ -40,6 +40,21 @@ NodeList l = listNodes2Root(node); return l; } + + /** + * The parent node in the hierarchy. + * + * @param node A node of some type with a field 'path' + * @return parent node + */ + public static Node parent(Node node) { + NodeList l = listNodes2Root(node); + if (l.size() > 1) { + return l.get(l.size() - 2); + } else { + return l.get(0); + } + } /** * Get the '(most) root' node, being the (grand)parent of all the nodes in the crumbpath. _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs