1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration.tree;
18
19 import java.io.PrintStream;
20 import java.util.Iterator;
21
22
23
24
25
26
27
28
29
30 public final class TreeUtils
31 {
32
33 private TreeUtils()
34 {
35 }
36
37
38
39
40
41
42 public static void printTree(PrintStream stream, ConfigurationNode result)
43 {
44 if (stream != null)
45 {
46 printTree(stream, "", result);
47 }
48 }
49
50 private static void printTree(PrintStream stream, String indent, ConfigurationNode result)
51 {
52 StringBuffer buffer = new StringBuffer(indent).append("<").append(result.getName());
53 Iterator<ConfigurationNode> iter = result.getAttributes().iterator();
54 while (iter.hasNext())
55 {
56 ConfigurationNode node = iter.next();
57 buffer.append(" ").append(node.getName()).append("='").append(node.getValue()).append("'");
58 }
59 buffer.append(">");
60 stream.print(buffer.toString());
61 if (result.getValue() != null)
62 {
63 stream.print(result.getValue());
64 }
65 boolean newline = false;
66 if (result.getChildrenCount() > 0)
67 {
68 stream.print("\n");
69 iter = result.getChildren().iterator();
70 while (iter.hasNext())
71 {
72 printTree(stream, indent + " ", iter.next());
73 }
74 newline = true;
75 }
76 if (newline)
77 {
78 stream.print(indent);
79 }
80 stream.println("</" + result.getName() + ">");
81 }
82 }