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