]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api/src/org/argeo/api/gcr/Contents.java
62b1e9b450867dddbfdce25a96d6d07f9bff5c85
1 package org
.argeo
.api
.gcr
;
3 import java
.io
.PrintStream
;
4 import java
.util
.function
.BiConsumer
;
6 public class Contents
{
7 public static void traverse(Content content
, BiConsumer
<Content
, Integer
> doIt
) {
8 traverse(content
, doIt
, 0);
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
);
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
++) {
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
));
30 if (content
.hasText()) {
31 out
.println("<![CDATA[" + content
.getText().trim() + "]]>");
36 public static <T
> boolean isString(T t
) {
37 return t
instanceof String
;