1 package org.apache.maven.shared.utils.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.IOException;
23 import java.io.PrintWriter;
24 import java.io.Writer;
25
26
27
28
29 public class Xpp3DomWriter
30 {
31
32
33
34
35
36 public static void write( Writer writer, Xpp3Dom dom ) throws IOException
37 {
38 write( new PrettyPrintXMLWriter( writer ), dom );
39 }
40
41
42
43
44
45
46 public static void write( PrintWriter writer, Xpp3Dom dom ) throws IOException
47 {
48 write( new PrettyPrintXMLWriter( writer ), dom );
49 }
50
51
52
53
54
55
56 public static void write( XMLWriter xmlWriter, Xpp3Dom dom ) throws IOException
57 {
58 write( xmlWriter, dom, true );
59 }
60
61
62
63
64
65
66
67 public static void write( XMLWriter xmlWriter, Xpp3Dom dom, boolean escape ) throws IOException
68 {
69 xmlWriter.startElement( dom.getName() );
70 String[] attributeNames = dom.getAttributeNames();
71 for ( String attributeName : attributeNames )
72 {
73 xmlWriter.addAttribute( attributeName, dom.getAttribute( attributeName ) );
74 }
75 Xpp3Dom[] children = dom.getChildren();
76 for ( Xpp3Dom aChildren : children )
77 {
78 write( xmlWriter, aChildren, escape );
79 }
80
81 String value = dom.getValue();
82 if ( value != null )
83 {
84 if ( escape )
85 {
86 xmlWriter.writeText( value );
87 }
88 else
89 {
90 xmlWriter.writeMarkup( value );
91 }
92 }
93 xmlWriter.endElement();
94 }
95
96 }