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