1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.xml;
20
21 import java.io.PrintWriter;
22 import java.io.Writer;
23 import java.util.Map;
24 import org.apache.maven.api.xml.Dom;
25 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
26 import org.codehaus.plexus.util.xml.XMLWriter;
27
28
29
30
31 public class Xpp3DomWriter {
32 public static void write(Writer writer, Dom dom) {
33 write(new PrettyPrintXMLWriter(writer), dom);
34 }
35
36 public static void write(PrintWriter writer, Dom dom) {
37 write(new PrettyPrintXMLWriter(writer), dom);
38 }
39
40 public static void write(XMLWriter xmlWriter, Dom dom) {
41 write(xmlWriter, dom, true);
42 }
43
44 public static void write(XMLWriter xmlWriter, Dom dom, boolean escape) {
45
46 xmlWriter.startElement(dom.getName());
47 for (Map.Entry<String, String> attr : dom.getAttributes().entrySet()) {
48 xmlWriter.addAttribute(attr.getKey(), attr.getValue());
49 }
50 for (Dom aChildren : dom.getChildren()) {
51 write(xmlWriter, aChildren, escape);
52 }
53
54 String value = dom.getValue();
55 if (value != null) {
56 if (escape) {
57 xmlWriter.writeText(value);
58 } else {
59 xmlWriter.writeMarkup(value);
60 }
61 }
62
63 xmlWriter.endElement();
64 }
65 }