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