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 if ( checkFieldWithDuplicate( parser, "isDirectory", null, parsed ) )
758             {
759                 artifact.setIsDirectory( getBooleanValue( interpolatedTrimmed( parser.nextText(), "isDirectory" ), "isDirectory", parser, "false" ) );
760             }
761             else
762             {
763                 checkUnknownElement( parser, strict );
764             }
765         }
766         return artifact;
767     } //-- Artifact parseArtifact( XmlPullParser, boolean )
768 
769     /**
770      * Method parseBuild.
771      * 
772      * @param parser a parser object.
773      * @param strict a strict object.
774      * @throws IOException IOException if any.
775      * @throws XmlPullParserException XmlPullParserException if
776      * any.
777      * @return Build
778      */
779     private Build parseBuild( XmlPullParser parser, boolean strict )
780         throws IOException, XmlPullParserException
781     {
782         String tagName = parser.getName();
783         Build build = new Build();
784         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
785         {
786             String name = parser.getAttributeName( i );
787             String value = parser.getAttributeValue( i );
788 
789             if ( name.indexOf( ':' ) >= 0 )
790             {
791                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
792             }
793             else if ( "xmlns".equals( name ) )
794             {
795                 // ignore xmlns attribute in root class, which is a reserved attribute name
796             }
797             else
798             {
799                 checkUnknownAttribute( parser, name, tagName, strict );
800             }
801         }
802         java.util.Set<String> parsed = new java.util.HashSet<String>();
803         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
804         {
805             if ( checkFieldWithDuplicate( parser, "cacheImplementationVersion", null, parsed ) )
806             {
807                 build.setCacheImplementationVersion( interpolatedTrimmed( parser.nextText(), "cacheImplementationVersion" ) );
808             }
809             else if ( checkFieldWithDuplicate( parser, "final", "final", parsed ) )
810             {
811                 build.set_final( getBooleanValue( interpolatedTrimmed( parser.nextText(), "final" ), "final", parser, "null" ) );
812             }
813             else if ( checkFieldWithDuplicate( parser, "hashFunction", null, parsed ) )
814             {
815                 build.setHashFunction( interpolatedTrimmed( parser.nextText(), "hashFunction" ) );
816             }
817             else if ( checkFieldWithDuplicate( parser, "buildTime", null, parsed ) )
818             {
819                 String dateFormat = null;
820                 build.setBuildTime( getDateValue( interpolatedTrimmed( parser.nextText(), "buildTime" ), "buildTime", dateFormat, parser ) );
821             }
822             else if ( checkFieldWithDuplicate( parser, "buildServer", null, parsed ) )
823             {
824                 build.setBuildServer( interpolatedTrimmed( parser.nextText(), "buildServer" ) );
825             }
826             else if ( checkFieldWithDuplicate( parser, "scm", null, parsed ) )
827             {
828                 build.setScm( parseScm( parser, strict ) );
829             }
830             else if ( checkFieldWithDuplicate( parser, "goals", null, parsed ) )
831             {
832                 java.util.List<String> goals = new java.util.ArrayList<String>();
833                 while ( parser.nextTag() == XmlPullParser.START_TAG )
834                 {
835                     if ( "goal".equals( parser.getName() ) )
836                     {
837                         goals.add( interpolatedTrimmed( parser.nextText(), "goals" ) );
838                     }
839                     else
840                     {
841                         checkUnknownElement( parser, strict );
842                     }
843                 }
844                 build.setGoals( goals );
845             }
846             else if ( checkFieldWithDuplicate( parser, "artifact", null, parsed ) )
847             {
848                 build.setArtifact( parseArtifact( parser, strict ) );
849             }
850             else if ( checkFieldWithDuplicate( parser, "attachedArtifacts", null, parsed ) )
851             {
852                 java.util.List<Artifact> attachedArtifacts = new java.util.ArrayList<Artifact>();
853                 while ( parser.nextTag() == XmlPullParser.START_TAG )
854                 {
855                     if ( "attachedArtifact".equals( parser.getName() ) )
856                     {
857                         attachedArtifacts.add( parseArtifact( parser, strict ) );
858                     }
859                     else
860                     {
861                         checkUnknownElement( parser, strict );
862                     }
863                 }
864                 build.setAttachedArtifacts( attachedArtifacts );
865             }
866             else if ( checkFieldWithDuplicate( parser, "executions", null, parsed ) )
867             {
868                 java.util.List<CompletedExecution> executions = new java.util.ArrayList<CompletedExecution>();
869                 while ( parser.nextTag() == XmlPullParser.START_TAG )
870                 {
871                     if ( "execution".equals( parser.getName() ) )
872                     {
873                         executions.add( parseCompletedExecution( parser, strict ) );
874                     }
875                     else
876                     {
877                         checkUnknownElement( parser, strict );
878                     }
879                 }
880                 build.setExecutions( executions );
881             }
882             else if ( checkFieldWithDuplicate( parser, "projectsInputInfo", null, parsed ) )
883             {
884                 build.setProjectsInputInfo( parseProjectsInputInfo( parser, strict ) );
885             }
886             else
887             {
888                 checkUnknownElement( parser, strict );
889             }
890         }
891         return build;
892     } //-- Build parseBuild( XmlPullParser, boolean )
893 
894     /**
895      * Method parseCompletedExecution.
896      * 
897      * @param parser a parser object.
898      * @param strict a strict object.
899      * @throws IOException IOException if any.
900      * @throws XmlPullParserException XmlPullParserException if
901      * any.
902      * @return CompletedExecution
903      */
904     private CompletedExecution parseCompletedExecution( XmlPullParser parser, boolean strict )
905         throws IOException, XmlPullParserException
906     {
907         String tagName = parser.getName();
908         CompletedExecution completedExecution = new CompletedExecution();
909         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
910         {
911             String name = parser.getAttributeName( i );
912             String value = parser.getAttributeValue( i );
913 
914             if ( name.indexOf( ':' ) >= 0 )
915             {
916                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
917             }
918             else
919             {
920                 checkUnknownAttribute( parser, name, tagName, strict );
921             }
922         }
923         java.util.Set<String> parsed = new java.util.HashSet<String>();
924         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
925         {
926             if ( checkFieldWithDuplicate( parser, "executionKey", null, parsed ) )
927             {
928                 completedExecution.setExecutionKey( interpolatedTrimmed( parser.nextText(), "executionKey" ) );
929             }
930             else if ( checkFieldWithDuplicate( parser, "mojoClassName", null, parsed ) )
931             {
932                 completedExecution.setMojoClassName( interpolatedTrimmed( parser.nextText(), "mojoClassName" ) );
933             }
934             else if ( checkFieldWithDuplicate( parser, "properties", null, parsed ) )
935             {
936                 java.util.List<PropertyValue> properties = new java.util.ArrayList<PropertyValue>();
937                 while ( parser.nextTag() == XmlPullParser.START_TAG )
938                 {
939                     if ( "property".equals( parser.getName() ) )
940                     {
941                         properties.add( parsePropertyValue( parser, strict ) );
942                     }
943                     else
944                     {
945                         checkUnknownElement( parser, strict );
946                     }
947                 }
948                 completedExecution.setProperties( properties );
949             }
950             else
951             {
952                 checkUnknownElement( parser, strict );
953             }
954         }
955         return completedExecution;
956     } //-- CompletedExecution parseCompletedExecution( XmlPullParser, boolean )
957 
958     /**
959      * Method parseDigestItem.
960      * 
961      * @param parser a parser object.
962      * @param strict a strict object.
963      * @throws IOException IOException if any.
964      * @throws XmlPullParserException XmlPullParserException if
965      * any.
966      * @return DigestItem
967      */
968     private DigestItem parseDigestItem( XmlPullParser parser, boolean strict )
969         throws IOException, XmlPullParserException
970     {
971         String tagName = parser.getName();
972         DigestItem digestItem = new DigestItem();
973         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
974         {
975             String name = parser.getAttributeName( i );
976             String value = parser.getAttributeValue( i );
977 
978             if ( name.indexOf( ':' ) >= 0 )
979             {
980                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
981             }
982             else if ( "type".equals( name ) )
983             {
984                 digestItem.setType( interpolatedTrimmed( value, "type" ) );
985             }
986             else if ( "hash".equals( name ) )
987             {
988                 digestItem.setHash( interpolatedTrimmed( value, "hash" ) );
989             }
990             else if ( "fileChecksum".equals( name ) )
991             {
992                 digestItem.setFileChecksum( interpolatedTrimmed( value, "fileChecksum" ) );
993             }
994             else if ( "content".equals( name ) )
995             {
996                 digestItem.setContent( interpolatedTrimmed( value, "content" ) );
997             }
998             else if ( "isText".equals( name ) )
999             {
1000                 digestItem.setIsText( interpolatedTrimmed( value, "isText" ) );
1001             }
1002             else if ( "charset".equals( name ) )
1003             {
1004                 digestItem.setCharset( interpolatedTrimmed( value, "charset" ) );
1005             }
1006             else if ( "eol".equals( name ) )
1007             {
1008                 digestItem.setEol( interpolatedTrimmed( value, "eol" ) );
1009             }
1010             else
1011             {
1012                 checkUnknownAttribute( parser, name, tagName, strict );
1013             }
1014         }
1015         digestItem.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
1016         return digestItem;
1017     } //-- DigestItem parseDigestItem( XmlPullParser, boolean )
1018 
1019     /**
1020      * Method parseProjectsInputInfo.
1021      * 
1022      * @param parser a parser object.
1023      * @param strict a strict object.
1024      * @throws IOException IOException if any.
1025      * @throws XmlPullParserException XmlPullParserException if
1026      * any.
1027      * @return ProjectsInputInfo
1028      */
1029     private ProjectsInputInfo parseProjectsInputInfo( XmlPullParser parser, boolean strict )
1030         throws IOException, XmlPullParserException
1031     {
1032         String tagName = parser.getName();
1033         ProjectsInputInfo projectsInputInfo = new ProjectsInputInfo();
1034         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1035         {
1036             String name = parser.getAttributeName( i );
1037             String value = parser.getAttributeValue( i );
1038 
1039             if ( name.indexOf( ':' ) >= 0 )
1040             {
1041                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1042             }
1043             else
1044             {
1045                 checkUnknownAttribute( parser, name, tagName, strict );
1046             }
1047         }
1048         java.util.Set<String> parsed = new java.util.HashSet<String>();
1049         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1050         {
1051             if ( checkFieldWithDuplicate( parser, "checksum", null, parsed ) )
1052             {
1053                 projectsInputInfo.setChecksum( interpolatedTrimmed( parser.nextText(), "checksum" ) );
1054             }
1055             else if ( checkFieldWithDuplicate( parser, "items", null, parsed ) )
1056             {
1057                 java.util.List<DigestItem> items = new java.util.ArrayList<DigestItem>();
1058                 while ( parser.nextTag() == XmlPullParser.START_TAG )
1059                 {
1060                     if ( "item".equals( parser.getName() ) )
1061                     {
1062                         items.add( parseDigestItem( parser, strict ) );
1063                     }
1064                     else
1065                     {
1066                         checkUnknownElement( parser, strict );
1067                     }
1068                 }
1069                 projectsInputInfo.setItems( items );
1070             }
1071             else
1072             {
1073                 checkUnknownElement( parser, strict );
1074             }
1075         }
1076         return projectsInputInfo;
1077     } //-- ProjectsInputInfo parseProjectsInputInfo( XmlPullParser, boolean )
1078 
1079     /**
1080      * Method parsePropertyValue.
1081      * 
1082      * @param parser a parser object.
1083      * @param strict a strict object.
1084      * @throws IOException IOException if any.
1085      * @throws XmlPullParserException XmlPullParserException if
1086      * any.
1087      * @return PropertyValue
1088      */
1089     private PropertyValue parsePropertyValue( XmlPullParser parser, boolean strict )
1090         throws IOException, XmlPullParserException
1091     {
1092         String tagName = parser.getName();
1093         PropertyValue propertyValue = new PropertyValue();
1094         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1095         {
1096             String name = parser.getAttributeName( i );
1097             String value = parser.getAttributeValue( i );
1098 
1099             if ( name.indexOf( ':' ) >= 0 )
1100             {
1101                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1102             }
1103             else if ( "name".equals( name ) )
1104             {
1105                 propertyValue.setName( interpolatedTrimmed( value, "name" ) );
1106             }
1107             else if ( "tracked".equals( name ) )
1108             {
1109                 propertyValue.setTracked( getBooleanValue( interpolatedTrimmed( value, "tracked" ), "tracked", parser, "null" ) );
1110             }
1111             else
1112             {
1113                 checkUnknownAttribute( parser, name, tagName, strict );
1114             }
1115         }
1116         propertyValue.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
1117         return propertyValue;
1118     } //-- PropertyValue parsePropertyValue( XmlPullParser, boolean )
1119 
1120     /**
1121      * Method parseScm.
1122      * 
1123      * @param parser a parser object.
1124      * @param strict a strict object.
1125      * @throws IOException IOException if any.
1126      * @throws XmlPullParserException XmlPullParserException if
1127      * any.
1128      * @return Scm
1129      */
1130     private Scm parseScm( XmlPullParser parser, boolean strict )
1131         throws IOException, XmlPullParserException
1132     {
1133         String tagName = parser.getName();
1134         Scm scm = new Scm();
1135         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1136         {
1137             String name = parser.getAttributeName( i );
1138             String value = parser.getAttributeValue( i );
1139 
1140             if ( name.indexOf( ':' ) >= 0 )
1141             {
1142                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1143             }
1144             else
1145             {
1146                 checkUnknownAttribute( parser, name, tagName, strict );
1147             }
1148         }
1149         java.util.Set<String> parsed = new java.util.HashSet<String>();
1150         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1151         {
1152             if ( checkFieldWithDuplicate( parser, "sourceBranch", null, parsed ) )
1153             {
1154                 scm.setSourceBranch( interpolatedTrimmed( parser.nextText(), "sourceBranch" ) );
1155             }
1156             else if ( checkFieldWithDuplicate( parser, "revision", null, parsed ) )
1157             {
1158                 scm.setRevision( interpolatedTrimmed( parser.nextText(), "revision" ) );
1159             }
1160             else
1161             {
1162                 checkUnknownElement( parser, strict );
1163             }
1164         }
1165         return scm;
1166     } //-- Scm parseScm( XmlPullParser, boolean )
1167 
1168     /**
1169      * Sets the state of the "add default entities" flag.
1170      * 
1171      * @param addDefaultEntities a addDefaultEntities object.
1172      */
1173     public void setAddDefaultEntities( boolean addDefaultEntities )
1174     {
1175         this.addDefaultEntities = addDefaultEntities;
1176     } //-- void setAddDefaultEntities( boolean )
1177 
1178     public static interface ContentTransformer
1179 {
1180     /**
1181      * Interpolate the value read from the xpp3 document
1182      * @param source The source value
1183      * @param fieldName A description of the field being interpolated. The implementation may use this to
1184      *                           log stuff.
1185      * @return The interpolated value.
1186      */
1187     String transform( String source, String fieldName );
1188 }
1189 
1190 }