1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
package org.apache.maven.plugin.pmd.model.io.xpp3; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
import java.io.IOException; |
15 | |
import java.io.InputStream; |
16 | |
import java.io.Reader; |
17 | |
import java.text.DateFormat; |
18 | |
import java.util.Locale; |
19 | |
import org.apache.maven.plugin.pmd.model.PmdErrorDetail; |
20 | |
import org.apache.maven.plugin.pmd.model.PmdFile; |
21 | |
import org.apache.maven.plugin.pmd.model.Violation; |
22 | |
import org.codehaus.plexus.util.ReaderFactory; |
23 | |
import org.codehaus.plexus.util.xml.pull.MXParser; |
24 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParser; |
25 | |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
@SuppressWarnings( "all" ) |
33 | 3 | public class PmdXpp3Reader |
34 | |
{ |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 3 | private boolean addDefaultEntities = true; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed ) |
68 | |
throws XmlPullParserException |
69 | |
{ |
70 | 0 | if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) ) |
71 | |
{ |
72 | 0 | return false; |
73 | |
} |
74 | 0 | if ( !parsed.add( tagName ) ) |
75 | |
{ |
76 | 0 | throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null ); |
77 | |
} |
78 | 0 | return true; |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict ) |
92 | |
throws XmlPullParserException, IOException |
93 | |
{ |
94 | |
|
95 | 108 | if ( strict ) |
96 | |
{ |
97 | 0 | throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null ); |
98 | |
} |
99 | 108 | } |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
private void checkUnknownElement( XmlPullParser parser, boolean strict ) |
110 | |
throws XmlPullParserException, IOException |
111 | |
{ |
112 | 0 | if ( strict ) |
113 | |
{ |
114 | 0 | throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null ); |
115 | |
} |
116 | |
|
117 | 0 | for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; ) |
118 | |
{ |
119 | 0 | int eventType = parser.next(); |
120 | 0 | if ( eventType == XmlPullParser.START_TAG ) |
121 | |
{ |
122 | 0 | unrecognizedTagCount++; |
123 | |
} |
124 | 0 | else if ( eventType == XmlPullParser.END_TAG ) |
125 | |
{ |
126 | 0 | unrecognizedTagCount--; |
127 | |
} |
128 | 0 | } |
129 | 0 | } |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public boolean getAddDefaultEntities() |
137 | |
{ |
138 | 0 | return addDefaultEntities; |
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
private boolean getBooleanValue( String s, String attribute, XmlPullParser parser ) |
151 | |
throws XmlPullParserException |
152 | |
{ |
153 | 0 | return getBooleanValue( s, attribute, parser, null ); |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue ) |
167 | |
throws XmlPullParserException |
168 | |
{ |
169 | 0 | if ( s != null && s.length() != 0 ) |
170 | |
{ |
171 | 0 | return Boolean.valueOf( s ).booleanValue(); |
172 | |
} |
173 | 0 | if ( defaultValue != null ) |
174 | |
{ |
175 | 0 | return Boolean.valueOf( defaultValue ).booleanValue(); |
176 | |
} |
177 | 0 | return false; |
178 | |
} |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict ) |
191 | |
throws XmlPullParserException |
192 | |
{ |
193 | 0 | if ( s != null ) |
194 | |
{ |
195 | |
try |
196 | |
{ |
197 | 0 | return Byte.valueOf( s ).byteValue(); |
198 | |
} |
199 | 0 | catch ( NumberFormatException nfe ) |
200 | |
{ |
201 | 0 | if ( strict ) |
202 | |
{ |
203 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe ); |
204 | |
} |
205 | |
} |
206 | |
} |
207 | 0 | return 0; |
208 | |
} |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
private char getCharacterValue( String s, String attribute, XmlPullParser parser ) |
220 | |
throws XmlPullParserException |
221 | |
{ |
222 | 0 | if ( s != null ) |
223 | |
{ |
224 | 0 | return s.charAt( 0 ); |
225 | |
} |
226 | 0 | return 0; |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser ) |
239 | |
throws XmlPullParserException |
240 | |
{ |
241 | 0 | return getDateValue( s, attribute, null, parser ); |
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser ) |
255 | |
throws XmlPullParserException |
256 | |
{ |
257 | 0 | if ( s != null ) |
258 | |
{ |
259 | 0 | String effectiveDateFormat = dateFormat; |
260 | 0 | if ( dateFormat == null ) |
261 | |
{ |
262 | 0 | effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"; |
263 | |
} |
264 | 0 | if ( "long".equals( effectiveDateFormat ) ) |
265 | |
{ |
266 | |
try |
267 | |
{ |
268 | 0 | return new java.util.Date( Long.parseLong( s ) ); |
269 | |
} |
270 | 0 | catch ( NumberFormatException e ) |
271 | |
{ |
272 | 0 | throw new XmlPullParserException( e.getMessage(), parser, e ); |
273 | |
} |
274 | |
} |
275 | |
else |
276 | |
{ |
277 | |
try |
278 | |
{ |
279 | 0 | DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, Locale.US ); |
280 | 0 | return dateParser.parse( s ); |
281 | |
} |
282 | 0 | catch ( java.text.ParseException e ) |
283 | |
{ |
284 | 0 | throw new XmlPullParserException( e.getMessage(), parser, e ); |
285 | |
} |
286 | |
} |
287 | |
} |
288 | 0 | return null; |
289 | |
} |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict ) |
302 | |
throws XmlPullParserException |
303 | |
{ |
304 | 0 | if ( s != null ) |
305 | |
{ |
306 | |
try |
307 | |
{ |
308 | 0 | return Double.valueOf( s ).doubleValue(); |
309 | |
} |
310 | 0 | catch ( NumberFormatException nfe ) |
311 | |
{ |
312 | 0 | if ( strict ) |
313 | |
{ |
314 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); |
315 | |
} |
316 | |
} |
317 | |
} |
318 | 0 | return 0; |
319 | |
} |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict ) |
332 | |
throws XmlPullParserException |
333 | |
{ |
334 | 0 | if ( s != null ) |
335 | |
{ |
336 | |
try |
337 | |
{ |
338 | 0 | return Float.valueOf( s ).floatValue(); |
339 | |
} |
340 | 0 | catch ( NumberFormatException nfe ) |
341 | |
{ |
342 | 0 | if ( strict ) |
343 | |
{ |
344 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); |
345 | |
} |
346 | |
} |
347 | |
} |
348 | 0 | return 0; |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict ) |
362 | |
throws XmlPullParserException |
363 | |
{ |
364 | 36 | if ( s != null ) |
365 | |
{ |
366 | |
try |
367 | |
{ |
368 | 36 | return Integer.valueOf( s ).intValue(); |
369 | |
} |
370 | 0 | catch ( NumberFormatException nfe ) |
371 | |
{ |
372 | 0 | if ( strict ) |
373 | |
{ |
374 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe ); |
375 | |
} |
376 | |
} |
377 | |
} |
378 | 0 | return 0; |
379 | |
} |
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict ) |
392 | |
throws XmlPullParserException |
393 | |
{ |
394 | 0 | if ( s != null ) |
395 | |
{ |
396 | |
try |
397 | |
{ |
398 | 0 | return Long.valueOf( s ).longValue(); |
399 | |
} |
400 | 0 | catch ( NumberFormatException nfe ) |
401 | |
{ |
402 | 0 | if ( strict ) |
403 | |
{ |
404 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe ); |
405 | |
} |
406 | |
} |
407 | |
} |
408 | 0 | return 0; |
409 | |
} |
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict ) |
422 | |
throws XmlPullParserException |
423 | |
{ |
424 | 0 | if ( s == null ) |
425 | |
{ |
426 | 0 | if ( strict ) |
427 | |
{ |
428 | 0 | throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null ); |
429 | |
} |
430 | |
} |
431 | 0 | return s; |
432 | |
} |
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict ) |
445 | |
throws XmlPullParserException |
446 | |
{ |
447 | 0 | if ( s != null ) |
448 | |
{ |
449 | |
try |
450 | |
{ |
451 | 0 | return Short.valueOf( s ).shortValue(); |
452 | |
} |
453 | 0 | catch ( NumberFormatException nfe ) |
454 | |
{ |
455 | 0 | if ( strict ) |
456 | |
{ |
457 | 0 | throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe ); |
458 | |
} |
459 | |
} |
460 | |
} |
461 | 0 | return 0; |
462 | |
} |
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | |
private String getTrimmedValue( String s ) |
471 | |
{ |
472 | 114 | if ( s != null ) |
473 | |
{ |
474 | 114 | s = s.trim(); |
475 | |
} |
476 | 114 | return s; |
477 | |
} |
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
|
483 | |
|
484 | |
|
485 | |
private void initParser( XmlPullParser parser ) |
486 | |
throws XmlPullParserException |
487 | |
{ |
488 | 3 | if ( addDefaultEntities ) |
489 | |
{ |
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | 3 | parser.defineEntityReplacementText( "nbsp", "\u00a0" ); |
495 | 3 | parser.defineEntityReplacementText( "iexcl", "\u00a1" ); |
496 | 3 | parser.defineEntityReplacementText( "cent", "\u00a2" ); |
497 | 3 | parser.defineEntityReplacementText( "pound", "\u00a3" ); |
498 | 3 | parser.defineEntityReplacementText( "curren", "\u00a4" ); |
499 | 3 | parser.defineEntityReplacementText( "yen", "\u00a5" ); |
500 | 3 | parser.defineEntityReplacementText( "brvbar", "\u00a6" ); |
501 | 3 | parser.defineEntityReplacementText( "sect", "\u00a7" ); |
502 | 3 | parser.defineEntityReplacementText( "uml", "\u00a8" ); |
503 | 3 | parser.defineEntityReplacementText( "copy", "\u00a9" ); |
504 | 3 | parser.defineEntityReplacementText( "ordf", "\u00aa" ); |
505 | 3 | parser.defineEntityReplacementText( "laquo", "\u00ab" ); |
506 | 3 | parser.defineEntityReplacementText( "not", "\u00ac" ); |
507 | 3 | parser.defineEntityReplacementText( "shy", "\u00ad" ); |
508 | 3 | parser.defineEntityReplacementText( "reg", "\u00ae" ); |
509 | 3 | parser.defineEntityReplacementText( "macr", "\u00af" ); |
510 | 3 | parser.defineEntityReplacementText( "deg", "\u00b0" ); |
511 | 3 | parser.defineEntityReplacementText( "plusmn", "\u00b1" ); |
512 | 3 | parser.defineEntityReplacementText( "sup2", "\u00b2" ); |
513 | 3 | parser.defineEntityReplacementText( "sup3", "\u00b3" ); |
514 | 3 | parser.defineEntityReplacementText( "acute", "\u00b4" ); |
515 | 3 | parser.defineEntityReplacementText( "micro", "\u00b5" ); |
516 | 3 | parser.defineEntityReplacementText( "para", "\u00b6" ); |
517 | 3 | parser.defineEntityReplacementText( "middot", "\u00b7" ); |
518 | 3 | parser.defineEntityReplacementText( "cedil", "\u00b8" ); |
519 | 3 | parser.defineEntityReplacementText( "sup1", "\u00b9" ); |
520 | 3 | parser.defineEntityReplacementText( "ordm", "\u00ba" ); |
521 | 3 | parser.defineEntityReplacementText( "raquo", "\u00bb" ); |
522 | 3 | parser.defineEntityReplacementText( "frac14", "\u00bc" ); |
523 | 3 | parser.defineEntityReplacementText( "frac12", "\u00bd" ); |
524 | 3 | parser.defineEntityReplacementText( "frac34", "\u00be" ); |
525 | 3 | parser.defineEntityReplacementText( "iquest", "\u00bf" ); |
526 | 3 | parser.defineEntityReplacementText( "Agrave", "\u00c0" ); |
527 | 3 | parser.defineEntityReplacementText( "Aacute", "\u00c1" ); |
528 | 3 | parser.defineEntityReplacementText( "Acirc", "\u00c2" ); |
529 | 3 | parser.defineEntityReplacementText( "Atilde", "\u00c3" ); |
530 | 3 | parser.defineEntityReplacementText( "Auml", "\u00c4" ); |
531 | 3 | parser.defineEntityReplacementText( "Aring", "\u00c5" ); |
532 | 3 | parser.defineEntityReplacementText( "AElig", "\u00c6" ); |
533 | 3 | parser.defineEntityReplacementText( "Ccedil", "\u00c7" ); |
534 | 3 | parser.defineEntityReplacementText( "Egrave", "\u00c8" ); |
535 | 3 | parser.defineEntityReplacementText( "Eacute", "\u00c9" ); |
536 | 3 | parser.defineEntityReplacementText( "Ecirc", "\u00ca" ); |
537 | 3 | parser.defineEntityReplacementText( "Euml", "\u00cb" ); |
538 | 3 | parser.defineEntityReplacementText( "Igrave", "\u00cc" ); |
539 | 3 | parser.defineEntityReplacementText( "Iacute", "\u00cd" ); |
540 | 3 | parser.defineEntityReplacementText( "Icirc", "\u00ce" ); |
541 | 3 | parser.defineEntityReplacementText( "Iuml", "\u00cf" ); |
542 | 3 | parser.defineEntityReplacementText( "ETH", "\u00d0" ); |
543 | 3 | parser.defineEntityReplacementText( "Ntilde", "\u00d1" ); |
544 | 3 | parser.defineEntityReplacementText( "Ograve", "\u00d2" ); |
545 | 3 | parser.defineEntityReplacementText( "Oacute", "\u00d3" ); |
546 | 3 | parser.defineEntityReplacementText( "Ocirc", "\u00d4" ); |
547 | 3 | parser.defineEntityReplacementText( "Otilde", "\u00d5" ); |
548 | 3 | parser.defineEntityReplacementText( "Ouml", "\u00d6" ); |
549 | 3 | parser.defineEntityReplacementText( "times", "\u00d7" ); |
550 | 3 | parser.defineEntityReplacementText( "Oslash", "\u00d8" ); |
551 | 3 | parser.defineEntityReplacementText( "Ugrave", "\u00d9" ); |
552 | 3 | parser.defineEntityReplacementText( "Uacute", "\u00da" ); |
553 | 3 | parser.defineEntityReplacementText( "Ucirc", "\u00db" ); |
554 | 3 | parser.defineEntityReplacementText( "Uuml", "\u00dc" ); |
555 | 3 | parser.defineEntityReplacementText( "Yacute", "\u00dd" ); |
556 | 3 | parser.defineEntityReplacementText( "THORN", "\u00de" ); |
557 | 3 | parser.defineEntityReplacementText( "szlig", "\u00df" ); |
558 | 3 | parser.defineEntityReplacementText( "agrave", "\u00e0" ); |
559 | 3 | parser.defineEntityReplacementText( "aacute", "\u00e1" ); |
560 | 3 | parser.defineEntityReplacementText( "acirc", "\u00e2" ); |
561 | 3 | parser.defineEntityReplacementText( "atilde", "\u00e3" ); |
562 | 3 | parser.defineEntityReplacementText( "auml", "\u00e4" ); |
563 | 3 | parser.defineEntityReplacementText( "aring", "\u00e5" ); |
564 | 3 | parser.defineEntityReplacementText( "aelig", "\u00e6" ); |
565 | 3 | parser.defineEntityReplacementText( "ccedil", "\u00e7" ); |
566 | 3 | parser.defineEntityReplacementText( "egrave", "\u00e8" ); |
567 | 3 | parser.defineEntityReplacementText( "eacute", "\u00e9" ); |
568 | 3 | parser.defineEntityReplacementText( "ecirc", "\u00ea" ); |
569 | 3 | parser.defineEntityReplacementText( "euml", "\u00eb" ); |
570 | 3 | parser.defineEntityReplacementText( "igrave", "\u00ec" ); |
571 | 3 | parser.defineEntityReplacementText( "iacute", "\u00ed" ); |
572 | 3 | parser.defineEntityReplacementText( "icirc", "\u00ee" ); |
573 | 3 | parser.defineEntityReplacementText( "iuml", "\u00ef" ); |
574 | 3 | parser.defineEntityReplacementText( "eth", "\u00f0" ); |
575 | 3 | parser.defineEntityReplacementText( "ntilde", "\u00f1" ); |
576 | 3 | parser.defineEntityReplacementText( "ograve", "\u00f2" ); |
577 | 3 | parser.defineEntityReplacementText( "oacute", "\u00f3" ); |
578 | 3 | parser.defineEntityReplacementText( "ocirc", "\u00f4" ); |
579 | 3 | parser.defineEntityReplacementText( "otilde", "\u00f5" ); |
580 | 3 | parser.defineEntityReplacementText( "ouml", "\u00f6" ); |
581 | 3 | parser.defineEntityReplacementText( "divide", "\u00f7" ); |
582 | 3 | parser.defineEntityReplacementText( "oslash", "\u00f8" ); |
583 | 3 | parser.defineEntityReplacementText( "ugrave", "\u00f9" ); |
584 | 3 | parser.defineEntityReplacementText( "uacute", "\u00fa" ); |
585 | 3 | parser.defineEntityReplacementText( "ucirc", "\u00fb" ); |
586 | 3 | parser.defineEntityReplacementText( "uuml", "\u00fc" ); |
587 | 3 | parser.defineEntityReplacementText( "yacute", "\u00fd" ); |
588 | 3 | parser.defineEntityReplacementText( "thorn", "\u00fe" ); |
589 | 3 | parser.defineEntityReplacementText( "yuml", "\u00ff" ); |
590 | |
|
591 | |
|
592 | |
|
593 | |
|
594 | |
|
595 | 3 | parser.defineEntityReplacementText( "OElig", "\u0152" ); |
596 | 3 | parser.defineEntityReplacementText( "oelig", "\u0153" ); |
597 | 3 | parser.defineEntityReplacementText( "Scaron", "\u0160" ); |
598 | 3 | parser.defineEntityReplacementText( "scaron", "\u0161" ); |
599 | 3 | parser.defineEntityReplacementText( "Yuml", "\u0178" ); |
600 | 3 | parser.defineEntityReplacementText( "circ", "\u02c6" ); |
601 | 3 | parser.defineEntityReplacementText( "tilde", "\u02dc" ); |
602 | 3 | parser.defineEntityReplacementText( "ensp", "\u2002" ); |
603 | 3 | parser.defineEntityReplacementText( "emsp", "\u2003" ); |
604 | 3 | parser.defineEntityReplacementText( "thinsp", "\u2009" ); |
605 | 3 | parser.defineEntityReplacementText( "zwnj", "\u200c" ); |
606 | 3 | parser.defineEntityReplacementText( "zwj", "\u200d" ); |
607 | 3 | parser.defineEntityReplacementText( "lrm", "\u200e" ); |
608 | 3 | parser.defineEntityReplacementText( "rlm", "\u200f" ); |
609 | 3 | parser.defineEntityReplacementText( "ndash", "\u2013" ); |
610 | 3 | parser.defineEntityReplacementText( "mdash", "\u2014" ); |
611 | 3 | parser.defineEntityReplacementText( "lsquo", "\u2018" ); |
612 | 3 | parser.defineEntityReplacementText( "rsquo", "\u2019" ); |
613 | 3 | parser.defineEntityReplacementText( "sbquo", "\u201a" ); |
614 | 3 | parser.defineEntityReplacementText( "ldquo", "\u201c" ); |
615 | 3 | parser.defineEntityReplacementText( "rdquo", "\u201d" ); |
616 | 3 | parser.defineEntityReplacementText( "bdquo", "\u201e" ); |
617 | 3 | parser.defineEntityReplacementText( "dagger", "\u2020" ); |
618 | 3 | parser.defineEntityReplacementText( "Dagger", "\u2021" ); |
619 | 3 | parser.defineEntityReplacementText( "permil", "\u2030" ); |
620 | 3 | parser.defineEntityReplacementText( "lsaquo", "\u2039" ); |
621 | 3 | parser.defineEntityReplacementText( "rsaquo", "\u203a" ); |
622 | 3 | parser.defineEntityReplacementText( "euro", "\u20ac" ); |
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
|
628 | 3 | parser.defineEntityReplacementText( "fnof", "\u0192" ); |
629 | 3 | parser.defineEntityReplacementText( "Alpha", "\u0391" ); |
630 | 3 | parser.defineEntityReplacementText( "Beta", "\u0392" ); |
631 | 3 | parser.defineEntityReplacementText( "Gamma", "\u0393" ); |
632 | 3 | parser.defineEntityReplacementText( "Delta", "\u0394" ); |
633 | 3 | parser.defineEntityReplacementText( "Epsilon", "\u0395" ); |
634 | 3 | parser.defineEntityReplacementText( "Zeta", "\u0396" ); |
635 | 3 | parser.defineEntityReplacementText( "Eta", "\u0397" ); |
636 | 3 | parser.defineEntityReplacementText( "Theta", "\u0398" ); |
637 | 3 | parser.defineEntityReplacementText( "Iota", "\u0399" ); |
638 | 3 | parser.defineEntityReplacementText( "Kappa", "\u039a" ); |
639 | 3 | parser.defineEntityReplacementText( "Lambda", "\u039b" ); |
640 | 3 | parser.defineEntityReplacementText( "Mu", "\u039c" ); |
641 | 3 | parser.defineEntityReplacementText( "Nu", "\u039d" ); |
642 | 3 | parser.defineEntityReplacementText( "Xi", "\u039e" ); |
643 | 3 | parser.defineEntityReplacementText( "Omicron", "\u039f" ); |
644 | 3 | parser.defineEntityReplacementText( "Pi", "\u03a0" ); |
645 | 3 | parser.defineEntityReplacementText( "Rho", "\u03a1" ); |
646 | 3 | parser.defineEntityReplacementText( "Sigma", "\u03a3" ); |
647 | 3 | parser.defineEntityReplacementText( "Tau", "\u03a4" ); |
648 | 3 | parser.defineEntityReplacementText( "Upsilon", "\u03a5" ); |
649 | 3 | parser.defineEntityReplacementText( "Phi", "\u03a6" ); |
650 | 3 | parser.defineEntityReplacementText( "Chi", "\u03a7" ); |
651 | 3 | parser.defineEntityReplacementText( "Psi", "\u03a8" ); |
652 | 3 | parser.defineEntityReplacementText( "Omega", "\u03a9" ); |
653 | 3 | parser.defineEntityReplacementText( "alpha", "\u03b1" ); |
654 | 3 | parser.defineEntityReplacementText( "beta", "\u03b2" ); |
655 | 3 | parser.defineEntityReplacementText( "gamma", "\u03b3" ); |
656 | 3 | parser.defineEntityReplacementText( "delta", "\u03b4" ); |
657 | 3 | parser.defineEntityReplacementText( "epsilon", "\u03b5" ); |
658 | 3 | parser.defineEntityReplacementText( "zeta", "\u03b6" ); |
659 | 3 | parser.defineEntityReplacementText( "eta", "\u03b7" ); |
660 | 3 | parser.defineEntityReplacementText( "theta", "\u03b8" ); |
661 | 3 | parser.defineEntityReplacementText( "iota", "\u03b9" ); |
662 | 3 | parser.defineEntityReplacementText( "kappa", "\u03ba" ); |
663 | 3 | parser.defineEntityReplacementText( "lambda", "\u03bb" ); |
664 | 3 | parser.defineEntityReplacementText( "mu", "\u03bc" ); |
665 | 3 | parser.defineEntityReplacementText( "nu", "\u03bd" ); |
666 | 3 | parser.defineEntityReplacementText( "xi", "\u03be" ); |
667 | 3 | parser.defineEntityReplacementText( "omicron", "\u03bf" ); |
668 | 3 | parser.defineEntityReplacementText( "pi", "\u03c0" ); |
669 | 3 | parser.defineEntityReplacementText( "rho", "\u03c1" ); |
670 | 3 | parser.defineEntityReplacementText( "sigmaf", "\u03c2" ); |
671 | 3 | parser.defineEntityReplacementText( "sigma", "\u03c3" ); |
672 | 3 | parser.defineEntityReplacementText( "tau", "\u03c4" ); |
673 | 3 | parser.defineEntityReplacementText( "upsilon", "\u03c5" ); |
674 | 3 | parser.defineEntityReplacementText( "phi", "\u03c6" ); |
675 | 3 | parser.defineEntityReplacementText( "chi", "\u03c7" ); |
676 | 3 | parser.defineEntityReplacementText( "psi", "\u03c8" ); |
677 | 3 | parser.defineEntityReplacementText( "omega", "\u03c9" ); |
678 | 3 | parser.defineEntityReplacementText( "thetasym", "\u03d1" ); |
679 | 3 | parser.defineEntityReplacementText( "upsih", "\u03d2" ); |
680 | 3 | parser.defineEntityReplacementText( "piv", "\u03d6" ); |
681 | 3 | parser.defineEntityReplacementText( "bull", "\u2022" ); |
682 | 3 | parser.defineEntityReplacementText( "hellip", "\u2026" ); |
683 | 3 | parser.defineEntityReplacementText( "prime", "\u2032" ); |
684 | 3 | parser.defineEntityReplacementText( "Prime", "\u2033" ); |
685 | 3 | parser.defineEntityReplacementText( "oline", "\u203e" ); |
686 | 3 | parser.defineEntityReplacementText( "frasl", "\u2044" ); |
687 | 3 | parser.defineEntityReplacementText( "weierp", "\u2118" ); |
688 | 3 | parser.defineEntityReplacementText( "image", "\u2111" ); |
689 | 3 | parser.defineEntityReplacementText( "real", "\u211c" ); |
690 | 3 | parser.defineEntityReplacementText( "trade", "\u2122" ); |
691 | 3 | parser.defineEntityReplacementText( "alefsym", "\u2135" ); |
692 | 3 | parser.defineEntityReplacementText( "larr", "\u2190" ); |
693 | 3 | parser.defineEntityReplacementText( "uarr", "\u2191" ); |
694 | 3 | parser.defineEntityReplacementText( "rarr", "\u2192" ); |
695 | 3 | parser.defineEntityReplacementText( "darr", "\u2193" ); |
696 | 3 | parser.defineEntityReplacementText( "harr", "\u2194" ); |
697 | 3 | parser.defineEntityReplacementText( "crarr", "\u21b5" ); |
698 | 3 | parser.defineEntityReplacementText( "lArr", "\u21d0" ); |
699 | 3 | parser.defineEntityReplacementText( "uArr", "\u21d1" ); |
700 | 3 | parser.defineEntityReplacementText( "rArr", "\u21d2" ); |
701 | 3 | parser.defineEntityReplacementText( "dArr", "\u21d3" ); |
702 | 3 | parser.defineEntityReplacementText( "hArr", "\u21d4" ); |
703 | 3 | parser.defineEntityReplacementText( "forall", "\u2200" ); |
704 | 3 | parser.defineEntityReplacementText( "part", "\u2202" ); |
705 | 3 | parser.defineEntityReplacementText( "exist", "\u2203" ); |
706 | 3 | parser.defineEntityReplacementText( "empty", "\u2205" ); |
707 | 3 | parser.defineEntityReplacementText( "nabla", "\u2207" ); |
708 | 3 | parser.defineEntityReplacementText( "isin", "\u2208" ); |
709 | 3 | parser.defineEntityReplacementText( "notin", "\u2209" ); |
710 | 3 | parser.defineEntityReplacementText( "ni", "\u220b" ); |
711 | 3 | parser.defineEntityReplacementText( "prod", "\u220f" ); |
712 | 3 | parser.defineEntityReplacementText( "sum", "\u2211" ); |
713 | 3 | parser.defineEntityReplacementText( "minus", "\u2212" ); |
714 | 3 | parser.defineEntityReplacementText( "lowast", "\u2217" ); |
715 | 3 | parser.defineEntityReplacementText( "radic", "\u221a" ); |
716 | 3 | parser.defineEntityReplacementText( "prop", "\u221d" ); |
717 | 3 | parser.defineEntityReplacementText( "infin", "\u221e" ); |
718 | 3 | parser.defineEntityReplacementText( "ang", "\u2220" ); |
719 | 3 | parser.defineEntityReplacementText( "and", "\u2227" ); |
720 | 3 | parser.defineEntityReplacementText( "or", "\u2228" ); |
721 | 3 | parser.defineEntityReplacementText( "cap", "\u2229" ); |
722 | 3 | parser.defineEntityReplacementText( "cup", "\u222a" ); |
723 | 3 | parser.defineEntityReplacementText( "int", "\u222b" ); |
724 | 3 | parser.defineEntityReplacementText( "there4", "\u2234" ); |
725 | 3 | parser.defineEntityReplacementText( "sim", "\u223c" ); |
726 | 3 | parser.defineEntityReplacementText( "cong", "\u2245" ); |
727 | 3 | parser.defineEntityReplacementText( "asymp", "\u2248" ); |
728 | 3 | parser.defineEntityReplacementText( "ne", "\u2260" ); |
729 | 3 | parser.defineEntityReplacementText( "equiv", "\u2261" ); |
730 | 3 | parser.defineEntityReplacementText( "le", "\u2264" ); |
731 | 3 | parser.defineEntityReplacementText( "ge", "\u2265" ); |
732 | 3 | parser.defineEntityReplacementText( "sub", "\u2282" ); |
733 | 3 | parser.defineEntityReplacementText( "sup", "\u2283" ); |
734 | 3 | parser.defineEntityReplacementText( "nsub", "\u2284" ); |
735 | 3 | parser.defineEntityReplacementText( "sube", "\u2286" ); |
736 | 3 | parser.defineEntityReplacementText( "supe", "\u2287" ); |
737 | 3 | parser.defineEntityReplacementText( "oplus", "\u2295" ); |
738 | 3 | parser.defineEntityReplacementText( "otimes", "\u2297" ); |
739 | 3 | parser.defineEntityReplacementText( "perp", "\u22a5" ); |
740 | 3 | parser.defineEntityReplacementText( "sdot", "\u22c5" ); |
741 | 3 | parser.defineEntityReplacementText( "lceil", "\u2308" ); |
742 | 3 | parser.defineEntityReplacementText( "rceil", "\u2309" ); |
743 | 3 | parser.defineEntityReplacementText( "lfloor", "\u230a" ); |
744 | 3 | parser.defineEntityReplacementText( "rfloor", "\u230b" ); |
745 | 3 | parser.defineEntityReplacementText( "lang", "\u2329" ); |
746 | 3 | parser.defineEntityReplacementText( "rang", "\u232a" ); |
747 | 3 | parser.defineEntityReplacementText( "loz", "\u25ca" ); |
748 | 3 | parser.defineEntityReplacementText( "spades", "\u2660" ); |
749 | 3 | parser.defineEntityReplacementText( "clubs", "\u2663" ); |
750 | 3 | parser.defineEntityReplacementText( "hearts", "\u2665" ); |
751 | 3 | parser.defineEntityReplacementText( "diams", "\u2666" ); |
752 | |
|
753 | |
} |
754 | 3 | } |
755 | |
|
756 | |
|
757 | |
|
758 | |
|
759 | |
|
760 | |
|
761 | |
|
762 | |
|
763 | |
|
764 | |
private int nextTag( XmlPullParser parser ) |
765 | |
throws IOException, XmlPullParserException |
766 | |
{ |
767 | 39 | int eventType = parser.next(); |
768 | 39 | if ( eventType == XmlPullParser.TEXT ) |
769 | |
{ |
770 | 39 | eventType = parser.next(); |
771 | |
} |
772 | 39 | if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG ) |
773 | |
{ |
774 | 0 | throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null ); |
775 | |
} |
776 | 39 | return eventType; |
777 | |
} |
778 | |
|
779 | |
|
780 | |
|
781 | |
|
782 | |
|
783 | |
|
784 | |
|
785 | |
|
786 | |
|
787 | |
|
788 | |
private PmdErrorDetail parsePmdErrorDetail( XmlPullParser parser, boolean strict ) |
789 | |
throws IOException, XmlPullParserException |
790 | |
{ |
791 | 3 | String tagName = parser.getName(); |
792 | 3 | PmdErrorDetail pmdErrorDetail = new PmdErrorDetail(); |
793 | 9 | for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) |
794 | |
{ |
795 | 6 | String name = parser.getAttributeName( i ); |
796 | 6 | String value = parser.getAttributeValue( i ); |
797 | |
|
798 | 6 | if ( name.indexOf( ':' ) >= 0 ) |
799 | |
{ |
800 | |
|
801 | |
} |
802 | 6 | else if ( "xmlns".equals( name ) ) |
803 | |
{ |
804 | |
|
805 | |
} |
806 | |
else |
807 | |
{ |
808 | 6 | checkUnknownAttribute( parser, name, tagName, strict ); |
809 | |
} |
810 | |
} |
811 | 3 | java.util.Set parsed = new java.util.HashSet(); |
812 | 12 | while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) |
813 | |
{ |
814 | 9 | if ( "file".equals( parser.getName() ) ) |
815 | |
{ |
816 | 9 | java.util.List files = pmdErrorDetail.getFiles(); |
817 | 9 | if ( files == null ) |
818 | |
{ |
819 | 0 | files = new java.util.ArrayList(); |
820 | 0 | pmdErrorDetail.setFiles( files ); |
821 | |
} |
822 | 9 | files.add( parsePmdFile( parser, strict ) ); |
823 | 9 | } |
824 | |
else |
825 | |
{ |
826 | 0 | checkUnknownElement( parser, strict ); |
827 | |
} |
828 | |
} |
829 | 3 | return pmdErrorDetail; |
830 | |
} |
831 | |
|
832 | |
|
833 | |
|
834 | |
|
835 | |
|
836 | |
|
837 | |
|
838 | |
|
839 | |
|
840 | |
|
841 | |
private PmdFile parsePmdFile( XmlPullParser parser, boolean strict ) |
842 | |
throws IOException, XmlPullParserException |
843 | |
{ |
844 | 9 | String tagName = parser.getName(); |
845 | 9 | PmdFile pmdFile = new PmdFile(); |
846 | 18 | for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) |
847 | |
{ |
848 | 9 | String name = parser.getAttributeName( i ); |
849 | 9 | String value = parser.getAttributeValue( i ); |
850 | |
|
851 | 9 | if ( name.indexOf( ':' ) >= 0 ) |
852 | |
{ |
853 | |
|
854 | |
} |
855 | 9 | else if ( "name".equals( name ) ) |
856 | |
{ |
857 | 9 | pmdFile.setName( getTrimmedValue( value ) ); |
858 | |
} |
859 | |
else |
860 | |
{ |
861 | 0 | checkUnknownAttribute( parser, name, tagName, strict ); |
862 | |
} |
863 | |
} |
864 | 9 | java.util.Set parsed = new java.util.HashSet(); |
865 | 27 | while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) |
866 | |
{ |
867 | 18 | if ( "violation".equals( parser.getName() ) ) |
868 | |
{ |
869 | 18 | java.util.List violations = pmdFile.getViolations(); |
870 | 18 | if ( violations == null ) |
871 | |
{ |
872 | 0 | violations = new java.util.ArrayList(); |
873 | 0 | pmdFile.setViolations( violations ); |
874 | |
} |
875 | 18 | violations.add( parseViolation( parser, strict ) ); |
876 | 18 | } |
877 | |
else |
878 | |
{ |
879 | 0 | checkUnknownElement( parser, strict ); |
880 | |
} |
881 | |
} |
882 | 9 | return pmdFile; |
883 | |
} |
884 | |
|
885 | |
|
886 | |
|
887 | |
|
888 | |
|
889 | |
|
890 | |
|
891 | |
|
892 | |
|
893 | |
|
894 | |
private Violation parseViolation( XmlPullParser parser, boolean strict ) |
895 | |
throws IOException, XmlPullParserException |
896 | |
{ |
897 | 18 | String tagName = parser.getName(); |
898 | 18 | Violation violation = new Violation(); |
899 | 207 | for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) |
900 | |
{ |
901 | 189 | String name = parser.getAttributeName( i ); |
902 | 189 | String value = parser.getAttributeValue( i ); |
903 | |
|
904 | 189 | if ( name.indexOf( ':' ) >= 0 ) |
905 | |
{ |
906 | |
|
907 | |
} |
908 | 189 | else if ( "beginline".equals( name ) ) |
909 | |
{ |
910 | 18 | violation.setBeginline( getIntegerValue( getTrimmedValue( value ), "beginline", parser, strict ) ); |
911 | |
} |
912 | 171 | else if ( "class".equals( name ) ) |
913 | |
{ |
914 | 15 | violation.setViolationClass( getTrimmedValue( value ) ); |
915 | |
} |
916 | 156 | else if ( "package".equals( name ) ) |
917 | |
{ |
918 | 18 | violation.setViolationPackage( getTrimmedValue( value ) ); |
919 | |
} |
920 | 138 | else if ( "rule".equals( name ) ) |
921 | |
{ |
922 | 18 | violation.setRule( getTrimmedValue( value ) ); |
923 | |
} |
924 | 120 | else if ( "priority".equals( name ) ) |
925 | |
{ |
926 | 18 | violation.setPriority( getIntegerValue( getTrimmedValue( value ), "priority", parser, strict ) ); |
927 | |
} |
928 | |
else |
929 | |
{ |
930 | 102 | checkUnknownAttribute( parser, name, tagName, strict ); |
931 | |
} |
932 | |
} |
933 | 18 | violation.setText( getTrimmedValue( parser.nextText() ) ); |
934 | 18 | return violation; |
935 | |
} |
936 | |
|
937 | |
|
938 | |
|
939 | |
|
940 | |
|
941 | |
|
942 | |
|
943 | |
|
944 | |
|
945 | |
|
946 | |
public PmdErrorDetail read( Reader reader, boolean strict ) |
947 | |
throws IOException, XmlPullParserException |
948 | |
{ |
949 | 3 | XmlPullParser parser = new MXParser(); |
950 | |
|
951 | 3 | parser.setInput( reader ); |
952 | |
|
953 | 3 | initParser( parser ); |
954 | |
|
955 | 3 | return read( parser, strict ); |
956 | |
} |
957 | |
|
958 | |
|
959 | |
|
960 | |
|
961 | |
|
962 | |
|
963 | |
|
964 | |
|
965 | |
|
966 | |
public PmdErrorDetail read( Reader reader ) |
967 | |
throws IOException, XmlPullParserException |
968 | |
{ |
969 | 0 | return read( reader, true ); |
970 | |
} |
971 | |
|
972 | |
|
973 | |
|
974 | |
|
975 | |
|
976 | |
|
977 | |
|
978 | |
|
979 | |
|
980 | |
|
981 | |
public PmdErrorDetail read( InputStream in, boolean strict ) |
982 | |
throws IOException, XmlPullParserException |
983 | |
{ |
984 | 0 | return read( ReaderFactory.newXmlReader( in ), strict ); |
985 | |
} |
986 | |
|
987 | |
|
988 | |
|
989 | |
|
990 | |
|
991 | |
|
992 | |
|
993 | |
|
994 | |
|
995 | |
public PmdErrorDetail read( InputStream in ) |
996 | |
throws IOException, XmlPullParserException |
997 | |
{ |
998 | 0 | return read( ReaderFactory.newXmlReader( in ) ); |
999 | |
} |
1000 | |
|
1001 | |
|
1002 | |
|
1003 | |
|
1004 | |
|
1005 | |
|
1006 | |
|
1007 | |
|
1008 | |
|
1009 | |
|
1010 | |
private PmdErrorDetail read( XmlPullParser parser, boolean strict ) |
1011 | |
throws IOException, XmlPullParserException |
1012 | |
{ |
1013 | 3 | int eventType = parser.getEventType(); |
1014 | 6 | while ( eventType != XmlPullParser.END_DOCUMENT ) |
1015 | |
{ |
1016 | 6 | if ( eventType == XmlPullParser.START_TAG ) |
1017 | |
{ |
1018 | 3 | if ( strict && ! "pmd".equals( parser.getName() ) ) |
1019 | |
{ |
1020 | 0 | throw new XmlPullParserException( "Expected root element 'pmd' but found '" + parser.getName() + "'", parser, null ); |
1021 | |
} |
1022 | 3 | PmdErrorDetail pmdErrorDetail = parsePmdErrorDetail( parser, strict ); |
1023 | 3 | pmdErrorDetail.setModelEncoding( parser.getInputEncoding() ); |
1024 | 3 | return pmdErrorDetail; |
1025 | |
} |
1026 | 3 | eventType = parser.next(); |
1027 | |
} |
1028 | 0 | throw new XmlPullParserException( "Expected root element 'pmd' but found no element at all: invalid XML document", parser, null ); |
1029 | |
} |
1030 | |
|
1031 | |
|
1032 | |
|
1033 | |
|
1034 | |
|
1035 | |
|
1036 | |
public void setAddDefaultEntities( boolean addDefaultEntities ) |
1037 | |
{ |
1038 | 0 | this.addDefaultEntities = addDefaultEntities; |
1039 | 0 | } |
1040 | |
|
1041 | |
} |