]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/acr/ContentUtils.java
Improve ACR.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / acr / ContentUtils.java
index d0ce5d1535bcf954242533f0a4d2febafdf16b55..5609cf7778ca65555824c500e48d3769be944f69 100644 (file)
@@ -6,17 +6,26 @@ import java.util.function.BiConsumer;
 import javax.xml.namespace.QName;
 
 import org.argeo.api.acr.Content;
+import org.argeo.api.cms.CmsSession;
 
+/** Utilities and routines around {@link Content}. */
 public class ContentUtils {
        public static void traverse(Content content, BiConsumer<Content, Integer> doIt) {
-               traverse(content, doIt, 0);
+               traverse(content, doIt, (Integer) null);
        }
 
-       public static void traverse(Content content, BiConsumer<Content, Integer> doIt, int currentDepth) {
+       public static void traverse(Content content, BiConsumer<Content, Integer> doIt, Integer maxDepth) {
+               doTraverse(content, doIt, 0, maxDepth);
+       }
+
+       private static void doTraverse(Content content, BiConsumer<Content, Integer> doIt, int currentDepth,
+                       Integer maxDepth) {
                doIt.accept(content, currentDepth);
+               if (maxDepth != null && currentDepth == maxDepth)
+                       return;
                int nextDepth = currentDepth + 1;
                for (Content child : content) {
-                       traverse(child, doIt, nextDepth);
+                       doTraverse(child, doIt, nextDepth, maxDepth);
                }
        }
 
@@ -37,8 +46,6 @@ public class ContentUtils {
                }
        }
 
-       
-
 //     public static <T> boolean isString(T t) {
 //             return t instanceof String;
 //     }