]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api/src/org/argeo/api/gcr/Contents.java
62b1e9b450867dddbfdce25a96d6d07f9bff5c85
[lgpl/argeo-commons.git] / org.argeo.api / src / org / argeo / api / gcr / Contents.java
1 package org.argeo.api.gcr;
2
3 import java.io.PrintStream;
4 import java.util.function.BiConsumer;
5
6 public class Contents {
7 public static void traverse(Content content, BiConsumer<Content, Integer> doIt) {
8 traverse(content, doIt, 0);
9 }
10
11 public static void traverse(Content content, BiConsumer<Content, Integer> doIt, int currentDepth) {
12 doIt.accept(content, currentDepth);
13 int nextDepth = currentDepth + 1;
14 for (Content child : content) {
15 traverse(child, doIt, nextDepth);
16 }
17 }
18
19 public static void print(Content content, PrintStream out, int depth, boolean printText) {
20 StringBuilder sb = new StringBuilder();
21 for (int i = 0; i < depth; i++) {
22 sb.append(" ");
23 }
24 String prefix = sb.toString();
25 out.println(prefix + content.getName());
26 for (String key : content.keySet()) {
27 out.println(prefix + " " + key + "=" + content.get(key));
28 }
29 if (printText) {
30 if (content.hasText()) {
31 out.println("<![CDATA[" + content.getText().trim() + "]]>");
32 }
33 }
34 }
35
36 public static <T> boolean isString(T t) {
37 return t instanceof String;
38 }
39
40 /** Singleton. */
41 private Contents() {
42
43 }
44 }