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.buildcache.xml.build.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.buildcache.xml.build.Artifact;
17  import org.apache.maven.buildcache.xml.build.Build;
18  import org.apache.maven.buildcache.xml.build.CompletedExecution;
19  import org.apache.maven.buildcache.xml.build.DigestItem;
20  import org.apache.maven.buildcache.xml.build.ProjectsInputInfo;
21  import org.apache.maven.buildcache.xml.build.PropertyValue;
22  import org.apache.maven.buildcache.xml.build.Scm;
23  import org.codehaus.plexus.util.ReaderFactory;
24  import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
25  import org.codehaus.plexus.util.xml.pull.MXParser;
26  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
27  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
28  
29  /**
30   * Class BuildCacheBuildXpp3Reader.
31   * 
32   * @version $Revision$ $Date$
33   */
34  @SuppressWarnings( "all" )
35  public class BuildCacheBuildXpp3Reader
36  {
37  
38        //--------------------------/
39       //- Class/Member Variables -/
40      //--------------------------/
41  
42      /**
43       * If set the parser will be loaded with all single characters
44       * from the XHTML specification.
45       * The entities used:
46       * <ul>
47       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
48       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
49       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
50       * </ul>
51       */
52      private boolean addDefaultEntities = true;
53  
54      /**
55       * Field contentTransformer.
56       */
57      public final ContentTransformer contentTransformer;
58  
59  
60        //----------------/
61       //- Constructors -/
62      //----------------/
63  
64      public BuildCacheBuildXpp3Reader()
65      {
66          this( new ContentTransformer()
67          {
68              public String transform( String source, String fieldName )
69              {
70                  return source;
71              }
72          } );
73      } //-- org.apache.maven.buildcache.xml.build.io.xpp3.BuildCacheBuildXpp3Reader()
74  
75      public BuildCacheBuildXpp3Reader(ContentTransformer contentTransformer)
76      {
77          this.contentTransformer = contentTransformer;
78      } //-- org.apache.maven.buildcache.xml.build.io.xpp3.BuildCacheBuildXpp3Reader(ContentTransformer)
79  
80  
81        //-----------/
82       //- Methods -/
83      //-----------/
84  
85      /**
86       * Method checkFieldWithDuplicate.
87       * 
88       * @param parser a parser object.
89       * @param parsed a parsed object.
90       * @param alias a alias object.
91       * @param tagName a tagName object.
92       * @throws XmlPullParserException XmlPullParserException if
93       * any.
94       * @return boolean
95       */
96      private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
97          throws XmlPullParserException
98      {
99          if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
100         {
101             return false;
102         }
103         if ( !parsed.add( tagName ) )
104         {
105             throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
106         }
107         return true;
108     } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set )
109 
110     /**
111      * Method checkUnknownAttribute.
112      * 
113      * @param parser a parser object.
114      * @param strict a strict object.
115      * @param tagName a tagName object.
116      * @param attribute a attribute object.
117      * @throws XmlPullParserException XmlPullParserException if
118      * any.
119      * @throws IOException IOException if any.
120      */
121     private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
122         throws XmlPullParserException, IOException
123     {
124         // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
125         if ( strict )
126         {
127             throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
128         }
129     } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
130 
131     /**
132      * Method checkUnknownElement.
133      * 
134      * @param parser a parser object.
135      * @param strict a strict object.
136      * @throws XmlPullParserException XmlPullParserException if
137      * any.
138      * @throws IOException IOException if any.
139      */
140     private void checkUnknownElement( XmlPullParser parser, boolean strict )
141         throws XmlPullParserException, IOException
142     {
143         if ( strict )
144         {
145             throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
146         }
147 
148         for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
149         {
150             int eventType = parser.next();
151             if ( eventType == XmlPullParser.START_TAG )
152             {
153                 unrecognizedTagCount++;
154             }
155             else if ( eventType == XmlPullParser.END_TAG )
156             {
157                 unrecognizedTagCount--;
158             }
159         }
160     } //-- void checkUnknownElement( XmlPullParser, boolean )
161 
162     /**
163      * Returns the state of the "add default entities" flag.
164      * 
165      * @return boolean
166      */
167     public boolean getAddDefaultEntities()
168     {
169         return addDefaultEntities;
170     } //-- boolean getAddDefaultEntities()
171 
172     /**
173      * Method getBooleanValue.
174      * 
175      * @param s a s object.
176      * @param parser a parser object.
177      * @param attribute a attribute object.
178      * @throws XmlPullParserException XmlPullParserException if
179      * any.
180      * @return boolean
181      */
182     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
183         throws XmlPullParserException
184     {
185         return getBooleanValue( s, attribute, parser, null );
186     } //-- boolean getBooleanValue( String, String, XmlPullParser )
187 
188     /**
189      * Method getBooleanValue.
190      * 
191      * @param s a s object.
192      * @param defaultValue a defaultValue object.
193      * @param parser a parser object.
194      * @param attribute a attribute object.
195      * @throws XmlPullParserException XmlPullParserException if
196      * any.
197      * @return boolean
198      */
199     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
200         throws XmlPullParserException
201     {
202         if ( s != null && s.length() != 0 )
203         {
204             return Boolean.valueOf( s ).booleanValue();
205         }
206         if ( defaultValue != null )
207         {
208             return Boolean.valueOf( defaultValue ).booleanValue();
209         }
210         return false;
211     } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
212 
213     /**
214      * Method getByteValue.
215      * 
216      * @param s a s object.
217      * @param strict a strict object.
218      * @param parser a parser object.
219      * @param attribute a attribute object.
220      * @throws XmlPullParserException XmlPullParserException if
221      * any.
222      * @return byte
223      */
224     private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
225         throws XmlPullParserException
226     {
227         if ( s != null )
228         {
229             try
230             {
231                 return Byte.valueOf( s ).byteValue();
232             }
233             catch ( NumberFormatException nfe )
234             {
235                 if ( strict )
236                 {
237                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
238                 }
239             }
240         }
241         return 0;
242     } //-- byte getByteValue( String, String, XmlPullParser, boolean )
243 
244     /**
245      * Method getCharacterValue.
246      * 
247      * @param s a s object.
248      * @param parser a parser object.
249      * @param attribute a attribute object.
250      * @throws XmlPullParserException XmlPullParserException if
251      * any.
252      * @return char
253      */
254     private char getCharacterValue( String s, String attribute, XmlPullParser parser )
255         throws XmlPullParserException
256     {
257         if ( s != null )
258         {
259             return s.charAt( 0 );
260         }
261         return 0;
262     } //-- char getCharacterValue( String, String, XmlPullParser )
263 
264     /**
265      * Method getDateValue.
266      * 
267      * @param s a s object.
268      * @param parser a parser object.
269      * @param attribute a attribute object.
270      * @throws XmlPullParserException XmlPullParserException if
271      * any.
272      * @return Date
273      */
274     private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
275         throws XmlPullParserException
276     {
277         return getDateValue( s, attribute, null, parser );
278     } //-- java.util.Date getDateValue( String, String, XmlPullParser )
279 
280     /**
281      * Method getDateValue.
282      * 
283      * @param s a s object.
284      * @param parser a parser object.
285      * @param dateFormat a dateFormat object.
286      * @param attribute a attribute object.
287      * @throws XmlPullParserException XmlPullParserException if
288      * any.
289      * @return Date
290      */
291     private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
292         throws XmlPullParserException
293     {
294         if ( s != null )
295         {
296             String effectiveDateFormat = dateFormat;
297             if ( dateFormat == null )
298             {
299                 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
300             }
301             if ( "long".equals( effectiveDateFormat ) )
302             {
303                 try
304                 {
305                     return new java.util.Date( Long.parseLong( s ) );
306                 }
307                 catch ( NumberFormatException e )
308                 {
309                     throw new XmlPullParserException( e.getMessage(), parser, e );
310                 }
311             }
312             else
313             {
314                 try
315                 {
316                     DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
317                     return dateParser.parse( s );
318                 }
319                 catch ( java.text.ParseException e )
320                 {
321                     throw new XmlPullParserException( e.getMessage(), parser, e );
322                 }
323             }
324         }
325         return null;
326     } //-- java.util.Date getDateValue( String, String, String, XmlPullParser )
327 
328     /**
329      * Method getDoubleValue.
330      * 
331      * @param s a s object.
332      * @param strict a strict object.
333      * @param parser a parser object.
334      * @param attribute a attribute object.
335      * @throws XmlPullParserException XmlPullParserException if
336      * any.
337      * @return double
338      */
339     private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
340         throws XmlPullParserException
341     {
342         if ( s != null )
343         {
344             try
345             {
346                 return Double.valueOf( s ).doubleValue();
347             }
348             catch ( NumberFormatException nfe )
349             {
350                 if ( strict )
351                 {
352                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
353                 }
354             }
355         }
356         return 0;
357     } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
358 
359     /**
360      * Method getFloatValue.
361      * 
362      * @param s a s object.
363      * @param strict a strict object.
364      * @param parser a parser object.
365      * @param attribute a attribute object.
366      * @throws XmlPullParserException XmlPullParserException if
367      * any.
368      * @return float
369      */
370     private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
371         throws XmlPullParserException
372     {
373         if ( s != null )
374         {
375             try
376             {
377                 return Float.valueOf( s ).floatValue();
378             }
379             catch ( NumberFormatException nfe )
380             {
381                 if ( strict )
382                 {
383                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
384                 }
385             }
386         }
387         return 0;
388     } //-- float getFloatValue( String, String, XmlPullParser, boolean )
389 
390     /**
391      * Method getIntegerValue.
392      * 
393      * @param s a s object.
394      * @param strict a strict object.
395      * @param parser a parser object.
396      * @param attribute a attribute object.
397      * @throws XmlPullParserException XmlPullParserException if
398      * any.
399      * @return int
400      */
401     private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
402         throws XmlPullParserException
403     {
404         if ( s != null )
405         {
406             try
407             {
408                 return Integer.valueOf( s ).intValue();
409             }
410             catch ( NumberFormatException nfe )
411             {
412                 if ( strict )
413                 {
414                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
415                 }
416             }
417         }
418         return 0;
419     } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
420 
421     /**
422      * Method getLongValue.
423      * 
424      * @param s a s object.
425      * @param strict a strict object.
426      * @param parser a parser object.
427      * @param attribute a attribute object.
428      * @throws XmlPullParserException XmlPullParserException if
429      * any.
430      * @return long
431      */
432     private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
433         throws XmlPullParserException
434     {
435         if ( s != null )
436         {
437             try
438             {
439                 return Long.valueOf( s ).longValue();
440             }
441             catch ( NumberFormatException nfe )
442             {
443                 if ( strict )
444                 {
445                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
446                 }
447             }
448         }
449         return 0;
450     } //-- long getLongValue( String, String, XmlPullParser, boolean )
451 
452     /**
453      * Method getRequiredAttributeValue.
454      * 
455      * @param s a s object.
456      * @param strict a strict object.
457      * @param parser a parser object.
458      * @param attribute a attribute object.
459      * @throws XmlPullParserException XmlPullParserException if
460      * any.
461      * @return String
462      */
463     private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
464         throws XmlPullParserException
465     {
466         if ( s == null )
467         {
468             if ( strict )
469             {
470                 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
471             }
472         }
473         return s;
474     } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
475 
476     /**
477      * Method getShortValue.
478      * 
479      * @param s a s object.
480      * @param strict a strict object.
481      * @param parser a parser object.
482      * @param attribute a attribute object.
483      * @throws XmlPullParserException XmlPullParserException if
484      * any.
485      * @return short
486      */
487     private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
488         throws XmlPullParserException
489     {
490         if ( s != null )
491         {
492             try
493             {
494                 return Short.valueOf( s ).shortValue();
495             }
496             catch ( NumberFormatException nfe )
497             {
498                 if ( strict )
499                 {
500                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
501                 }
502             }
503         }
504         return 0;
505     } //-- short getShortValue( String, String, XmlPullParser, boolean )
506 
507     /**
508      * Method getTrimmedValue.
509      * 
510      * @param s a s object.
511      * @return String
512      */
513     private String getTrimmedValue( String s )
514     {
515         if ( s != null )
516         {
517             s = s.trim();
518         }
519         return s;
520     } //-- String getTrimmedValue( String )
521 
522     /**
523      * Method interpolatedTrimmed.
524      * 
525      * @param value a value object.
526      * @param context a context object.
527      * @return String
528      */
529     private String interpolatedTrimmed( String value, String context )
530     {
531         return getTrimmedValue( contentTransformer.transform( value, context ) );
532     } //-- String interpolatedTrimmed( String, String )
533 
534     /**
535      * Method nextTag.
536      * 
537      * @param parser a parser object.
538      * @throws IOException IOException if any.
539      * @throws XmlPullParserException XmlPullParserException if
540      * any.
541      * @return int
542      */
543     private int nextTag( XmlPullParser parser )
544         throws IOException, XmlPullParserException
545     {
546         int eventType = parser.next();
547         if ( eventType == XmlPullParser.TEXT )
548         {
549             eventType = parser.next();
550         }
551         if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
552         {
553             throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
554         }
555         return eventType;
556     } //-- int nextTag( XmlPullParser )
557 
558     /**
559      * Method read.
560      * 
561      * @param parser a parser object.
562      * @param strict a strict object.
563      * @throws IOException IOException if any.
564      * @throws XmlPullParserException XmlPullParserException if
565      * any.
566      * @return Build
567      */
568     public Build read( XmlPullParser parser, boolean strict )
569         throws IOException, XmlPullParserException
570     {
571         Build build = null;
572         int eventType = parser.getEventType();
573         boolean parsed = false;
574         while ( eventType != XmlPullParser.END_DOCUMENT )
575         {
576             if ( eventType == XmlPullParser.START_TAG )
577             {
578                 if ( strict && ! "build".equals( parser.getName() ) )
579                 {
580                     throw new XmlPullParserException( "Expected root element 'build' but found '" + parser.getName() + "'", parser, null );
581                 }
582                 else if ( parsed )
583                 {
584                     // fallback, already expected a XmlPullParserException due to invalid XML
585                     throw new XmlPullParserException( "Duplicated tag: 'build'", parser, null );
586                 }
587                 build = parseBuild( parser, strict );
588                 build.setModelEncoding( parser.getInputEncoding() );
589                 parsed = true;
590             }
591             eventType = parser.next();
592         }
593         if ( parsed )
594         {
595             return build;
596         }
597         throw new XmlPullParserException( "Expected root element 'build' but found no element at all: invalid XML document", parser, null );
598     } //-- Build read( XmlPullParser, boolean )
599 
600     /**
601      * @see ReaderFactory#newXmlReader
602      * 
603      * @param reader a reader object.
604      * @param strict a strict object.
605      * @throws IOException IOException if any.
606      * @throws XmlPullParserException XmlPullParserException if
607      * any.
608      * @return Build
609      */
610     public Build read( Reader reader, boolean strict )
611         throws IOException, XmlPullParserException
612     {
613         XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
614 
615         parser.setInput( reader );
616 
617 
618         return read( parser, strict );
619     } //-- Build read( Reader, boolean )
620 
621     /**
622      * @see ReaderFactory#newXmlReader
623      * 
624      * @param reader a reader object.
625      * @throws IOException IOException if any.
626      * @throws XmlPullParserException XmlPullParserException if
627      * any.
628      * @return Build
629      */
630     public Build read( Reader reader )
631         throws IOException, XmlPullParserException
632     {
633         return read( reader, true );
634     } //-- Build read( Reader )
635 
636     /**
637      * Method read.
638      * 
639      * @param in a in object.
640      * @param strict a strict object.
641      * @throws IOException IOException if any.
642      * @throws XmlPullParserException XmlPullParserException if
643      * any.
644      * @return Build
645      */
646     public Build read( InputStream in, boolean strict )
647         throws IOException, XmlPullParserException
648     {
649         return read( ReaderFactory.newXmlReader( in ), strict );
650     } //-- Build read( InputStream, boolean )
651 
652     /**
653      * Method read.
654      * 
655      * @param in a in object.
656      * @throws IOException IOException if any.
657      * @throws XmlPullParserException XmlPullParserException if
658      * any.
659      * @return Build
660      */
661     public Build read( InputStream in )
662         throws IOException, XmlPullParserException
663     {
664         return read( ReaderFactory.newXmlReader( in ) );
665     } //-- Build read( InputStream )
666 
667     /**
668      * Method parseArtifact.
669      * 
670      * @param parser a parser object.
671      * @param strict a strict object.
672      * @throws IOException IOException if any.
673      * @throws XmlPullParserException XmlPullParserException if
674      * any.
675      * @return Artifact
676      */
677     private Artifact parseArtifact( XmlPullParser parser, boolean strict )
678         throws IOException, XmlPullParserException
679     {
680         String tagName = parser.getName();
681         Artifact artifact = new Artifact();
682         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
683         {
684             String name = parser.getAttributeName( i );
685             String value = parser.getAttributeValue( i );
686 
687             if ( name.indexOf( ':' ) >= 0 )
688             {
689                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
690             }
691             else
692             {
693                 checkUnknownAttribute( parser, name, tagName, strict );
694             }
695         }
696         java.util.Set parsed = new java.util.HashSet();
697         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
698         {
699             if ( checkFieldWithDuplicate( parser, "groupId", null, parsed ) )
700             {
701                 artifact.setGroupId( interpolatedTrimmed( parser.nextText(), "groupId" ) );
702             }
703             else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) )
704             {
705                 artifact.setArtifactId( interpolatedTrimmed( parser.nextText(), "artifactId" ) );
706             }
707             else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
708             {
709                 artifact.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) );
710             }
711             else if ( checkFieldWithDuplicate( parser, "classifier", null, parsed ) )
712             {
713                 artifact.setClassifier( interpolatedTrimmed( parser.nextText(), "classifier" ) );
714             }
715             else if ( checkFieldWithDuplicate( parser, "type", null, parsed ) )
716             {
717                 artifact.setType( interpolatedTrimmed( parser.nextText(), "type" ) );
718             }
719             else if ( checkFieldWithDuplicate( parser, "scope", null, parsed ) )
720             {
721                 artifact.setScope( interpolatedTrimmed( parser.nextText(), "scope" ) );
722             }
723             else if ( checkFieldWithDuplicate( parser, "fileName", null, parsed ) )
724             {
725                 artifact.setFileName( interpolatedTrimmed( parser.nextText(), "fileName" ) );
726             }
727             else if ( checkFieldWithDuplicate( parser, "fileHash", null, parsed ) )
728             {
729                 artifact.setFileHash( interpolatedTrimmed( parser.nextText(), "fileHash" ) );
730             }
731             else if ( checkFieldWithDuplicate( parser, "fileSize", null, parsed ) )
732             {
733                 artifact.setFileSize( getLongValue( interpolatedTrimmed( parser.nextText(), "fileSize" ), "fileSize", parser, strict ) );
734             }
735             else if ( checkFieldWithDuplicate( parser, "filePath", null, parsed ) )
736             {
737                 artifact.setFilePath( interpolatedTrimmed( parser.nextText(), "filePath" ) );
738             }
739             else
740             {
741                 checkUnknownElement( parser, strict );
742             }
743         }
744         return artifact;
745     } //-- Artifact parseArtifact( XmlPullParser, boolean )
746 
747     /**
748      * Method parseBuild.
749      * 
750      * @param parser a parser object.
751      * @param strict a strict object.
752      * @throws IOException IOException if any.
753      * @throws XmlPullParserException XmlPullParserException if
754      * any.
755      * @return Build
756      */
757     private Build parseBuild( XmlPullParser parser, boolean strict )
758         throws IOException, XmlPullParserException
759     {
760         String tagName = parser.getName();
761         Build build = new Build();
762         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
763         {
764             String name = parser.getAttributeName( i );
765             String value = parser.getAttributeValue( i );
766 
767             if ( name.indexOf( ':' ) >= 0 )
768             {
769                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
770             }
771             else if ( "xmlns".equals( name ) )
772             {
773                 // ignore xmlns attribute in root class, which is a reserved attribute name
774             }
775             else
776             {
777                 checkUnknownAttribute( parser, name, tagName, strict );
778             }
779         }
780         java.util.Set parsed = new java.util.HashSet();
781         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
782         {
783             if ( checkFieldWithDuplicate( parser, "cacheImplementationVersion", null, parsed ) )
784             {
785                 build.setCacheImplementationVersion( interpolatedTrimmed( parser.nextText(), "cacheImplementationVersion" ) );
786             }
787             else if ( checkFieldWithDuplicate( parser, "final", "final", parsed ) )
788             {
789                 build.set_final( getBooleanValue( interpolatedTrimmed( parser.nextText(), "final" ), "final", parser, "null" ) );
790             }
791             else if ( checkFieldWithDuplicate( parser, "hashFunction", null, parsed ) )
792             {
793                 build.setHashFunction( interpolatedTrimmed( parser.nextText(), "hashFunction" ) );
794             }
795             else if ( checkFieldWithDuplicate( parser, "buildTime", null, parsed ) )
796             {
797                 String dateFormat = null;
798                 build.setBuildTime( getDateValue( interpolatedTrimmed( parser.nextText(), "buildTime" ), "buildTime", dateFormat, parser ) );
799             }
800             else if ( checkFieldWithDuplicate( parser, "buildServer", null, parsed ) )
801             {
802                 build.setBuildServer( interpolatedTrimmed( parser.nextText(), "buildServer" ) );
803             }
804             else if ( checkFieldWithDuplicate( parser, "scm", null, parsed ) )
805             {
806                 build.setScm( parseScm( parser, strict ) );
807             }
808             else if ( checkFieldWithDuplicate( parser, "goals", null, parsed ) )
809             {
810                 java.util.List<String> goals = new java.util.ArrayList<String>();
811                 while ( parser.nextTag() == XmlPullParser.START_TAG )
812                 {
813                     if ( "goal".equals( parser.getName() ) )
814                     {
815                         goals.add( interpolatedTrimmed( parser.nextText(), "goals" ) );
816                     }
817                     else
818                     {
819                         checkUnknownElement( parser, strict );
820                     }
821                 }
822                 build.setGoals( goals );
823             }
824             else if ( checkFieldWithDuplicate( parser, "artifact", null, parsed ) )
825             {
826                 build.setArtifact( parseArtifact( parser, strict ) );
827             }
828             else if ( checkFieldWithDuplicate( parser, "attachedArtifacts", null, parsed ) )
829             {
830                 java.util.List<Artifact> attachedArtifacts = new java.util.ArrayList<Artifact>();
831                 while ( parser.nextTag() == XmlPullParser.START_TAG )
832                 {
833                     if ( "attachedArtifact".equals( parser.getName() ) )
834                     {
835                         attachedArtifacts.add( parseArtifact( parser, strict ) );
836                     }
837                     else
838                     {
839                         checkUnknownElement( parser, strict );
840                     }
841                 }
842                 build.setAttachedArtifacts( attachedArtifacts );
843             }
844             else if ( checkFieldWithDuplicate( parser, "executions", null, parsed ) )
845             {
846                 java.util.List<CompletedExecution> executions = new java.util.ArrayList<CompletedExecution>();
847                 while ( parser.nextTag() == XmlPullParser.START_TAG )
848                 {
849                     if ( "execution".equals( parser.getName() ) )
850                     {
851                         executions.add( parseCompletedExecution( parser, strict ) );
852                     }
853                     else
854                     {
855                         checkUnknownElement( parser, strict );
856                     }
857                 }
858                 build.setExecutions( executions );
859             }
860             else if ( checkFieldWithDuplicate( parser, "projectsInputInfo", null, parsed ) )
861             {
862                 build.setProjectsInputInfo( parseProjectsInputInfo( parser, strict ) );
863             }
864             else
865             {
866                 checkUnknownElement( parser, strict );
867             }
868         }
869         return build;
870     } //-- Build parseBuild( XmlPullParser, boolean )
871 
872     /**
873      * Method parseCompletedExecution.
874      * 
875      * @param parser a parser object.
876      * @param strict a strict object.
877      * @throws IOException IOException if any.
878      * @throws XmlPullParserException XmlPullParserException if
879      * any.
880      * @return CompletedExecution
881      */
882     private CompletedExecution parseCompletedExecution( XmlPullParser parser, boolean strict )
883         throws IOException, XmlPullParserException
884     {
885         String tagName = parser.getName();
886         CompletedExecution completedExecution = new CompletedExecution();
887         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
888         {
889             String name = parser.getAttributeName( i );
890             String value = parser.getAttributeValue( i );
891 
892             if ( name.indexOf( ':' ) >= 0 )
893             {
894                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
895             }
896             else
897             {
898                 checkUnknownAttribute( parser, name, tagName, strict );
899             }
900         }
901         java.util.Set parsed = new java.util.HashSet();
902         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
903         {
904             if ( checkFieldWithDuplicate( parser, "executionKey", null, parsed ) )
905             {
906                 completedExecution.setExecutionKey( interpolatedTrimmed( parser.nextText(), "executionKey" ) );
907             }
908             else if ( checkFieldWithDuplicate( parser, "mojoClassName", null, parsed ) )
909             {
910                 completedExecution.setMojoClassName( interpolatedTrimmed( parser.nextText(), "mojoClassName" ) );
911             }
912             else if ( checkFieldWithDuplicate( parser, "properties", null, parsed ) )
913             {
914                 java.util.List<PropertyValue> properties = new java.util.ArrayList<PropertyValue>();
915                 while ( parser.nextTag() == XmlPullParser.START_TAG )
916                 {
917                     if ( "property".equals( parser.getName() ) )
918                     {
919                         properties.add( parsePropertyValue( parser, strict ) );
920                     }
921                     else
922                     {
923                         checkUnknownElement( parser, strict );
924                     }
925                 }
926                 completedExecution.setProperties( properties );
927             }
928             else
929             {
930                 checkUnknownElement( parser, strict );
931             }
932         }
933         return completedExecution;
934     } //-- CompletedExecution parseCompletedExecution( XmlPullParser, boolean )
935 
936     /**
937      * Method parseDigestItem.
938      * 
939      * @param parser a parser object.
940      * @param strict a strict object.
941      * @throws IOException IOException if any.
942      * @throws XmlPullParserException XmlPullParserException if
943      * any.
944      * @return DigestItem
945      */
946     private DigestItem parseDigestItem( XmlPullParser parser, boolean strict )
947         throws IOException, XmlPullParserException
948     {
949         String tagName = parser.getName();
950         DigestItem digestItem = new DigestItem();
951         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
952         {
953             String name = parser.getAttributeName( i );
954             String value = parser.getAttributeValue( i );
955 
956             if ( name.indexOf( ':' ) >= 0 )
957             {
958                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
959             }
960             else if ( "type".equals( name ) )
961             {
962                 digestItem.setType( interpolatedTrimmed( value, "type" ) );
963             }
964             else if ( "hash".equals( name ) )
965             {
966                 digestItem.setHash( interpolatedTrimmed( value, "hash" ) );
967             }
968             else if ( "fileChecksum".equals( name ) )
969             {
970                 digestItem.setFileChecksum( interpolatedTrimmed( value, "fileChecksum" ) );
971             }
972             else if ( "content".equals( name ) )
973             {
974                 digestItem.setContent( interpolatedTrimmed( value, "content" ) );
975             }
976             else if ( "isText".equals( name ) )
977             {
978                 digestItem.setIsText( interpolatedTrimmed( value, "isText" ) );
979             }
980             else if ( "charset".equals( name ) )
981             {
982                 digestItem.setCharset( interpolatedTrimmed( value, "charset" ) );
983             }
984             else if ( "eol".equals( name ) )
985             {
986                 digestItem.setEol( interpolatedTrimmed( value, "eol" ) );
987             }
988             else
989             {
990                 checkUnknownAttribute( parser, name, tagName, strict );
991             }
992         }
993         digestItem.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
994         return digestItem;
995     } //-- DigestItem parseDigestItem( XmlPullParser, boolean )
996 
997     /**
998      * Method parseProjectsInputInfo.
999      * 
1000      * @param parser a parser object.
1001      * @param strict a strict object.
1002      * @throws IOException IOException if any.
1003      * @throws XmlPullParserException XmlPullParserException if
1004      * any.
1005      * @return ProjectsInputInfo
1006      */
1007     private ProjectsInputInfo parseProjectsInputInfo( XmlPullParser parser, boolean strict )
1008         throws IOException, XmlPullParserException
1009     {
1010         String tagName = parser.getName();
1011         ProjectsInputInfo projectsInputInfo = new ProjectsInputInfo();
1012         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1013         {
1014             String name = parser.getAttributeName( i );
1015             String value = parser.getAttributeValue( i );
1016 
1017             if ( name.indexOf( ':' ) >= 0 )
1018             {
1019                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1020             }
1021             else
1022             {
1023                 checkUnknownAttribute( parser, name, tagName, strict );
1024             }
1025         }
1026         java.util.Set parsed = new java.util.HashSet();
1027         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1028         {
1029             if ( checkFieldWithDuplicate( parser, "checksum", null, parsed ) )
1030             {
1031                 projectsInputInfo.setChecksum( interpolatedTrimmed( parser.nextText(), "checksum" ) );
1032             }
1033             else if ( checkFieldWithDuplicate( parser, "items", null, parsed ) )
1034             {
1035                 java.util.List<DigestItem> items = new java.util.ArrayList<DigestItem>();
1036                 while ( parser.nextTag() == XmlPullParser.START_TAG )
1037                 {
1038                     if ( "item".equals( parser.getName() ) )
1039                     {
1040                         items.add( parseDigestItem( parser, strict ) );
1041                     }
1042                     else
1043                     {
1044                         checkUnknownElement( parser, strict );
1045                     }
1046                 }
1047                 projectsInputInfo.setItems( items );
1048             }
1049             else
1050             {
1051                 checkUnknownElement( parser, strict );
1052             }
1053         }
1054         return projectsInputInfo;
1055     } //-- ProjectsInputInfo parseProjectsInputInfo( XmlPullParser, boolean )
1056 
1057     /**
1058      * Method parsePropertyValue.
1059      * 
1060      * @param parser a parser object.
1061      * @param strict a strict object.
1062      * @throws IOException IOException if any.
1063      * @throws XmlPullParserException XmlPullParserException if
1064      * any.
1065      * @return PropertyValue
1066      */
1067     private PropertyValue parsePropertyValue( XmlPullParser parser, boolean strict )
1068         throws IOException, XmlPullParserException
1069     {
1070         String tagName = parser.getName();
1071         PropertyValue propertyValue = new PropertyValue();
1072         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1073         {
1074             String name = parser.getAttributeName( i );
1075             String value = parser.getAttributeValue( i );
1076 
1077             if ( name.indexOf( ':' ) >= 0 )
1078             {
1079                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1080             }
1081             else if ( "name".equals( name ) )
1082             {
1083                 propertyValue.setName( interpolatedTrimmed( value, "name" ) );
1084             }
1085             else if ( "tracked".equals( name ) )
1086             {
1087                 propertyValue.setTracked( getBooleanValue( interpolatedTrimmed( value, "tracked" ), "tracked", parser, "null" ) );
1088             }
1089             else
1090             {
1091                 checkUnknownAttribute( parser, name, tagName, strict );
1092             }
1093         }
1094         propertyValue.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
1095         return propertyValue;
1096     } //-- PropertyValue parsePropertyValue( XmlPullParser, boolean )
1097 
1098     /**
1099      * Method parseScm.
1100      * 
1101      * @param parser a parser object.
1102      * @param strict a strict object.
1103      * @throws IOException IOException if any.
1104      * @throws XmlPullParserException XmlPullParserException if
1105      * any.
1106      * @return Scm
1107      */
1108     private Scm parseScm( XmlPullParser parser, boolean strict )
1109         throws IOException, XmlPullParserException
1110     {
1111         String tagName = parser.getName();
1112         Scm scm = new Scm();
1113         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1114         {
1115             String name = parser.getAttributeName( i );
1116             String value = parser.getAttributeValue( i );
1117 
1118             if ( name.indexOf( ':' ) >= 0 )
1119             {
1120                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1121             }
1122             else
1123             {
1124                 checkUnknownAttribute( parser, name, tagName, strict );
1125             }
1126         }
1127         java.util.Set parsed = new java.util.HashSet();
1128         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1129         {
1130             if ( checkFieldWithDuplicate( parser, "sourceBranch", null, parsed ) )
1131             {
1132                 scm.setSourceBranch( interpolatedTrimmed( parser.nextText(), "sourceBranch" ) );
1133             }
1134             else if ( checkFieldWithDuplicate( parser, "revision", null, parsed ) )
1135             {
1136                 scm.setRevision( interpolatedTrimmed( parser.nextText(), "revision" ) );
1137             }
1138             else
1139             {
1140                 checkUnknownElement( parser, strict );
1141             }
1142         }
1143         return scm;
1144     } //-- Scm parseScm( XmlPullParser, boolean )
1145 
1146     /**
1147      * Sets the state of the "add default entities" flag.
1148      * 
1149      * @param addDefaultEntities a addDefaultEntities object.
1150      */
1151     public void setAddDefaultEntities( boolean addDefaultEntities )
1152     {
1153         this.addDefaultEntities = addDefaultEntities;
1154     } //-- void setAddDefaultEntities( boolean )
1155 
1156     public static interface ContentTransformer
1157 {
1158     /**
1159      * Interpolate the value read from the xpp3 document
1160      * @param source The source value
1161      * @param fieldName A description of the field being interpolated. The implementation may use this to
1162      *                           log stuff.
1163      * @return The interpolated value.
1164      */
1165     String transform( String source, String fieldName );
1166 }
1167 
1168 }