View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 2.1.2,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.plugins.pmd.model.io.xpp3;
7   
8     //---------------------------------/
9    //- Imported classes and packages -/
10  //---------------------------------/
11  
12  import java.io.IOException;
13  import java.io.InputStream;
14  import java.io.Reader;
15  import java.text.DateFormat;
16  import org.apache.maven.plugins.pmd.model.PmdErrorDetail;
17  import org.apache.maven.plugins.pmd.model.PmdFile;
18  import org.apache.maven.plugins.pmd.model.ProcessingError;
19  import org.apache.maven.plugins.pmd.model.SuppressedViolation;
20  import org.apache.maven.plugins.pmd.model.Violation;
21  import org.codehaus.plexus.util.ReaderFactory;
22  import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
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   * Class PmdXpp3Reader.
29   * 
30   * @version $Revision$ $Date$
31   */
32  @SuppressWarnings( "all" )
33  public class PmdXpp3Reader
34  {
35  
36        //--------------------------/
37       //- Class/Member Variables -/
38      //--------------------------/
39  
40      /**
41       * If set the parser will be loaded with all single characters
42       * from the XHTML specification.
43       * The entities used:
44       * <ul>
45       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
46       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
47       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
48       * </ul>
49       */
50      private boolean addDefaultEntities = true;
51  
52      /**
53       * Field contentTransformer.
54       */
55      public final ContentTransformer contentTransformer;
56  
57  
58        //----------------/
59       //- Constructors -/
60      //----------------/
61  
62      public PmdXpp3Reader()
63      {
64          this( new ContentTransformer()
65          {
66              public String transform( String source, String fieldName )
67              {
68                  return source;
69              }
70          } );
71      } //-- org.apache.maven.plugins.pmd.model.io.xpp3.PmdXpp3Reader()
72  
73      public PmdXpp3Reader(ContentTransformer contentTransformer)
74      {
75          this.contentTransformer = contentTransformer;
76      } //-- org.apache.maven.plugins.pmd.model.io.xpp3.PmdXpp3Reader(ContentTransformer)
77  
78  
79        //-----------/
80       //- Methods -/
81      //-----------/
82  
83      /**
84       * Method checkFieldWithDuplicate.
85       * 
86       * @param parser a parser object.
87       * @param parsed a parsed object.
88       * @param alias a alias object.
89       * @param tagName a tagName object.
90       * @throws XmlPullParserException XmlPullParserException if
91       * any.
92       * @return boolean
93       */
94      private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
95          throws XmlPullParserException
96      {
97          if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
98          {
99              return false;
100         }
101         if ( !parsed.add( tagName ) )
102         {
103             throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
104         }
105         return true;
106     } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set )
107 
108     /**
109      * Method checkUnknownAttribute.
110      * 
111      * @param parser a parser object.
112      * @param strict a strict object.
113      * @param tagName a tagName object.
114      * @param attribute a attribute object.
115      * @throws XmlPullParserException XmlPullParserException if
116      * any.
117      * @throws IOException IOException if any.
118      */
119     private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
120         throws XmlPullParserException, IOException
121     {
122         // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
123         if ( strict )
124         {
125             throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
126         }
127     } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
128 
129     /**
130      * Method checkUnknownElement.
131      * 
132      * @param parser a parser object.
133      * @param strict a strict object.
134      * @throws XmlPullParserException XmlPullParserException if
135      * any.
136      * @throws IOException IOException if any.
137      */
138     private void checkUnknownElement( XmlPullParser parser, boolean strict )
139         throws XmlPullParserException, IOException
140     {
141         if ( strict )
142         {
143             throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
144         }
145 
146         for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
147         {
148             int eventType = parser.next();
149             if ( eventType == XmlPullParser.START_TAG )
150             {
151                 unrecognizedTagCount++;
152             }
153             else if ( eventType == XmlPullParser.END_TAG )
154             {
155                 unrecognizedTagCount--;
156             }
157         }
158     } //-- void checkUnknownElement( XmlPullParser, boolean )
159 
160     /**
161      * Returns the state of the "add default entities" flag.
162      * 
163      * @return boolean
164      */
165     public boolean getAddDefaultEntities()
166     {
167         return addDefaultEntities;
168     } //-- boolean getAddDefaultEntities()
169 
170     /**
171      * Method getBooleanValue.
172      * 
173      * @param s a s object.
174      * @param parser a parser object.
175      * @param attribute a attribute object.
176      * @throws XmlPullParserException XmlPullParserException if
177      * any.
178      * @return boolean
179      */
180     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
181         throws XmlPullParserException
182     {
183         return getBooleanValue( s, attribute, parser, null );
184     } //-- boolean getBooleanValue( String, String, XmlPullParser )
185 
186     /**
187      * Method getBooleanValue.
188      * 
189      * @param s a s object.
190      * @param defaultValue a defaultValue object.
191      * @param parser a parser object.
192      * @param attribute a attribute object.
193      * @throws XmlPullParserException XmlPullParserException if
194      * any.
195      * @return boolean
196      */
197     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
198         throws XmlPullParserException
199     {
200         if ( s != null && s.length() != 0 )
201         {
202             return Boolean.valueOf( s ).booleanValue();
203         }
204         if ( defaultValue != null )
205         {
206             return Boolean.valueOf( defaultValue ).booleanValue();
207         }
208         return false;
209     } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
210 
211     /**
212      * Method getByteValue.
213      * 
214      * @param s a s object.
215      * @param strict a strict object.
216      * @param parser a parser object.
217      * @param attribute a attribute object.
218      * @throws XmlPullParserException XmlPullParserException if
219      * any.
220      * @return byte
221      */
222     private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
223         throws XmlPullParserException
224     {
225         if ( s != null )
226         {
227             try
228             {
229                 return Byte.valueOf( s ).byteValue();
230             }
231             catch ( NumberFormatException nfe )
232             {
233                 if ( strict )
234                 {
235                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
236                 }
237             }
238         }
239         return 0;
240     } //-- byte getByteValue( String, String, XmlPullParser, boolean )
241 
242     /**
243      * Method getCharacterValue.
244      * 
245      * @param s a s object.
246      * @param parser a parser object.
247      * @param attribute a attribute object.
248      * @throws XmlPullParserException XmlPullParserException if
249      * any.
250      * @return char
251      */
252     private char getCharacterValue( String s, String attribute, XmlPullParser parser )
253         throws XmlPullParserException
254     {
255         if ( s != null )
256         {
257             return s.charAt( 0 );
258         }
259         return 0;
260     } //-- char getCharacterValue( String, String, XmlPullParser )
261 
262     /**
263      * Method getDateValue.
264      * 
265      * @param s a s object.
266      * @param parser a parser object.
267      * @param attribute a attribute object.
268      * @throws XmlPullParserException XmlPullParserException if
269      * any.
270      * @return Date
271      */
272     private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
273         throws XmlPullParserException
274     {
275         return getDateValue( s, attribute, null, parser );
276     } //-- java.util.Date getDateValue( String, String, XmlPullParser )
277 
278     /**
279      * Method getDateValue.
280      * 
281      * @param s a s object.
282      * @param parser a parser object.
283      * @param dateFormat a dateFormat object.
284      * @param attribute a attribute object.
285      * @throws XmlPullParserException XmlPullParserException if
286      * any.
287      * @return Date
288      */
289     private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
290         throws XmlPullParserException
291     {
292         if ( s != null )
293         {
294             String effectiveDateFormat = dateFormat;
295             if ( dateFormat == null )
296             {
297                 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
298             }
299             if ( "long".equals( effectiveDateFormat ) )
300             {
301                 try
302                 {
303                     return new java.util.Date( Long.parseLong( s ) );
304                 }
305                 catch ( NumberFormatException e )
306                 {
307                     throw new XmlPullParserException( e.getMessage(), parser, e );
308                 }
309             }
310             else
311             {
312                 try
313                 {
314                     DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
315                     return dateParser.parse( s );
316                 }
317                 catch ( java.text.ParseException e )
318                 {
319                     throw new XmlPullParserException( e.getMessage(), parser, e );
320                 }
321             }
322         }
323         return null;
324     } //-- java.util.Date getDateValue( String, String, String, XmlPullParser )
325 
326     /**
327      * Method getDoubleValue.
328      * 
329      * @param s a s object.
330      * @param strict a strict object.
331      * @param parser a parser object.
332      * @param attribute a attribute object.
333      * @throws XmlPullParserException XmlPullParserException if
334      * any.
335      * @return double
336      */
337     private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
338         throws XmlPullParserException
339     {
340         if ( s != null )
341         {
342             try
343             {
344                 return Double.valueOf( s ).doubleValue();
345             }
346             catch ( NumberFormatException nfe )
347             {
348                 if ( strict )
349                 {
350                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
351                 }
352             }
353         }
354         return 0;
355     } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
356 
357     /**
358      * Method getFloatValue.
359      * 
360      * @param s a s object.
361      * @param strict a strict object.
362      * @param parser a parser object.
363      * @param attribute a attribute object.
364      * @throws XmlPullParserException XmlPullParserException if
365      * any.
366      * @return float
367      */
368     private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
369         throws XmlPullParserException
370     {
371         if ( s != null )
372         {
373             try
374             {
375                 return Float.valueOf( s ).floatValue();
376             }
377             catch ( NumberFormatException nfe )
378             {
379                 if ( strict )
380                 {
381                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
382                 }
383             }
384         }
385         return 0;
386     } //-- float getFloatValue( String, String, XmlPullParser, boolean )
387 
388     /**
389      * Method getIntegerValue.
390      * 
391      * @param s a s object.
392      * @param strict a strict object.
393      * @param parser a parser object.
394      * @param attribute a attribute object.
395      * @throws XmlPullParserException XmlPullParserException if
396      * any.
397      * @return int
398      */
399     private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
400         throws XmlPullParserException
401     {
402         if ( s != null )
403         {
404             try
405             {
406                 return Integer.valueOf( s ).intValue();
407             }
408             catch ( NumberFormatException nfe )
409             {
410                 if ( strict )
411                 {
412                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
413                 }
414             }
415         }
416         return 0;
417     } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
418 
419     /**
420      * Method getLongValue.
421      * 
422      * @param s a s object.
423      * @param strict a strict object.
424      * @param parser a parser object.
425      * @param attribute a attribute object.
426      * @throws XmlPullParserException XmlPullParserException if
427      * any.
428      * @return long
429      */
430     private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
431         throws XmlPullParserException
432     {
433         if ( s != null )
434         {
435             try
436             {
437                 return Long.valueOf( s ).longValue();
438             }
439             catch ( NumberFormatException nfe )
440             {
441                 if ( strict )
442                 {
443                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
444                 }
445             }
446         }
447         return 0;
448     } //-- long getLongValue( String, String, XmlPullParser, boolean )
449 
450     /**
451      * Method getRequiredAttributeValue.
452      * 
453      * @param s a s object.
454      * @param strict a strict object.
455      * @param parser a parser object.
456      * @param attribute a attribute object.
457      * @throws XmlPullParserException XmlPullParserException if
458      * any.
459      * @return String
460      */
461     private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
462         throws XmlPullParserException
463     {
464         if ( s == null )
465         {
466             if ( strict )
467             {
468                 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
469             }
470         }
471         return s;
472     } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
473 
474     /**
475      * Method getShortValue.
476      * 
477      * @param s a s object.
478      * @param strict a strict object.
479      * @param parser a parser object.
480      * @param attribute a attribute object.
481      * @throws XmlPullParserException XmlPullParserException if
482      * any.
483      * @return short
484      */
485     private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
486         throws XmlPullParserException
487     {
488         if ( s != null )
489         {
490             try
491             {
492                 return Short.valueOf( s ).shortValue();
493             }
494             catch ( NumberFormatException nfe )
495             {
496                 if ( strict )
497                 {
498                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
499                 }
500             }
501         }
502         return 0;
503     } //-- short getShortValue( String, String, XmlPullParser, boolean )
504 
505     /**
506      * Method getTrimmedValue.
507      * 
508      * @param s a s object.
509      * @return String
510      */
511     private String getTrimmedValue( String s )
512     {
513         if ( s != null )
514         {
515             s = s.trim();
516         }
517         return s;
518     } //-- String getTrimmedValue( String )
519 
520     /**
521      * Method interpolatedTrimmed.
522      * 
523      * @param value a value object.
524      * @param context a context object.
525      * @return String
526      */
527     private String interpolatedTrimmed( String value, String context )
528     {
529         return getTrimmedValue( contentTransformer.transform( value, context ) );
530     } //-- String interpolatedTrimmed( String, String )
531 
532     /**
533      * Method nextTag.
534      * 
535      * @param parser a parser object.
536      * @throws IOException IOException if any.
537      * @throws XmlPullParserException XmlPullParserException if
538      * any.
539      * @return int
540      */
541     private int nextTag( XmlPullParser parser )
542         throws IOException, XmlPullParserException
543     {
544         int eventType = parser.next();
545         if ( eventType == XmlPullParser.TEXT )
546         {
547             eventType = parser.next();
548         }
549         if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
550         {
551             throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
552         }
553         return eventType;
554     } //-- int nextTag( XmlPullParser )
555 
556     /**
557      * Method read.
558      * 
559      * @param parser a parser object.
560      * @param strict a strict object.
561      * @throws IOException IOException if any.
562      * @throws XmlPullParserException XmlPullParserException if
563      * any.
564      * @return PmdErrorDetail
565      */
566     public PmdErrorDetail read( XmlPullParser parser, boolean strict )
567         throws IOException, XmlPullParserException
568     {
569         PmdErrorDetail pmdErrorDetail = null;
570         int eventType = parser.getEventType();
571         boolean parsed = false;
572         while ( eventType != XmlPullParser.END_DOCUMENT )
573         {
574             if ( eventType == XmlPullParser.START_TAG )
575             {
576                 if ( strict && ! "pmd".equals( parser.getName() ) )
577                 {
578                     throw new XmlPullParserException( "Expected root element 'pmd' but found '" + parser.getName() + "'", parser, null );
579                 }
580                 else if ( parsed )
581                 {
582                     // fallback, already expected a XmlPullParserException due to invalid XML
583                     throw new XmlPullParserException( "Duplicated tag: 'pmd'", parser, null );
584                 }
585                 pmdErrorDetail = parsePmdErrorDetail( parser, strict );
586                 pmdErrorDetail.setModelEncoding( parser.getInputEncoding() );
587                 parsed = true;
588             }
589             eventType = parser.next();
590         }
591         if ( parsed )
592         {
593             return pmdErrorDetail;
594         }
595         throw new XmlPullParserException( "Expected root element 'pmd' but found no element at all: invalid XML document", parser, null );
596     } //-- PmdErrorDetail read( XmlPullParser, boolean )
597 
598     /**
599      * @see ReaderFactory#newXmlReader
600      * 
601      * @param reader a reader object.
602      * @param strict a strict object.
603      * @throws IOException IOException if any.
604      * @throws XmlPullParserException XmlPullParserException if
605      * any.
606      * @return PmdErrorDetail
607      */
608     public PmdErrorDetail read( Reader reader, boolean strict )
609         throws IOException, XmlPullParserException
610     {
611         XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
612 
613         parser.setInput( reader );
614 
615 
616         return read( parser, strict );
617     } //-- PmdErrorDetail read( Reader, boolean )
618 
619     /**
620      * @see ReaderFactory#newXmlReader
621      * 
622      * @param reader a reader object.
623      * @throws IOException IOException if any.
624      * @throws XmlPullParserException XmlPullParserException if
625      * any.
626      * @return PmdErrorDetail
627      */
628     public PmdErrorDetail read( Reader reader )
629         throws IOException, XmlPullParserException
630     {
631         return read( reader, true );
632     } //-- PmdErrorDetail read( Reader )
633 
634     /**
635      * Method read.
636      * 
637      * @param in a in object.
638      * @param strict a strict object.
639      * @throws IOException IOException if any.
640      * @throws XmlPullParserException XmlPullParserException if
641      * any.
642      * @return PmdErrorDetail
643      */
644     public PmdErrorDetail read( InputStream in, boolean strict )
645         throws IOException, XmlPullParserException
646     {
647         return read( ReaderFactory.newXmlReader( in ), strict );
648     } //-- PmdErrorDetail read( InputStream, boolean )
649 
650     /**
651      * Method read.
652      * 
653      * @param in a in object.
654      * @throws IOException IOException if any.
655      * @throws XmlPullParserException XmlPullParserException if
656      * any.
657      * @return PmdErrorDetail
658      */
659     public PmdErrorDetail read( InputStream in )
660         throws IOException, XmlPullParserException
661     {
662         return read( ReaderFactory.newXmlReader( in ) );
663     } //-- PmdErrorDetail read( InputStream )
664 
665     /**
666      * Method parsePmdErrorDetail.
667      * 
668      * @param parser a parser object.
669      * @param strict a strict object.
670      * @throws IOException IOException if any.
671      * @throws XmlPullParserException XmlPullParserException if
672      * any.
673      * @return PmdErrorDetail
674      */
675     private PmdErrorDetail parsePmdErrorDetail( XmlPullParser parser, boolean strict )
676         throws IOException, XmlPullParserException
677     {
678         String tagName = parser.getName();
679         PmdErrorDetail pmdErrorDetail = new PmdErrorDetail();
680         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
681         {
682             String name = parser.getAttributeName( i );
683             String value = parser.getAttributeValue( i );
684 
685             if ( name.indexOf( ':' ) >= 0 )
686             {
687                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
688             }
689             else if ( "xmlns".equals( name ) )
690             {
691                 // ignore xmlns attribute in root class, which is a reserved attribute name
692             }
693             else
694             {
695                 checkUnknownAttribute( parser, name, tagName, strict );
696             }
697         }
698         java.util.Set parsed = new java.util.HashSet();
699         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
700         {
701             if ( "file".equals( parser.getName() ) )
702             {
703                 java.util.List<PmdFile> files = pmdErrorDetail.getFiles();
704                 if ( files == null )
705                 {
706                     files = new java.util.ArrayList<PmdFile>();
707                 }
708                 files.add( parsePmdFile( parser, strict ) );
709                 pmdErrorDetail.setFiles( files );
710             }
711             else if ( "suppressedviolation".equals( parser.getName() ) )
712             {
713                 java.util.List<SuppressedViolation> suppressedViolations = pmdErrorDetail.getSuppressedViolations();
714                 if ( suppressedViolations == null )
715                 {
716                     suppressedViolations = new java.util.ArrayList<SuppressedViolation>();
717                 }
718                 suppressedViolations.add( parseSuppressedViolation( parser, strict ) );
719                 pmdErrorDetail.setSuppressedViolations( suppressedViolations );
720             }
721             else if ( "error".equals( parser.getName() ) )
722             {
723                 java.util.List<ProcessingError> errors = pmdErrorDetail.getErrors();
724                 if ( errors == null )
725                 {
726                     errors = new java.util.ArrayList<ProcessingError>();
727                 }
728                 errors.add( parseProcessingError( parser, strict ) );
729                 pmdErrorDetail.setErrors( errors );
730             }
731             else
732             {
733                 checkUnknownElement( parser, strict );
734             }
735         }
736         return pmdErrorDetail;
737     } //-- PmdErrorDetail parsePmdErrorDetail( XmlPullParser, boolean )
738 
739     /**
740      * Method parsePmdFile.
741      * 
742      * @param parser a parser object.
743      * @param strict a strict object.
744      * @throws IOException IOException if any.
745      * @throws XmlPullParserException XmlPullParserException if
746      * any.
747      * @return PmdFile
748      */
749     private PmdFile parsePmdFile( XmlPullParser parser, boolean strict )
750         throws IOException, XmlPullParserException
751     {
752         String tagName = parser.getName();
753         PmdFile pmdFile = new PmdFile();
754         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
755         {
756             String name = parser.getAttributeName( i );
757             String value = parser.getAttributeValue( i );
758 
759             if ( name.indexOf( ':' ) >= 0 )
760             {
761                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
762             }
763             else if ( "name".equals( name ) )
764             {
765                 pmdFile.setName( interpolatedTrimmed( value, "name" ) );
766             }
767             else
768             {
769                 checkUnknownAttribute( parser, name, tagName, strict );
770             }
771         }
772         java.util.Set parsed = new java.util.HashSet();
773         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
774         {
775             if ( "violation".equals( parser.getName() ) )
776             {
777                 java.util.List<Violation> violations = pmdFile.getViolations();
778                 if ( violations == null )
779                 {
780                     violations = new java.util.ArrayList<Violation>();
781                 }
782                 violations.add( parseViolation( parser, strict ) );
783                 pmdFile.setViolations( violations );
784             }
785             else
786             {
787                 checkUnknownElement( parser, strict );
788             }
789         }
790         return pmdFile;
791     } //-- PmdFile parsePmdFile( XmlPullParser, boolean )
792 
793     /**
794      * Method parseProcessingError.
795      * 
796      * @param parser a parser object.
797      * @param strict a strict object.
798      * @throws IOException IOException if any.
799      * @throws XmlPullParserException XmlPullParserException if
800      * any.
801      * @return ProcessingError
802      */
803     private ProcessingError parseProcessingError( XmlPullParser parser, boolean strict )
804         throws IOException, XmlPullParserException
805     {
806         String tagName = parser.getName();
807         ProcessingError processingError = new ProcessingError();
808         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
809         {
810             String name = parser.getAttributeName( i );
811             String value = parser.getAttributeValue( i );
812 
813             if ( name.indexOf( ':' ) >= 0 )
814             {
815                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
816             }
817             else if ( "filename".equals( name ) )
818             {
819                 processingError.setFilename( interpolatedTrimmed( value, "filename" ) );
820             }
821             else if ( "msg".equals( name ) )
822             {
823                 processingError.setMsg( interpolatedTrimmed( value, "msg" ) );
824             }
825             else
826             {
827                 checkUnknownAttribute( parser, name, tagName, strict );
828             }
829         }
830         processingError.setDetail( interpolatedTrimmed( parser.nextText(), "detail" ) );
831         return processingError;
832     } //-- ProcessingError parseProcessingError( XmlPullParser, boolean )
833 
834     /**
835      * Method parseSuppressedViolation.
836      * 
837      * @param parser a parser object.
838      * @param strict a strict object.
839      * @throws IOException IOException if any.
840      * @throws XmlPullParserException XmlPullParserException if
841      * any.
842      * @return SuppressedViolation
843      */
844     private SuppressedViolation parseSuppressedViolation( XmlPullParser parser, boolean strict )
845         throws IOException, XmlPullParserException
846     {
847         String tagName = parser.getName();
848         SuppressedViolation suppressedViolation = new SuppressedViolation();
849         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
850         {
851             String name = parser.getAttributeName( i );
852             String value = parser.getAttributeValue( i );
853 
854             if ( name.indexOf( ':' ) >= 0 )
855             {
856                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
857             }
858             else if ( "filename".equals( name ) )
859             {
860                 suppressedViolation.setFilename( interpolatedTrimmed( value, "filename" ) );
861             }
862             else if ( "suppressiontype".equals( name ) )
863             {
864                 suppressedViolation.setSuppressionType( interpolatedTrimmed( value, "suppressiontype" ) );
865             }
866             else if ( "msg".equals( name ) )
867             {
868                 suppressedViolation.setRuleMessage( interpolatedTrimmed( value, "msg" ) );
869             }
870             else if ( "usermsg".equals( name ) )
871             {
872                 suppressedViolation.setUserMessage( interpolatedTrimmed( value, "usermsg" ) );
873             }
874             else
875             {
876                 checkUnknownAttribute( parser, name, tagName, strict );
877             }
878         }
879         java.util.Set parsed = new java.util.HashSet();
880         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
881         {
882             checkUnknownElement( parser, strict );
883         }
884         return suppressedViolation;
885     } //-- SuppressedViolation parseSuppressedViolation( XmlPullParser, boolean )
886 
887     /**
888      * Method parseViolation.
889      * 
890      * @param parser a parser object.
891      * @param strict a strict object.
892      * @throws IOException IOException if any.
893      * @throws XmlPullParserException XmlPullParserException if
894      * any.
895      * @return Violation
896      */
897     private Violation parseViolation( XmlPullParser parser, boolean strict )
898         throws IOException, XmlPullParserException
899     {
900         String tagName = parser.getName();
901         Violation violation = new Violation();
902         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
903         {
904             String name = parser.getAttributeName( i );
905             String value = parser.getAttributeValue( i );
906 
907             if ( name.indexOf( ':' ) >= 0 )
908             {
909                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
910             }
911             else if ( "beginline".equals( name ) )
912             {
913                 violation.setBeginline( getIntegerValue( interpolatedTrimmed( value, "beginline" ), "beginline", parser, strict ) );
914             }
915             else if ( "endline".equals( name ) )
916             {
917                 violation.setEndline( getIntegerValue( interpolatedTrimmed( value, "endline" ), "endline", parser, strict ) );
918             }
919             else if ( "class".equals( name ) )
920             {
921                 violation.setViolationClass( interpolatedTrimmed( value, "class" ) );
922             }
923             else if ( "package".equals( name ) )
924             {
925                 violation.setViolationPackage( interpolatedTrimmed( value, "package" ) );
926             }
927             else if ( "rule".equals( name ) )
928             {
929                 violation.setRule( interpolatedTrimmed( value, "rule" ) );
930             }
931             else if ( "priority".equals( name ) )
932             {
933                 violation.setPriority( getIntegerValue( interpolatedTrimmed( value, "priority" ), "priority", parser, strict ) );
934             }
935             else if ( "externalInfoUrl".equals( name ) )
936             {
937                 violation.setExternalInfoUrl( interpolatedTrimmed( value, "externalInfoUrl" ) );
938             }
939             else
940             {
941                 checkUnknownAttribute( parser, name, tagName, strict );
942             }
943         }
944         violation.setText( interpolatedTrimmed( parser.nextText(), "text" ) );
945         return violation;
946     } //-- Violation parseViolation( XmlPullParser, boolean )
947 
948     /**
949      * Sets the state of the "add default entities" flag.
950      * 
951      * @param addDefaultEntities a addDefaultEntities object.
952      */
953     public void setAddDefaultEntities( boolean addDefaultEntities )
954     {
955         this.addDefaultEntities = addDefaultEntities;
956     } //-- void setAddDefaultEntities( boolean )
957 
958     public static interface ContentTransformer
959 {
960     /**
961      * Interpolate the value read from the xpp3 document
962      * @param source The source value
963      * @param fieldName A description of the field being interpolated. The implementation may use this to
964      *                           log stuff.
965      * @return The interpolated value.
966      */
967     String transform( String source, String fieldName );
968 }
969 
970 }