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