1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration2.tree;
18
19 import java.io.PrintStream;
20
21
22
23
24
25
26 public final class TreeUtils {
27
28 private TreeUtils() {
29 }
30
31
32
33
34
35
36
37 public static void printTree(final PrintStream stream, final ImmutableNode result) {
38 if (stream != null) {
39 printTree(stream, "", result);
40 }
41 }
42
43 private static void printTree(final PrintStream stream, final String indent, final ImmutableNode result) {
44 final StringBuilder buffer = new StringBuilder(indent).append("<").append(result.getNodeName());
45 result.getAttributes().forEach((k, v) -> buffer.append(' ').append(k).append("='").append(v).append("'"));
46 buffer.append(">");
47 stream.print(buffer.toString());
48 if (result.getValue() != null) {
49 stream.print(result.getValue());
50 }
51 boolean newline = false;
52 if (!result.getChildren().isEmpty()) {
53 stream.print("\n");
54 result.forEach(child -> printTree(stream, indent + " ", child));
55 newline = true;
56 }
57 if (newline) {
58 stream.print(indent);
59 }
60 stream.println("</" + result.getNodeName() + ">");
61 }
62 }