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