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