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