View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 2.0.0,
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      * @see ReaderFactory#newXmlReader
562      * 
563      * @param reader a reader 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( Reader reader, boolean strict )
571         throws IOException, XmlPullParserException
572     {
573         XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
574 
575         parser.setInput( reader );
576 
577 
578         return read( parser, strict );
579     } //-- ProfilesRoot read( Reader, boolean )
580 
581     /**
582      * @see ReaderFactory#newXmlReader
583      * 
584      * @param reader a reader object.
585      * @throws IOException IOException if any.
586      * @throws XmlPullParserException XmlPullParserException if
587      * any.
588      * @return ProfilesRoot
589      */
590     public ProfilesRoot read( Reader reader )
591         throws IOException, XmlPullParserException
592     {
593         return read( reader, true );
594     } //-- ProfilesRoot read( Reader )
595 
596     /**
597      * Method read.
598      * 
599      * @param in a in object.
600      * @param strict a strict object.
601      * @throws IOException IOException if any.
602      * @throws XmlPullParserException XmlPullParserException if
603      * any.
604      * @return ProfilesRoot
605      */
606     public ProfilesRoot read( InputStream in, boolean strict )
607         throws IOException, XmlPullParserException
608     {
609         return read( ReaderFactory.newXmlReader( in ), strict );
610     } //-- ProfilesRoot read( InputStream, boolean )
611 
612     /**
613      * Method read.
614      * 
615      * @param in a in object.
616      * @throws IOException IOException if any.
617      * @throws XmlPullParserException XmlPullParserException if
618      * any.
619      * @return ProfilesRoot
620      */
621     public ProfilesRoot read( InputStream in )
622         throws IOException, XmlPullParserException
623     {
624         return read( ReaderFactory.newXmlReader( in ) );
625     } //-- ProfilesRoot read( InputStream )
626 
627     /**
628      * Method parseActivation.
629      * 
630      * @param parser a parser object.
631      * @param strict a strict object.
632      * @throws IOException IOException if any.
633      * @throws XmlPullParserException XmlPullParserException if
634      * any.
635      * @return Activation
636      */
637     private Activation parseActivation( XmlPullParser parser, boolean strict )
638         throws IOException, XmlPullParserException
639     {
640         String tagName = parser.getName();
641         Activation activation = new Activation();
642         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
643         {
644             String name = parser.getAttributeName( i );
645             String value = parser.getAttributeValue( i );
646 
647             if ( name.indexOf( ':' ) >= 0 )
648             {
649                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
650             }
651             else
652             {
653                 checkUnknownAttribute( parser, name, tagName, strict );
654             }
655         }
656         java.util.Set parsed = new java.util.HashSet();
657         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
658         {
659             if ( checkFieldWithDuplicate( parser, "activeByDefault", null, parsed ) )
660             {
661                 activation.setActiveByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "activeByDefault" ), "activeByDefault", parser, "false" ) );
662             }
663             else if ( checkFieldWithDuplicate( parser, "jdk", null, parsed ) )
664             {
665                 activation.setJdk( interpolatedTrimmed( parser.nextText(), "jdk" ) );
666             }
667             else if ( checkFieldWithDuplicate( parser, "os", null, parsed ) )
668             {
669                 activation.setOs( parseActivationOS( parser, strict ) );
670             }
671             else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) )
672             {
673                 activation.setProperty( parseActivationProperty( parser, strict ) );
674             }
675             else if ( checkFieldWithDuplicate( parser, "file", null, parsed ) )
676             {
677                 activation.setFile( parseActivationFile( parser, strict ) );
678             }
679             else
680             {
681                 checkUnknownElement( parser, strict );
682             }
683         }
684         return activation;
685     } //-- Activation parseActivation( XmlPullParser, boolean )
686 
687     /**
688      * Method parseActivationFile.
689      * 
690      * @param parser a parser object.
691      * @param strict a strict object.
692      * @throws IOException IOException if any.
693      * @throws XmlPullParserException XmlPullParserException if
694      * any.
695      * @return ActivationFile
696      */
697     private ActivationFile parseActivationFile( XmlPullParser parser, boolean strict )
698         throws IOException, XmlPullParserException
699     {
700         String tagName = parser.getName();
701         ActivationFile activationFile = new ActivationFile();
702         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
703         {
704             String name = parser.getAttributeName( i );
705             String value = parser.getAttributeValue( i );
706 
707             if ( name.indexOf( ':' ) >= 0 )
708             {
709                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
710             }
711             else
712             {
713                 checkUnknownAttribute( parser, name, tagName, strict );
714             }
715         }
716         java.util.Set parsed = new java.util.HashSet();
717         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
718         {
719             if ( checkFieldWithDuplicate( parser, "missing", null, parsed ) )
720             {
721                 activationFile.setMissing( interpolatedTrimmed( parser.nextText(), "missing" ) );
722             }
723             else if ( checkFieldWithDuplicate( parser, "exists", null, parsed ) )
724             {
725                 activationFile.setExists( interpolatedTrimmed( parser.nextText(), "exists" ) );
726             }
727             else
728             {
729                 checkUnknownElement( parser, strict );
730             }
731         }
732         return activationFile;
733     } //-- ActivationFile parseActivationFile( XmlPullParser, boolean )
734 
735     /**
736      * Method parseActivationOS.
737      * 
738      * @param parser a parser object.
739      * @param strict a strict object.
740      * @throws IOException IOException if any.
741      * @throws XmlPullParserException XmlPullParserException if
742      * any.
743      * @return ActivationOS
744      */
745     private ActivationOS parseActivationOS( XmlPullParser parser, boolean strict )
746         throws IOException, XmlPullParserException
747     {
748         String tagName = parser.getName();
749         ActivationOS activationOS = new ActivationOS();
750         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
751         {
752             String name = parser.getAttributeName( i );
753             String value = parser.getAttributeValue( i );
754 
755             if ( name.indexOf( ':' ) >= 0 )
756             {
757                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
758             }
759             else
760             {
761                 checkUnknownAttribute( parser, name, tagName, strict );
762             }
763         }
764         java.util.Set parsed = new java.util.HashSet();
765         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
766         {
767             if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
768             {
769                 activationOS.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
770             }
771             else if ( checkFieldWithDuplicate( parser, "family", null, parsed ) )
772             {
773                 activationOS.setFamily( interpolatedTrimmed( parser.nextText(), "family" ) );
774             }
775             else if ( checkFieldWithDuplicate( parser, "arch", null, parsed ) )
776             {
777                 activationOS.setArch( interpolatedTrimmed( parser.nextText(), "arch" ) );
778             }
779             else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
780             {
781                 activationOS.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) );
782             }
783             else
784             {
785                 checkUnknownElement( parser, strict );
786             }
787         }
788         return activationOS;
789     } //-- ActivationOS parseActivationOS( XmlPullParser, boolean )
790 
791     /**
792      * Method parseActivationProperty.
793      * 
794      * @param parser a parser object.
795      * @param strict a strict object.
796      * @throws IOException IOException if any.
797      * @throws XmlPullParserException XmlPullParserException if
798      * any.
799      * @return ActivationProperty
800      */
801     private ActivationProperty parseActivationProperty( XmlPullParser parser, boolean strict )
802         throws IOException, XmlPullParserException
803     {
804         String tagName = parser.getName();
805         ActivationProperty activationProperty = new ActivationProperty();
806         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
807         {
808             String name = parser.getAttributeName( i );
809             String value = parser.getAttributeValue( i );
810 
811             if ( name.indexOf( ':' ) >= 0 )
812             {
813                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
814             }
815             else
816             {
817                 checkUnknownAttribute( parser, name, tagName, strict );
818             }
819         }
820         java.util.Set parsed = new java.util.HashSet();
821         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
822         {
823             if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
824             {
825                 activationProperty.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
826             }
827             else if ( checkFieldWithDuplicate( parser, "value", null, parsed ) )
828             {
829                 activationProperty.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
830             }
831             else
832             {
833                 checkUnknownElement( parser, strict );
834             }
835         }
836         return activationProperty;
837     } //-- ActivationProperty parseActivationProperty( XmlPullParser, boolean )
838 
839     /**
840      * Method parseProfile.
841      * 
842      * @param parser a parser object.
843      * @param strict a strict object.
844      * @throws IOException IOException if any.
845      * @throws XmlPullParserException XmlPullParserException if
846      * any.
847      * @return Profile
848      */
849     private Profile parseProfile( XmlPullParser parser, boolean strict )
850         throws IOException, XmlPullParserException
851     {
852         String tagName = parser.getName();
853         Profile profile = new Profile();
854         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
855         {
856             String name = parser.getAttributeName( i );
857             String value = parser.getAttributeValue( i );
858 
859             if ( name.indexOf( ':' ) >= 0 )
860             {
861                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
862             }
863             else
864             {
865                 checkUnknownAttribute( parser, name, tagName, strict );
866             }
867         }
868         java.util.Set parsed = new java.util.HashSet();
869         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
870         {
871             if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
872             {
873                 profile.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
874             }
875             else if ( checkFieldWithDuplicate( parser, "activation", null, parsed ) )
876             {
877                 profile.setActivation( parseActivation( parser, strict ) );
878             }
879             else if ( checkFieldWithDuplicate( parser, "properties", null, parsed ) )
880             {
881                 while ( parser.nextTag() == XmlPullParser.START_TAG )
882                 {
883                     String key = parser.getName();
884                     String value = parser.nextText().trim();
885                     profile.addProperty( key, value );
886                 }
887             }
888             else if ( checkFieldWithDuplicate( parser, "repositories", null, parsed ) )
889             {
890                 java.util.List<Repository> repositories = new java.util.ArrayList<Repository>();
891                 profile.setRepositories( repositories );
892                 while ( parser.nextTag() == XmlPullParser.START_TAG )
893                 {
894                     if ( "repository".equals( parser.getName() ) )
895                     {
896                         repositories.add( parseRepository( parser, strict ) );
897                     }
898                     else
899                     {
900                         checkUnknownElement( parser, strict );
901                     }
902                 }
903             }
904             else if ( checkFieldWithDuplicate( parser, "pluginRepositories", null, parsed ) )
905             {
906                 java.util.List<Repository> pluginRepositories = new java.util.ArrayList<Repository>();
907                 profile.setPluginRepositories( pluginRepositories );
908                 while ( parser.nextTag() == XmlPullParser.START_TAG )
909                 {
910                     if ( "pluginRepository".equals( parser.getName() ) )
911                     {
912                         pluginRepositories.add( parseRepository( parser, strict ) );
913                     }
914                     else
915                     {
916                         checkUnknownElement( parser, strict );
917                     }
918                 }
919             }
920             else
921             {
922                 checkUnknownElement( parser, strict );
923             }
924         }
925         return profile;
926     } //-- Profile parseProfile( XmlPullParser, boolean )
927 
928     /**
929      * Method parseProfilesRoot.
930      * 
931      * @param parser a parser object.
932      * @param strict a strict object.
933      * @throws IOException IOException if any.
934      * @throws XmlPullParserException XmlPullParserException if
935      * any.
936      * @return ProfilesRoot
937      */
938     private ProfilesRoot parseProfilesRoot( XmlPullParser parser, boolean strict )
939         throws IOException, XmlPullParserException
940     {
941         String tagName = parser.getName();
942         ProfilesRoot profilesRoot = new ProfilesRoot();
943         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
944         {
945             String name = parser.getAttributeName( i );
946             String value = parser.getAttributeValue( i );
947 
948             if ( name.indexOf( ':' ) >= 0 )
949             {
950                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
951             }
952             else if ( "xmlns".equals( name ) )
953             {
954                 // ignore xmlns attribute in root class, which is a reserved attribute name
955             }
956             else
957             {
958                 checkUnknownAttribute( parser, name, tagName, strict );
959             }
960         }
961         java.util.Set parsed = new java.util.HashSet();
962         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
963         {
964             if ( checkFieldWithDuplicate( parser, "profiles", null, parsed ) )
965             {
966                 java.util.List<Profile> profiles = new java.util.ArrayList<Profile>();
967                 profilesRoot.setProfiles( profiles );
968                 while ( parser.nextTag() == XmlPullParser.START_TAG )
969                 {
970                     if ( "profile".equals( parser.getName() ) )
971                     {
972                         profiles.add( parseProfile( parser, strict ) );
973                     }
974                     else
975                     {
976                         checkUnknownElement( parser, strict );
977                     }
978                 }
979             }
980             else if ( checkFieldWithDuplicate( parser, "activeProfiles", null, parsed ) )
981             {
982                 java.util.List<String> activeProfiles = new java.util.ArrayList<String>();
983                 profilesRoot.setActiveProfiles( activeProfiles );
984                 while ( parser.nextTag() == XmlPullParser.START_TAG )
985                 {
986                     if ( "activeProfile".equals( parser.getName() ) )
987                     {
988                         activeProfiles.add( interpolatedTrimmed( parser.nextText(), "activeProfiles" ) );
989                     }
990                     else
991                     {
992                         checkUnknownElement( parser, strict );
993                     }
994                 }
995             }
996             else
997             {
998                 checkUnknownElement( parser, strict );
999             }
1000         }
1001         return profilesRoot;
1002     } //-- ProfilesRoot parseProfilesRoot( XmlPullParser, boolean )
1003 
1004     /**
1005      * Method parseRepository.
1006      * 
1007      * @param parser a parser object.
1008      * @param strict a strict object.
1009      * @throws IOException IOException if any.
1010      * @throws XmlPullParserException XmlPullParserException if
1011      * any.
1012      * @return Repository
1013      */
1014     private Repository parseRepository( XmlPullParser parser, boolean strict )
1015         throws IOException, XmlPullParserException
1016     {
1017         String tagName = parser.getName();
1018         Repository repository = new Repository();
1019         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1020         {
1021             String name = parser.getAttributeName( i );
1022             String value = parser.getAttributeValue( i );
1023 
1024             if ( name.indexOf( ':' ) >= 0 )
1025             {
1026                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1027             }
1028             else
1029             {
1030                 checkUnknownAttribute( parser, name, tagName, strict );
1031             }
1032         }
1033         java.util.Set parsed = new java.util.HashSet();
1034         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1035         {
1036             if ( checkFieldWithDuplicate( parser, "releases", null, parsed ) )
1037             {
1038                 repository.setReleases( parseRepositoryPolicy( parser, strict ) );
1039             }
1040             else if ( checkFieldWithDuplicate( parser, "snapshots", null, parsed ) )
1041             {
1042                 repository.setSnapshots( parseRepositoryPolicy( parser, strict ) );
1043             }
1044             else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1045             {
1046                 repository.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1047             }
1048             else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1049             {
1050                 repository.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1051             }
1052             else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1053             {
1054                 repository.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1055             }
1056             else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1057             {
1058                 repository.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1059             }
1060             else
1061             {
1062                 checkUnknownElement( parser, strict );
1063             }
1064         }
1065         return repository;
1066     } //-- Repository parseRepository( XmlPullParser, boolean )
1067 
1068     /**
1069      * Method parseRepositoryBase.
1070      * 
1071      * @param parser a parser object.
1072      * @param strict a strict object.
1073      * @throws IOException IOException if any.
1074      * @throws XmlPullParserException XmlPullParserException if
1075      * any.
1076      * @return RepositoryBase
1077      */
1078     private RepositoryBase parseRepositoryBase( XmlPullParser parser, boolean strict )
1079         throws IOException, XmlPullParserException
1080     {
1081         String tagName = parser.getName();
1082         RepositoryBase repositoryBase = new RepositoryBase();
1083         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1084         {
1085             String name = parser.getAttributeName( i );
1086             String value = parser.getAttributeValue( i );
1087 
1088             if ( name.indexOf( ':' ) >= 0 )
1089             {
1090                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1091             }
1092             else
1093             {
1094                 checkUnknownAttribute( parser, name, tagName, strict );
1095             }
1096         }
1097         java.util.Set parsed = new java.util.HashSet();
1098         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1099         {
1100             if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1101             {
1102                 repositoryBase.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1103             }
1104             else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1105             {
1106                 repositoryBase.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1107             }
1108             else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1109             {
1110                 repositoryBase.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1111             }
1112             else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1113             {
1114                 repositoryBase.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1115             }
1116             else
1117             {
1118                 checkUnknownElement( parser, strict );
1119             }
1120         }
1121         return repositoryBase;
1122     } //-- RepositoryBase parseRepositoryBase( XmlPullParser, boolean )
1123 
1124     /**
1125      * Method parseRepositoryPolicy.
1126      * 
1127      * @param parser a parser object.
1128      * @param strict a strict object.
1129      * @throws IOException IOException if any.
1130      * @throws XmlPullParserException XmlPullParserException if
1131      * any.
1132      * @return RepositoryPolicy
1133      */
1134     private RepositoryPolicy parseRepositoryPolicy( XmlPullParser parser, boolean strict )
1135         throws IOException, XmlPullParserException
1136     {
1137         String tagName = parser.getName();
1138         RepositoryPolicy repositoryPolicy = new RepositoryPolicy();
1139         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1140         {
1141             String name = parser.getAttributeName( i );
1142             String value = parser.getAttributeValue( i );
1143 
1144             if ( name.indexOf( ':' ) >= 0 )
1145             {
1146                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1147             }
1148             else
1149             {
1150                 checkUnknownAttribute( parser, name, tagName, strict );
1151             }
1152         }
1153         java.util.Set parsed = new java.util.HashSet();
1154         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1155         {
1156             if ( checkFieldWithDuplicate( parser, "enabled", null, parsed ) )
1157             {
1158                 repositoryPolicy.setEnabled( getBooleanValue( interpolatedTrimmed( parser.nextText(), "enabled" ), "enabled", parser, "true" ) );
1159             }
1160             else if ( checkFieldWithDuplicate( parser, "updatePolicy", null, parsed ) )
1161             {
1162                 repositoryPolicy.setUpdatePolicy( interpolatedTrimmed( parser.nextText(), "updatePolicy" ) );
1163             }
1164             else if ( checkFieldWithDuplicate( parser, "checksumPolicy", null, parsed ) )
1165             {
1166                 repositoryPolicy.setChecksumPolicy( interpolatedTrimmed( parser.nextText(), "checksumPolicy" ) );
1167             }
1168             else
1169             {
1170                 checkUnknownElement( parser, strict );
1171             }
1172         }
1173         return repositoryPolicy;
1174     } //-- RepositoryPolicy parseRepositoryPolicy( XmlPullParser, boolean )
1175 
1176     /**
1177      * Method read.
1178      * 
1179      * @param parser a parser object.
1180      * @param strict a strict object.
1181      * @throws IOException IOException if any.
1182      * @throws XmlPullParserException XmlPullParserException if
1183      * any.
1184      * @return ProfilesRoot
1185      */
1186     private ProfilesRoot read( XmlPullParser parser, boolean strict )
1187         throws IOException, XmlPullParserException
1188     {
1189         ProfilesRoot profilesRoot = null;
1190         int eventType = parser.getEventType();
1191         boolean parsed = false;
1192         while ( eventType != XmlPullParser.END_DOCUMENT )
1193         {
1194             if ( eventType == XmlPullParser.START_TAG )
1195             {
1196                 if ( strict && ! "profilesXml".equals( parser.getName() ) )
1197                 {
1198                     throw new XmlPullParserException( "Expected root element 'profilesXml' but found '" + parser.getName() + "'", parser, null );
1199                 }
1200                 else if ( parsed )
1201                 {
1202                     // fallback, already expected a XmlPullParserException due to invalid XML
1203                     throw new XmlPullParserException( "Duplicated tag: 'profilesXml'", parser, null );
1204                 }
1205                 profilesRoot = parseProfilesRoot( parser, strict );
1206                 profilesRoot.setModelEncoding( parser.getInputEncoding() );
1207                 parsed = true;
1208             }
1209             eventType = parser.next();
1210         }
1211         if ( parsed )
1212         {
1213             return profilesRoot;
1214         }
1215         throw new XmlPullParserException( "Expected root element 'profilesXml' but found no element at all: invalid XML document", parser, null );
1216     } //-- ProfilesRoot read( 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 }