1 |
|
package org.apache.maven.tools.plugin.generator; |
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 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
public class PrettyPrintXMLWriter |
32 |
|
extends org.codehaus.plexus.util.xml.PrettyPrintXMLWriter |
33 |
|
{ |
34 |
|
|
35 |
1 |
private static final String LS = System.getProperty( "line.separator" ); |
36 |
|
|
37 |
|
private PrintWriter writer; |
38 |
|
|
39 |
|
private String lineIndenter; |
40 |
|
|
41 |
|
private int depth; |
42 |
|
|
43 |
|
public PrettyPrintXMLWriter( PrintWriter writer, String lineIndenter ) |
44 |
|
{ |
45 |
0 |
this( writer, lineIndenter, null, null ); |
46 |
0 |
} |
47 |
|
|
48 |
|
public PrettyPrintXMLWriter( Writer writer, String lineIndenter ) |
49 |
|
{ |
50 |
0 |
this( new PrintWriter( writer ), lineIndenter ); |
51 |
0 |
} |
52 |
|
|
53 |
|
public PrettyPrintXMLWriter( PrintWriter writer ) |
54 |
|
{ |
55 |
1 |
this( writer, null, null ); |
56 |
1 |
} |
57 |
|
|
58 |
|
public PrettyPrintXMLWriter( Writer writer ) |
59 |
|
{ |
60 |
1 |
this( new PrintWriter( writer ) ); |
61 |
1 |
} |
62 |
|
|
63 |
|
public PrettyPrintXMLWriter( PrintWriter writer, String lineIndenter, String encoding, String doctype ) |
64 |
|
{ |
65 |
1 |
super( writer, lineIndenter, encoding, doctype ); |
66 |
|
|
67 |
1 |
setWriter( writer ); |
68 |
|
|
69 |
1 |
setLineIndenter( lineIndenter ); |
70 |
1 |
} |
71 |
|
|
72 |
|
public PrettyPrintXMLWriter( Writer writer, String lineIndenter, String encoding, String doctype ) |
73 |
|
{ |
74 |
0 |
this( new PrintWriter( writer ), lineIndenter, encoding, doctype ); |
75 |
0 |
} |
76 |
|
|
77 |
|
public PrettyPrintXMLWriter( PrintWriter writer, String encoding, String doctype ) |
78 |
|
{ |
79 |
1 |
this( writer, " ", encoding, doctype ); |
80 |
1 |
} |
81 |
|
|
82 |
|
public PrettyPrintXMLWriter( Writer writer, String encoding, String doctype ) |
83 |
|
{ |
84 |
0 |
this( new PrintWriter( writer ), encoding, doctype ); |
85 |
0 |
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
private void write( String str ) |
93 |
|
{ |
94 |
189 |
getWriter().write( str ); |
95 |
189 |
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
protected String getLineIndenter() |
103 |
|
{ |
104 |
152 |
return lineIndenter; |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
protected void setLineIndenter( String lineIndenter ) |
113 |
|
{ |
114 |
1 |
this.lineIndenter = lineIndenter; |
115 |
1 |
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
protected void endOfLine() |
122 |
|
{ |
123 |
37 |
write( LS ); |
124 |
|
|
125 |
189 |
for ( int i = 0; i < getDepth(); i++ ) |
126 |
|
{ |
127 |
152 |
write( getLineIndenter() ); |
128 |
|
} |
129 |
37 |
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
protected void setWriter( PrintWriter writer ) |
137 |
|
{ |
138 |
1 |
this.writer = writer; |
139 |
1 |
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
protected PrintWriter getWriter() |
147 |
|
{ |
148 |
189 |
return writer; |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
protected void setDepth( int depth ) |
157 |
|
{ |
158 |
54 |
this.depth = depth; |
159 |
54 |
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
protected int getDepth() |
167 |
|
{ |
168 |
243 |
return depth; |
169 |
|
} |
170 |
|
|
171 |
|
public void startElement( String name ) |
172 |
|
{ |
173 |
27 |
super.startElement( name ); |
174 |
|
|
175 |
27 |
setDepth( getDepth() + 1 ); |
176 |
27 |
} |
177 |
|
|
178 |
|
public void endElement() |
179 |
|
{ |
180 |
27 |
super.endElement(); |
181 |
|
|
182 |
27 |
setDepth( getDepth() - 1 ); |
183 |
27 |
} |
184 |
|
|
185 |
|
} |