001// =================== DO NOT EDIT THIS FILE ====================
002// Generated by Modello 1.8.1,
003// any modifications will be overwritten.
004// ==============================================================
005
006package org.apache.maven.artifact.repository.metadata.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.artifact.repository.metadata.Metadata;
017import org.apache.maven.artifact.repository.metadata.Plugin;
018import org.apache.maven.artifact.repository.metadata.Snapshot;
019import org.apache.maven.artifact.repository.metadata.SnapshotVersion;
020import org.apache.maven.artifact.repository.metadata.Versioning;
021import org.codehaus.plexus.util.ReaderFactory;
022import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
023import org.codehaus.plexus.util.xml.pull.MXParser;
024import org.codehaus.plexus.util.xml.pull.XmlPullParser;
025import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
026
027/**
028 * Class MetadataXpp3Reader.
029 * 
030 * @version $Revision$ $Date$
031 */
032@SuppressWarnings( "all" )
033public class MetadataXpp3Reader
034{
035
036      //--------------------------/
037     //- Class/Member Variables -/
038    //--------------------------/
039
040    /**
041     * If set the parser will be loaded with all single characters
042     * from the XHTML specification.
043     * The entities used:
044     * <ul>
045     * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
046     * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
047     * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
048     * </ul>
049     */
050    private boolean addDefaultEntities = true;
051
052
053      //-----------/
054     //- Methods -/
055    //-----------/
056
057    /**
058     * Method checkFieldWithDuplicate.
059     * 
060     * @param parser
061     * @param parsed
062     * @param alias
063     * @param tagName
064     * @throws XmlPullParserException
065     * @return boolean
066     */
067    private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
068        throws XmlPullParserException
069    {
070        if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
071        {
072            return false;
073        }
074        if ( !parsed.add( tagName ) )
075        {
076            throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
077        }
078        return true;
079    } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set )
080
081    /**
082     * Method checkUnknownAttribute.
083     * 
084     * @param parser
085     * @param strict
086     * @param tagName
087     * @param attribute
088     * @throws XmlPullParserException
089     * @throws IOException
090     */
091    private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
092        throws XmlPullParserException, IOException
093    {
094        // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
095        if ( strict )
096        {
097            throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
098        }
099    } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
100
101    /**
102     * Method checkUnknownElement.
103     * 
104     * @param parser
105     * @param strict
106     * @throws XmlPullParserException
107     * @throws IOException
108     */
109    private void checkUnknownElement( XmlPullParser parser, boolean strict )
110        throws XmlPullParserException, IOException
111    {
112        if ( strict )
113        {
114            throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
115        }
116
117        for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
118        {
119            int eventType = parser.next();
120            if ( eventType == XmlPullParser.START_TAG )
121            {
122                unrecognizedTagCount++;
123            }
124            else if ( eventType == XmlPullParser.END_TAG )
125            {
126                unrecognizedTagCount--;
127            }
128        }
129    } //-- void checkUnknownElement( XmlPullParser, boolean )
130
131    /**
132     * Returns the state of the "add default entities" flag.
133     * 
134     * @return boolean
135     */
136    public boolean getAddDefaultEntities()
137    {
138        return addDefaultEntities;
139    } //-- boolean getAddDefaultEntities()
140
141    /**
142     * Method getBooleanValue.
143     * 
144     * @param s
145     * @param parser
146     * @param attribute
147     * @throws XmlPullParserException
148     * @return boolean
149     */
150    private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
151        throws XmlPullParserException
152    {
153        return getBooleanValue( s, attribute, parser, null );
154    } //-- boolean getBooleanValue( String, String, XmlPullParser )
155
156    /**
157     * Method getBooleanValue.
158     * 
159     * @param s
160     * @param defaultValue
161     * @param parser
162     * @param attribute
163     * @throws XmlPullParserException
164     * @return boolean
165     */
166    private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
167        throws XmlPullParserException
168    {
169        if ( s != null && s.length() != 0 )
170        {
171            return Boolean.valueOf( s ).booleanValue();
172        }
173        if ( defaultValue != null )
174        {
175            return Boolean.valueOf( defaultValue ).booleanValue();
176        }
177        return false;
178    } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
179
180    /**
181     * Method getByteValue.
182     * 
183     * @param s
184     * @param strict
185     * @param parser
186     * @param attribute
187     * @throws XmlPullParserException
188     * @return byte
189     */
190    private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
191        throws XmlPullParserException
192    {
193        if ( s != null )
194        {
195            try
196            {
197                return Byte.valueOf( s ).byteValue();
198            }
199            catch ( NumberFormatException nfe )
200            {
201                if ( strict )
202                {
203                    throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
204                }
205            }
206        }
207        return 0;
208    } //-- byte getByteValue( String, String, XmlPullParser, boolean )
209
210    /**
211     * Method getCharacterValue.
212     * 
213     * @param s
214     * @param parser
215     * @param attribute
216     * @throws XmlPullParserException
217     * @return char
218     */
219    private char getCharacterValue( String s, String attribute, XmlPullParser parser )
220        throws XmlPullParserException
221    {
222        if ( s != null )
223        {
224            return s.charAt( 0 );
225        }
226        return 0;
227    } //-- char getCharacterValue( String, String, XmlPullParser )
228
229    /**
230     * Method getDateValue.
231     * 
232     * @param s
233     * @param parser
234     * @param attribute
235     * @throws XmlPullParserException
236     * @return Date
237     */
238    private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
239        throws XmlPullParserException
240    {
241        return getDateValue( s, attribute, null, parser );
242    } //-- java.util.Date getDateValue( String, String, XmlPullParser )
243
244    /**
245     * Method getDateValue.
246     * 
247     * @param s
248     * @param parser
249     * @param dateFormat
250     * @param attribute
251     * @throws XmlPullParserException
252     * @return Date
253     */
254    private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
255        throws XmlPullParserException
256    {
257        if ( s != null )
258        {
259            String effectiveDateFormat = dateFormat;
260            if ( dateFormat == null )
261            {
262                effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
263            }
264            if ( "long".equals( effectiveDateFormat ) )
265            {
266                try
267                {
268                    return new java.util.Date( Long.parseLong( s ) );
269                }
270                catch ( NumberFormatException e )
271                {
272                    throw new XmlPullParserException( e.getMessage(), parser, e );
273                }
274            }
275            else
276            {
277                try
278                {
279                    DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
280                    return dateParser.parse( s );
281                }
282                catch ( java.text.ParseException e )
283                {
284                    throw new XmlPullParserException( e.getMessage(), parser, e );
285                }
286            }
287        }
288        return null;
289    } //-- java.util.Date getDateValue( String, String, String, XmlPullParser )
290
291    /**
292     * Method getDoubleValue.
293     * 
294     * @param s
295     * @param strict
296     * @param parser
297     * @param attribute
298     * @throws XmlPullParserException
299     * @return double
300     */
301    private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
302        throws XmlPullParserException
303    {
304        if ( s != null )
305        {
306            try
307            {
308                return Double.valueOf( s ).doubleValue();
309            }
310            catch ( NumberFormatException nfe )
311            {
312                if ( strict )
313                {
314                    throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
315                }
316            }
317        }
318        return 0;
319    } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
320
321    /**
322     * Method getFloatValue.
323     * 
324     * @param s
325     * @param strict
326     * @param parser
327     * @param attribute
328     * @throws XmlPullParserException
329     * @return float
330     */
331    private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
332        throws XmlPullParserException
333    {
334        if ( s != null )
335        {
336            try
337            {
338                return Float.valueOf( s ).floatValue();
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    } //-- float getFloatValue( String, String, XmlPullParser, boolean )
350
351    /**
352     * Method getIntegerValue.
353     * 
354     * @param s
355     * @param strict
356     * @param parser
357     * @param attribute
358     * @throws XmlPullParserException
359     * @return int
360     */
361    private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
362        throws XmlPullParserException
363    {
364        if ( s != null )
365        {
366            try
367            {
368                return Integer.valueOf( s ).intValue();
369            }
370            catch ( NumberFormatException nfe )
371            {
372                if ( strict )
373                {
374                    throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
375                }
376            }
377        }
378        return 0;
379    } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
380
381    /**
382     * Method getLongValue.
383     * 
384     * @param s
385     * @param strict
386     * @param parser
387     * @param attribute
388     * @throws XmlPullParserException
389     * @return long
390     */
391    private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
392        throws XmlPullParserException
393    {
394        if ( s != null )
395        {
396            try
397            {
398                return Long.valueOf( s ).longValue();
399            }
400            catch ( NumberFormatException nfe )
401            {
402                if ( strict )
403                {
404                    throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
405                }
406            }
407        }
408        return 0;
409    } //-- long getLongValue( String, String, XmlPullParser, boolean )
410
411    /**
412     * Method getRequiredAttributeValue.
413     * 
414     * @param s
415     * @param strict
416     * @param parser
417     * @param attribute
418     * @throws XmlPullParserException
419     * @return String
420     */
421    private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
422        throws XmlPullParserException
423    {
424        if ( s == null )
425        {
426            if ( strict )
427            {
428                throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
429            }
430        }
431        return s;
432    } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
433
434    /**
435     * Method getShortValue.
436     * 
437     * @param s
438     * @param strict
439     * @param parser
440     * @param attribute
441     * @throws XmlPullParserException
442     * @return short
443     */
444    private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
445        throws XmlPullParserException
446    {
447        if ( s != null )
448        {
449            try
450            {
451                return Short.valueOf( s ).shortValue();
452            }
453            catch ( NumberFormatException nfe )
454            {
455                if ( strict )
456                {
457                    throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
458                }
459            }
460        }
461        return 0;
462    } //-- short getShortValue( String, String, XmlPullParser, boolean )
463
464    /**
465     * Method getTrimmedValue.
466     * 
467     * @param s
468     * @return String
469     */
470    private String getTrimmedValue( String s )
471    {
472        if ( s != null )
473        {
474            s = s.trim();
475        }
476        return s;
477    } //-- String getTrimmedValue( String )
478
479    /**
480     * Method nextTag.
481     * 
482     * @param parser
483     * @throws IOException
484     * @throws XmlPullParserException
485     * @return int
486     */
487    private int nextTag( XmlPullParser parser )
488        throws IOException, XmlPullParserException
489    {
490        int eventType = parser.next();
491        if ( eventType == XmlPullParser.TEXT )
492        {
493            eventType = parser.next();
494        }
495        if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
496        {
497            throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
498        }
499        return eventType;
500    } //-- int nextTag( XmlPullParser )
501
502    /**
503     * @see ReaderFactory#newXmlReader
504     * 
505     * @param reader
506     * @param strict
507     * @throws IOException
508     * @throws XmlPullParserException
509     * @return Metadata
510     */
511    public Metadata read( Reader reader, boolean strict )
512        throws IOException, XmlPullParserException
513    {
514        XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
515
516        parser.setInput( reader );
517
518
519        return read( parser, strict );
520    } //-- Metadata read( Reader, boolean )
521
522    /**
523     * @see ReaderFactory#newXmlReader
524     * 
525     * @param reader
526     * @throws IOException
527     * @throws XmlPullParserException
528     * @return Metadata
529     */
530    public Metadata read( Reader reader )
531        throws IOException, XmlPullParserException
532    {
533        return read( reader, true );
534    } //-- Metadata read( Reader )
535
536    /**
537     * Method read.
538     * 
539     * @param in
540     * @param strict
541     * @throws IOException
542     * @throws XmlPullParserException
543     * @return Metadata
544     */
545    public Metadata read( InputStream in, boolean strict )
546        throws IOException, XmlPullParserException
547    {
548        return read( ReaderFactory.newXmlReader( in ), strict );
549    } //-- Metadata read( InputStream, boolean )
550
551    /**
552     * Method read.
553     * 
554     * @param in
555     * @throws IOException
556     * @throws XmlPullParserException
557     * @return Metadata
558     */
559    public Metadata read( InputStream in )
560        throws IOException, XmlPullParserException
561    {
562        return read( ReaderFactory.newXmlReader( in ) );
563    } //-- Metadata read( InputStream )
564
565    /**
566     * Method parseMetadata.
567     * 
568     * @param parser
569     * @param strict
570     * @throws IOException
571     * @throws XmlPullParserException
572     * @return Metadata
573     */
574    private Metadata parseMetadata( XmlPullParser parser, boolean strict )
575        throws IOException, XmlPullParserException
576    {
577        String tagName = parser.getName();
578        Metadata metadata = new Metadata();
579        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
580        {
581            String name = parser.getAttributeName( i );
582            String value = parser.getAttributeValue( i );
583
584            if ( name.indexOf( ':' ) >= 0 )
585            {
586                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
587            }
588            else if ( "xmlns".equals( name ) )
589            {
590                // ignore xmlns attribute in root class, which is a reserved attribute name
591            }
592            else if ( "modelVersion".equals( name ) )
593            {
594                metadata.setModelVersion( getTrimmedValue( value ) );
595            }
596            else
597            {
598                checkUnknownAttribute( parser, name, tagName, strict );
599            }
600        }
601        java.util.Set parsed = new java.util.HashSet();
602        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
603        {
604            if ( checkFieldWithDuplicate( parser, "groupId", null, parsed ) )
605            {
606                metadata.setGroupId( getTrimmedValue( parser.nextText() ) );
607            }
608            else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) )
609            {
610                metadata.setArtifactId( getTrimmedValue( parser.nextText() ) );
611            }
612            else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
613            {
614                metadata.setVersion( getTrimmedValue( parser.nextText() ) );
615            }
616            else if ( checkFieldWithDuplicate( parser, "versioning", null, parsed ) )
617            {
618                metadata.setVersioning( parseVersioning( parser, strict ) );
619            }
620            else if ( checkFieldWithDuplicate( parser, "plugins", null, parsed ) )
621            {
622                java.util.List plugins = new java.util.ArrayList/*<Plugin>*/();
623                metadata.setPlugins( plugins );
624                while ( parser.nextTag() == XmlPullParser.START_TAG )
625                {
626                    if ( "plugin".equals( parser.getName() ) )
627                    {
628                        plugins.add( parsePlugin( parser, strict ) );
629                    }
630                    else
631                    {
632                        checkUnknownElement( parser, strict );
633                    }
634                }
635            }
636            else
637            {
638                checkUnknownElement( parser, strict );
639            }
640        }
641        return metadata;
642    } //-- Metadata parseMetadata( XmlPullParser, boolean )
643
644    /**
645     * Method parsePlugin.
646     * 
647     * @param parser
648     * @param strict
649     * @throws IOException
650     * @throws XmlPullParserException
651     * @return Plugin
652     */
653    private Plugin parsePlugin( XmlPullParser parser, boolean strict )
654        throws IOException, XmlPullParserException
655    {
656        String tagName = parser.getName();
657        Plugin plugin = new Plugin();
658        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
659        {
660            String name = parser.getAttributeName( i );
661            String value = parser.getAttributeValue( i );
662
663            if ( name.indexOf( ':' ) >= 0 )
664            {
665                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
666            }
667            else
668            {
669                checkUnknownAttribute( parser, name, tagName, strict );
670            }
671        }
672        java.util.Set parsed = new java.util.HashSet();
673        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
674        {
675            if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
676            {
677                plugin.setName( getTrimmedValue( parser.nextText() ) );
678            }
679            else if ( checkFieldWithDuplicate( parser, "prefix", null, parsed ) )
680            {
681                plugin.setPrefix( getTrimmedValue( parser.nextText() ) );
682            }
683            else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) )
684            {
685                plugin.setArtifactId( getTrimmedValue( parser.nextText() ) );
686            }
687            else
688            {
689                checkUnknownElement( parser, strict );
690            }
691        }
692        return plugin;
693    } //-- Plugin parsePlugin( XmlPullParser, boolean )
694
695    /**
696     * Method parseSnapshot.
697     * 
698     * @param parser
699     * @param strict
700     * @throws IOException
701     * @throws XmlPullParserException
702     * @return Snapshot
703     */
704    private Snapshot parseSnapshot( XmlPullParser parser, boolean strict )
705        throws IOException, XmlPullParserException
706    {
707        String tagName = parser.getName();
708        Snapshot snapshot = new Snapshot();
709        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
710        {
711            String name = parser.getAttributeName( i );
712            String value = parser.getAttributeValue( i );
713
714            if ( name.indexOf( ':' ) >= 0 )
715            {
716                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
717            }
718            else
719            {
720                checkUnknownAttribute( parser, name, tagName, strict );
721            }
722        }
723        java.util.Set parsed = new java.util.HashSet();
724        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
725        {
726            if ( checkFieldWithDuplicate( parser, "timestamp", null, parsed ) )
727            {
728                snapshot.setTimestamp( getTrimmedValue( parser.nextText() ) );
729            }
730            else if ( checkFieldWithDuplicate( parser, "buildNumber", null, parsed ) )
731            {
732                snapshot.setBuildNumber( getIntegerValue( getTrimmedValue( parser.nextText() ), "buildNumber", parser, strict ) );
733            }
734            else if ( checkFieldWithDuplicate( parser, "localCopy", null, parsed ) )
735            {
736                snapshot.setLocalCopy( getBooleanValue( getTrimmedValue( parser.nextText() ), "localCopy", parser, "false" ) );
737            }
738            else
739            {
740                checkUnknownElement( parser, strict );
741            }
742        }
743        return snapshot;
744    } //-- Snapshot parseSnapshot( XmlPullParser, boolean )
745
746    /**
747     * Method parseSnapshotVersion.
748     * 
749     * @param parser
750     * @param strict
751     * @throws IOException
752     * @throws XmlPullParserException
753     * @return SnapshotVersion
754     */
755    private SnapshotVersion parseSnapshotVersion( XmlPullParser parser, boolean strict )
756        throws IOException, XmlPullParserException
757    {
758        String tagName = parser.getName();
759        SnapshotVersion snapshotVersion = new SnapshotVersion();
760        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
761        {
762            String name = parser.getAttributeName( i );
763            String value = parser.getAttributeValue( i );
764
765            if ( name.indexOf( ':' ) >= 0 )
766            {
767                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
768            }
769            else
770            {
771                checkUnknownAttribute( parser, name, tagName, strict );
772            }
773        }
774        java.util.Set parsed = new java.util.HashSet();
775        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
776        {
777            if ( checkFieldWithDuplicate( parser, "classifier", null, parsed ) )
778            {
779                snapshotVersion.setClassifier( getTrimmedValue( parser.nextText() ) );
780            }
781            else if ( checkFieldWithDuplicate( parser, "extension", null, parsed ) )
782            {
783                snapshotVersion.setExtension( getTrimmedValue( parser.nextText() ) );
784            }
785            else if ( checkFieldWithDuplicate( parser, "value", null, parsed ) )
786            {
787                snapshotVersion.setVersion( getTrimmedValue( parser.nextText() ) );
788            }
789            else if ( checkFieldWithDuplicate( parser, "updated", null, parsed ) )
790            {
791                snapshotVersion.setUpdated( getTrimmedValue( parser.nextText() ) );
792            }
793            else
794            {
795                checkUnknownElement( parser, strict );
796            }
797        }
798        return snapshotVersion;
799    } //-- SnapshotVersion parseSnapshotVersion( XmlPullParser, boolean )
800
801    /**
802     * Method parseVersioning.
803     * 
804     * @param parser
805     * @param strict
806     * @throws IOException
807     * @throws XmlPullParserException
808     * @return Versioning
809     */
810    private Versioning parseVersioning( XmlPullParser parser, boolean strict )
811        throws IOException, XmlPullParserException
812    {
813        String tagName = parser.getName();
814        Versioning versioning = new Versioning();
815        for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
816        {
817            String name = parser.getAttributeName( i );
818            String value = parser.getAttributeValue( i );
819
820            if ( name.indexOf( ':' ) >= 0 )
821            {
822                // just ignore attributes with non-default namespace (for example: xmlns:xsi)
823            }
824            else
825            {
826                checkUnknownAttribute( parser, name, tagName, strict );
827            }
828        }
829        java.util.Set parsed = new java.util.HashSet();
830        while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
831        {
832            if ( checkFieldWithDuplicate( parser, "latest", null, parsed ) )
833            {
834                versioning.setLatest( getTrimmedValue( parser.nextText() ) );
835            }
836            else if ( checkFieldWithDuplicate( parser, "release", null, parsed ) )
837            {
838                versioning.setRelease( getTrimmedValue( parser.nextText() ) );
839            }
840            else if ( checkFieldWithDuplicate( parser, "snapshot", null, parsed ) )
841            {
842                versioning.setSnapshot( parseSnapshot( parser, strict ) );
843            }
844            else if ( checkFieldWithDuplicate( parser, "versions", null, parsed ) )
845            {
846                java.util.List versions = new java.util.ArrayList/*<String>*/();
847                versioning.setVersions( versions );
848                while ( parser.nextTag() == XmlPullParser.START_TAG )
849                {
850                    if ( "version".equals( parser.getName() ) )
851                    {
852                        versions.add( getTrimmedValue( parser.nextText() ) );
853                    }
854                    else
855                    {
856                        checkUnknownElement( parser, strict );
857                    }
858                }
859            }
860            else if ( checkFieldWithDuplicate( parser, "lastUpdated", null, parsed ) )
861            {
862                versioning.setLastUpdated( getTrimmedValue( parser.nextText() ) );
863            }
864            else if ( checkFieldWithDuplicate( parser, "snapshotVersions", null, parsed ) )
865            {
866                java.util.List snapshotVersions = new java.util.ArrayList/*<SnapshotVersion>*/();
867                versioning.setSnapshotVersions( snapshotVersions );
868                while ( parser.nextTag() == XmlPullParser.START_TAG )
869                {
870                    if ( "snapshotVersion".equals( parser.getName() ) )
871                    {
872                        snapshotVersions.add( parseSnapshotVersion( parser, strict ) );
873                    }
874                    else
875                    {
876                        checkUnknownElement( parser, strict );
877                    }
878                }
879            }
880            else
881            {
882                checkUnknownElement( parser, strict );
883            }
884        }
885        return versioning;
886    } //-- Versioning parseVersioning( XmlPullParser, boolean )
887
888    /**
889     * Method read.
890     * 
891     * @param parser
892     * @param strict
893     * @throws IOException
894     * @throws XmlPullParserException
895     * @return Metadata
896     */
897    private Metadata read( XmlPullParser parser, boolean strict )
898        throws IOException, XmlPullParserException
899    {
900        int eventType = parser.getEventType();
901        while ( eventType != XmlPullParser.END_DOCUMENT )
902        {
903            if ( eventType == XmlPullParser.START_TAG )
904            {
905                if ( strict && ! "metadata".equals( parser.getName() ) )
906                {
907                    throw new XmlPullParserException( "Expected root element 'metadata' but found '" + parser.getName() + "'", parser, null );
908                }
909                Metadata metadata = parseMetadata( parser, strict );
910                metadata.setModelEncoding( parser.getInputEncoding() );
911                return metadata;
912            }
913            eventType = parser.next();
914        }
915        throw new XmlPullParserException( "Expected root element 'metadata' but found no element at all: invalid XML document", parser, null );
916    } //-- Metadata read( XmlPullParser, boolean )
917
918    /**
919     * Sets the state of the "add default entities" flag.
920     * 
921     * @param addDefaultEntities
922     */
923    public void setAddDefaultEntities( boolean addDefaultEntities )
924    {
925        this.addDefaultEntities = addDefaultEntities;
926    } //-- void setAddDefaultEntities( boolean )
927
928}