1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.xml.internal.output; |
21 |
|
|
22 |
|
import java.io.OutputStream; |
23 |
|
|
24 |
|
import javax.xml.stream.XMLOutputFactory; |
25 |
|
import javax.xml.stream.XMLStreamException; |
26 |
|
import javax.xml.stream.XMLStreamWriter; |
27 |
|
|
28 |
|
import org.xwiki.filter.FilterException; |
29 |
|
import org.xwiki.filter.xml.output.XMLOutputProperties; |
30 |
|
|
31 |
|
import javanet.staxutils.IndentingXMLStreamWriter; |
32 |
|
|
33 |
|
|
34 |
|
@version |
35 |
|
@since |
36 |
|
|
|
|
| 56.1% |
Uncovered Elements: 36 (82) |
Complexity: 34 |
Complexity Density: 0.61 |
|
37 |
|
public class FilterStreamXMLStreamWriter |
38 |
|
{ |
39 |
|
private final XMLStreamWriter writer; |
40 |
|
|
41 |
|
private final boolean printNullValue; |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
43 |
0 |
public FilterStreamXMLStreamWriter(XMLStreamWriter writer, boolean printNullValue)... |
44 |
|
{ |
45 |
0 |
this.writer = writer; |
46 |
0 |
this.printNullValue = printNullValue; |
47 |
|
} |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
49 |
0 |
public FilterStreamXMLStreamWriter(OutputStream outputStream, String encoding, boolean format,... |
50 |
|
boolean printNullValue) throws FilterException |
51 |
|
{ |
52 |
0 |
try { |
53 |
0 |
XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, encoding); |
54 |
|
|
55 |
0 |
if (format) { |
56 |
0 |
this.writer = new IndentingXMLStreamWriter(streamWriter); |
57 |
|
} else { |
58 |
0 |
this.writer = streamWriter; |
59 |
|
} |
60 |
|
} catch (Exception e) { |
61 |
0 |
throw new FilterException("Failed to create XML writer", e); |
62 |
|
} |
63 |
|
|
64 |
0 |
this.printNullValue = printNullValue; |
65 |
|
} |
66 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
67 |
7604 |
public FilterStreamXMLStreamWriter(XMLOutputProperties properties, boolean printNullValue) throws FilterException... |
68 |
|
{ |
69 |
7604 |
try { |
70 |
7604 |
this.writer = XMLOutputFilterStreamUtils.createXMLStreamWriter(properties); |
71 |
|
} catch (Exception e) { |
72 |
0 |
throw new FilterException("Failed to create XML writer", e); |
73 |
|
} |
74 |
|
|
75 |
7604 |
this.printNullValue = printNullValue; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
29763 |
public XMLStreamWriter getWriter()... |
79 |
|
{ |
80 |
29763 |
return this.writer; |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@throws |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
90 |
0 |
public void writeStartDocument() throws FilterException... |
91 |
|
{ |
92 |
0 |
try { |
93 |
0 |
this.writer.writeStartDocument(); |
94 |
|
} catch (XMLStreamException e) { |
95 |
0 |
throw new FilterException("Failed to write start document", e); |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
@param |
104 |
|
@throws |
105 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
106 |
6343 |
public void writeStartDocument(String encoding, String version) throws FilterException... |
107 |
|
{ |
108 |
6343 |
try { |
109 |
6343 |
this.writer.writeStartDocument(encoding, version); |
110 |
|
} catch (XMLStreamException e) { |
111 |
0 |
throw new FilterException("Failed to write start document", e); |
112 |
|
} |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
@throws |
119 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
120 |
6343 |
public void writeEndDocument() throws FilterException... |
121 |
|
{ |
122 |
6343 |
try { |
123 |
6343 |
this.writer.writeEndDocument(); |
124 |
|
} catch (XMLStreamException e) { |
125 |
0 |
throw new FilterException("Failed to write end document", e); |
126 |
|
} |
127 |
|
} |
128 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
129 |
122077 |
public void writeEmptyElement(String localName) throws FilterException... |
130 |
|
{ |
131 |
122077 |
try { |
132 |
122077 |
this.writer.writeEmptyElement(localName); |
133 |
|
} catch (XMLStreamException e) { |
134 |
0 |
throw new FilterException(String.format("Failed to write empty element [%s]", localName), e); |
135 |
|
} |
136 |
|
} |
137 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
138 |
898495 |
public void writeElement(String localName, String value) throws FilterException... |
139 |
|
{ |
140 |
898495 |
if (value != null) { |
141 |
898493 |
if (value.isEmpty()) { |
142 |
122075 |
writeEmptyElement(localName); |
143 |
|
} else { |
144 |
776418 |
writeStartElement(localName); |
145 |
776418 |
writeCharacters(value); |
146 |
776418 |
writeEndElement(); |
147 |
|
} |
148 |
2 |
} else if (this.printNullValue) { |
149 |
2 |
writeEmptyElement(localName); |
150 |
|
} |
151 |
|
} |
152 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
153 |
776445 |
public void writeCharacters(String text) throws FilterException... |
154 |
|
{ |
155 |
776445 |
try { |
156 |
776445 |
this.writer.writeCharacters(text); |
157 |
|
} catch (XMLStreamException e) { |
158 |
0 |
throw new FilterException(String.format("Failed to write characters [%s]", text), e); |
159 |
|
} |
160 |
|
} |
161 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
162 |
928925 |
public void writeStartElement(String localName) throws FilterException... |
163 |
|
{ |
164 |
928925 |
try { |
165 |
928925 |
this.writer.writeStartElement(localName); |
166 |
|
} catch (XMLStreamException e) { |
167 |
0 |
throw new FilterException(String.format("Failed to write start element [%s]", localName), e); |
168 |
|
} |
169 |
|
} |
170 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
171 |
928925 |
public void writeEndElement() throws FilterException... |
172 |
|
{ |
173 |
928925 |
try { |
174 |
928925 |
this.writer.writeEndElement(); |
175 |
|
} catch (XMLStreamException e) { |
176 |
0 |
throw new FilterException("Failed to write end element", e); |
177 |
|
} |
178 |
|
} |
179 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
180 |
19029 |
public void writeAttribute(String localName, String value) throws FilterException... |
181 |
|
{ |
182 |
19029 |
if (value != null) { |
183 |
19029 |
try { |
184 |
19029 |
this.writer.writeAttribute(localName, value); |
185 |
|
} catch (XMLStreamException e) { |
186 |
0 |
throw new FilterException( |
187 |
|
String.format("Failed to write attribute [%s] with value [%s]", localName, value), e); |
188 |
|
} |
189 |
|
} |
190 |
|
} |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
192 |
0 |
public void writeCharacters(char[] text, int start, int len) throws FilterException... |
193 |
|
{ |
194 |
0 |
try { |
195 |
0 |
this.writer.writeCharacters(text, start, len); |
196 |
|
} catch (XMLStreamException e) { |
197 |
0 |
throw new FilterException("Failed to write characters", e); |
198 |
|
} |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
@throws |
206 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
207 |
7604 |
public void close() throws FilterException... |
208 |
|
{ |
209 |
7604 |
try { |
210 |
7604 |
this.writer.close(); |
211 |
|
} catch (XMLStreamException e) { |
212 |
0 |
throw new FilterException("Failed to close writer", e); |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
@throws |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
221 |
0 |
public void flush() throws FilterException... |
222 |
|
{ |
223 |
0 |
try { |
224 |
0 |
this.writer.flush(); |
225 |
|
} catch (XMLStreamException e) { |
226 |
0 |
throw new FilterException("Failed to flush writer", e); |
227 |
|
} |
228 |
|
} |
229 |
|
} |