View Javadoc

1   /*
2    =================== DO NOT EDIT THIS FILE ====================
3    Generated by Modello 1.4.1 on 2011-11-23 07:27:52,
4    any modifications will be overwritten.
5    ==============================================================
6    */
7   
8   package org.apache.maven.archetype.catalog.io.xpp3;
9   
10    //---------------------------------/
11   //- Imported classes and packages -/
12  //---------------------------------/
13  
14  import java.io.IOException;
15  import java.io.InputStream;
16  import java.io.Reader;
17  import java.text.DateFormat;
18  import java.util.Locale;
19  import org.apache.maven.archetype.catalog.Archetype;
20  import org.apache.maven.archetype.catalog.ArchetypeCatalog;
21  import org.codehaus.plexus.util.ReaderFactory;
22  import org.codehaus.plexus.util.xml.pull.MXParser;
23  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
24  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
25  
26  /**
27   * Class ArchetypeCatalogXpp3Reader.
28   * 
29   * @version $Revision$ $Date$
30   */
31  @SuppressWarnings( "all" )
32  public class ArchetypeCatalogXpp3Reader
33  {
34  
35        //--------------------------/
36       //- Class/Member Variables -/
37      //--------------------------/
38  
39      /**
40       * If set the parser will be loaded with all single characters
41       * from the XHTML specification.
42       * The entities used:
43       * <ul>
44       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
45       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
46       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
47       * </ul>
48       */
49      private boolean addDefaultEntities = true;
50  
51  
52        //-----------/
53       //- Methods -/
54      //-----------/
55  
56      /**
57       * Method checkFieldWithDuplicate.
58       * 
59       * @param parser
60       * @param parsed
61       * @param alias
62       * @param tagName
63       * @throws XmlPullParserException
64       * @return boolean
65       */
66      private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
67          throws XmlPullParserException
68      {
69          if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
70          {
71              return false;
72          }
73          if ( !parsed.add( tagName ) )
74          {
75              throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
76          }
77          return true;
78      } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set )
79  
80      /**
81       * Method checkUnknownAttribute.
82       * 
83       * @param parser
84       * @param strict
85       * @param tagName
86       * @param attribute
87       * @throws XmlPullParserException
88       * @throws IOException
89       */
90      private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
91          throws XmlPullParserException, IOException
92      {
93          // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
94          if ( strict )
95          {
96              throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
97          }
98      } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
99  
100     /**
101      * Method checkUnknownElement.
102      * 
103      * @param parser
104      * @param strict
105      * @throws XmlPullParserException
106      * @throws IOException
107      */
108     private void checkUnknownElement( XmlPullParser parser, boolean strict )
109         throws XmlPullParserException, IOException
110     {
111         if ( strict )
112         {
113             throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
114         }
115 
116         for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
117         {
118             int eventType = parser.next();
119             if ( eventType == XmlPullParser.START_TAG )
120             {
121                 unrecognizedTagCount++;
122             }
123             else if ( eventType == XmlPullParser.END_TAG )
124             {
125                 unrecognizedTagCount--;
126             }
127         }
128     } //-- void checkUnknownElement( XmlPullParser, boolean )
129 
130     /**
131      * Returns the state of the "add default entities" flag.
132      * 
133      * @return boolean
134      */
135     public boolean getAddDefaultEntities()
136     {
137         return addDefaultEntities;
138     } //-- boolean getAddDefaultEntities()
139 
140     /**
141      * Method getBooleanValue.
142      * 
143      * @param s
144      * @param parser
145      * @param attribute
146      * @throws XmlPullParserException
147      * @return boolean
148      */
149     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
150         throws XmlPullParserException
151     {
152         return getBooleanValue( s, attribute, parser, null );
153     } //-- boolean getBooleanValue( String, String, XmlPullParser )
154 
155     /**
156      * Method getBooleanValue.
157      * 
158      * @param s
159      * @param defaultValue
160      * @param parser
161      * @param attribute
162      * @throws XmlPullParserException
163      * @return boolean
164      */
165     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
166         throws XmlPullParserException
167     {
168         if ( s != null && s.length() != 0 )
169         {
170             return Boolean.valueOf( s ).booleanValue();
171         }
172         if ( defaultValue != null )
173         {
174             return Boolean.valueOf( defaultValue ).booleanValue();
175         }
176         return false;
177     } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
178 
179     /**
180      * Method getByteValue.
181      * 
182      * @param s
183      * @param strict
184      * @param parser
185      * @param attribute
186      * @throws XmlPullParserException
187      * @return byte
188      */
189     private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
190         throws XmlPullParserException
191     {
192         if ( s != null )
193         {
194             try
195             {
196                 return Byte.valueOf( s ).byteValue();
197             }
198             catch ( NumberFormatException nfe )
199             {
200                 if ( strict )
201                 {
202                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
203                 }
204             }
205         }
206         return 0;
207     } //-- byte getByteValue( String, String, XmlPullParser, boolean )
208 
209     /**
210      * Method getCharacterValue.
211      * 
212      * @param s
213      * @param parser
214      * @param attribute
215      * @throws XmlPullParserException
216      * @return char
217      */
218     private char getCharacterValue( String s, String attribute, XmlPullParser parser )
219         throws XmlPullParserException
220     {
221         if ( s != null )
222         {
223             return s.charAt( 0 );
224         }
225         return 0;
226     } //-- char getCharacterValue( String, String, XmlPullParser )
227 
228     /**
229      * Method getDateValue.
230      * 
231      * @param s
232      * @param parser
233      * @param attribute
234      * @throws XmlPullParserException
235      * @return Date
236      */
237     private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
238         throws XmlPullParserException
239     {
240         return getDateValue( s, attribute, null, parser );
241     } //-- java.util.Date getDateValue( String, String, XmlPullParser )
242 
243     /**
244      * Method getDateValue.
245      * 
246      * @param s
247      * @param parser
248      * @param dateFormat
249      * @param attribute
250      * @throws XmlPullParserException
251      * @return Date
252      */
253     private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
254         throws XmlPullParserException
255     {
256         if ( s != null )
257         {
258             String effectiveDateFormat = dateFormat;
259             if ( dateFormat == null )
260             {
261                 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
262             }
263             if ( "long".equals( effectiveDateFormat ) )
264             {
265                 try
266                 {
267                     return new java.util.Date( Long.parseLong( s ) );
268                 }
269                 catch ( NumberFormatException e )
270                 {
271                     throw new XmlPullParserException( e.getMessage(), parser, e );
272                 }
273             }
274             else
275             {
276                 try
277                 {
278                     DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, Locale.US );
279                     return dateParser.parse( s );
280                 }
281                 catch ( java.text.ParseException e )
282                 {
283                     throw new XmlPullParserException( e.getMessage(), parser, e );
284                 }
285             }
286         }
287         return null;
288     } //-- java.util.Date getDateValue( String, String, String, XmlPullParser )
289 
290     /**
291      * Method getDoubleValue.
292      * 
293      * @param s
294      * @param strict
295      * @param parser
296      * @param attribute
297      * @throws XmlPullParserException
298      * @return double
299      */
300     private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
301         throws XmlPullParserException
302     {
303         if ( s != null )
304         {
305             try
306             {
307                 return Double.valueOf( s ).doubleValue();
308             }
309             catch ( NumberFormatException nfe )
310             {
311                 if ( strict )
312                 {
313                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
314                 }
315             }
316         }
317         return 0;
318     } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
319 
320     /**
321      * Method getFloatValue.
322      * 
323      * @param s
324      * @param strict
325      * @param parser
326      * @param attribute
327      * @throws XmlPullParserException
328      * @return float
329      */
330     private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
331         throws XmlPullParserException
332     {
333         if ( s != null )
334         {
335             try
336             {
337                 return Float.valueOf( s ).floatValue();
338             }
339             catch ( NumberFormatException nfe )
340             {
341                 if ( strict )
342                 {
343                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
344                 }
345             }
346         }
347         return 0;
348     } //-- float getFloatValue( String, String, XmlPullParser, boolean )
349 
350     /**
351      * Method getIntegerValue.
352      * 
353      * @param s
354      * @param strict
355      * @param parser
356      * @param attribute
357      * @throws XmlPullParserException
358      * @return int
359      */
360     private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
361         throws XmlPullParserException
362     {
363         if ( s != null )
364         {
365             try
366             {
367                 return Integer.valueOf( s ).intValue();
368             }
369             catch ( NumberFormatException nfe )
370             {
371                 if ( strict )
372                 {
373                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
374                 }
375             }
376         }
377         return 0;
378     } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
379 
380     /**
381      * Method getLongValue.
382      * 
383      * @param s
384      * @param strict
385      * @param parser
386      * @param attribute
387      * @throws XmlPullParserException
388      * @return long
389      */
390     private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
391         throws XmlPullParserException
392     {
393         if ( s != null )
394         {
395             try
396             {
397                 return Long.valueOf( s ).longValue();
398             }
399             catch ( NumberFormatException nfe )
400             {
401                 if ( strict )
402                 {
403                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
404                 }
405             }
406         }
407         return 0;
408     } //-- long getLongValue( String, String, XmlPullParser, boolean )
409 
410     /**
411      * Method getRequiredAttributeValue.
412      * 
413      * @param s
414      * @param strict
415      * @param parser
416      * @param attribute
417      * @throws XmlPullParserException
418      * @return String
419      */
420     private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
421         throws XmlPullParserException
422     {
423         if ( s == null )
424         {
425             if ( strict )
426             {
427                 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
428             }
429         }
430         return s;
431     } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
432 
433     /**
434      * Method getShortValue.
435      * 
436      * @param s
437      * @param strict
438      * @param parser
439      * @param attribute
440      * @throws XmlPullParserException
441      * @return short
442      */
443     private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
444         throws XmlPullParserException
445     {
446         if ( s != null )
447         {
448             try
449             {
450                 return Short.valueOf( s ).shortValue();
451             }
452             catch ( NumberFormatException nfe )
453             {
454                 if ( strict )
455                 {
456                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
457                 }
458             }
459         }
460         return 0;
461     } //-- short getShortValue( String, String, XmlPullParser, boolean )
462 
463     /**
464      * Method getTrimmedValue.
465      * 
466      * @param s
467      * @return String
468      */
469     private String getTrimmedValue( String s )
470     {
471         if ( s != null )
472         {
473             s = s.trim();
474         }
475         return s;
476     } //-- String getTrimmedValue( String )
477 
478     /**
479      * Method initParser.
480      * 
481      * @param parser
482      * @throws XmlPullParserException
483      */
484     private void initParser( XmlPullParser parser )
485         throws XmlPullParserException
486     {
487         if ( addDefaultEntities )
488         {
489             // ----------------------------------------------------------------------
490             // Latin 1 entities
491             // ----------------------------------------------------------------------
492 
493             parser.defineEntityReplacementText( "nbsp", "\u00a0" );
494             parser.defineEntityReplacementText( "iexcl", "\u00a1" );
495             parser.defineEntityReplacementText( "cent", "\u00a2" );
496             parser.defineEntityReplacementText( "pound", "\u00a3" );
497             parser.defineEntityReplacementText( "curren", "\u00a4" );
498             parser.defineEntityReplacementText( "yen", "\u00a5" );
499             parser.defineEntityReplacementText( "brvbar", "\u00a6" );
500             parser.defineEntityReplacementText( "sect", "\u00a7" );
501             parser.defineEntityReplacementText( "uml", "\u00a8" );
502             parser.defineEntityReplacementText( "copy", "\u00a9" );
503             parser.defineEntityReplacementText( "ordf", "\u00aa" );
504             parser.defineEntityReplacementText( "laquo", "\u00ab" );
505             parser.defineEntityReplacementText( "not", "\u00ac" );
506             parser.defineEntityReplacementText( "shy", "\u00ad" );
507             parser.defineEntityReplacementText( "reg", "\u00ae" );
508             parser.defineEntityReplacementText( "macr", "\u00af" );
509             parser.defineEntityReplacementText( "deg", "\u00b0" );
510             parser.defineEntityReplacementText( "plusmn", "\u00b1" );
511             parser.defineEntityReplacementText( "sup2", "\u00b2" );
512             parser.defineEntityReplacementText( "sup3", "\u00b3" );
513             parser.defineEntityReplacementText( "acute", "\u00b4" );
514             parser.defineEntityReplacementText( "micro", "\u00b5" );
515             parser.defineEntityReplacementText( "para", "\u00b6" );
516             parser.defineEntityReplacementText( "middot", "\u00b7" );
517             parser.defineEntityReplacementText( "cedil", "\u00b8" );
518             parser.defineEntityReplacementText( "sup1", "\u00b9" );
519             parser.defineEntityReplacementText( "ordm", "\u00ba" );
520             parser.defineEntityReplacementText( "raquo", "\u00bb" );
521             parser.defineEntityReplacementText( "frac14", "\u00bc" );
522             parser.defineEntityReplacementText( "frac12", "\u00bd" );
523             parser.defineEntityReplacementText( "frac34", "\u00be" );
524             parser.defineEntityReplacementText( "iquest", "\u00bf" );
525             parser.defineEntityReplacementText( "Agrave", "\u00c0" );
526             parser.defineEntityReplacementText( "Aacute", "\u00c1" );
527             parser.defineEntityReplacementText( "Acirc", "\u00c2" );
528             parser.defineEntityReplacementText( "Atilde", "\u00c3" );
529             parser.defineEntityReplacementText( "Auml", "\u00c4" );
530             parser.defineEntityReplacementText( "Aring", "\u00c5" );
531             parser.defineEntityReplacementText( "AElig", "\u00c6" );
532             parser.defineEntityReplacementText( "Ccedil", "\u00c7" );
533             parser.defineEntityReplacementText( "Egrave", "\u00c8" );
534             parser.defineEntityReplacementText( "Eacute", "\u00c9" );
535             parser.defineEntityReplacementText( "Ecirc", "\u00ca" );
536             parser.defineEntityReplacementText( "Euml", "\u00cb" );
537             parser.defineEntityReplacementText( "Igrave", "\u00cc" );
538             parser.defineEntityReplacementText( "Iacute", "\u00cd" );
539             parser.defineEntityReplacementText( "Icirc", "\u00ce" );
540             parser.defineEntityReplacementText( "Iuml", "\u00cf" );
541             parser.defineEntityReplacementText( "ETH", "\u00d0" );
542             parser.defineEntityReplacementText( "Ntilde", "\u00d1" );
543             parser.defineEntityReplacementText( "Ograve", "\u00d2" );
544             parser.defineEntityReplacementText( "Oacute", "\u00d3" );
545             parser.defineEntityReplacementText( "Ocirc", "\u00d4" );
546             parser.defineEntityReplacementText( "Otilde", "\u00d5" );
547             parser.defineEntityReplacementText( "Ouml", "\u00d6" );
548             parser.defineEntityReplacementText( "times", "\u00d7" );
549             parser.defineEntityReplacementText( "Oslash", "\u00d8" );
550             parser.defineEntityReplacementText( "Ugrave", "\u00d9" );
551             parser.defineEntityReplacementText( "Uacute", "\u00da" );
552             parser.defineEntityReplacementText( "Ucirc", "\u00db" );
553             parser.defineEntityReplacementText( "Uuml", "\u00dc" );
554             parser.defineEntityReplacementText( "Yacute", "\u00dd" );
555             parser.defineEntityReplacementText( "THORN", "\u00de" );
556             parser.defineEntityReplacementText( "szlig", "\u00df" );
557             parser.defineEntityReplacementText( "agrave", "\u00e0" );
558             parser.defineEntityReplacementText( "aacute", "\u00e1" );
559             parser.defineEntityReplacementText( "acirc", "\u00e2" );
560             parser.defineEntityReplacementText( "atilde", "\u00e3" );
561             parser.defineEntityReplacementText( "auml", "\u00e4" );
562             parser.defineEntityReplacementText( "aring", "\u00e5" );
563             parser.defineEntityReplacementText( "aelig", "\u00e6" );
564             parser.defineEntityReplacementText( "ccedil", "\u00e7" );
565             parser.defineEntityReplacementText( "egrave", "\u00e8" );
566             parser.defineEntityReplacementText( "eacute", "\u00e9" );
567             parser.defineEntityReplacementText( "ecirc", "\u00ea" );
568             parser.defineEntityReplacementText( "euml", "\u00eb" );
569             parser.defineEntityReplacementText( "igrave", "\u00ec" );
570             parser.defineEntityReplacementText( "iacute", "\u00ed" );
571             parser.defineEntityReplacementText( "icirc", "\u00ee" );
572             parser.defineEntityReplacementText( "iuml", "\u00ef" );
573             parser.defineEntityReplacementText( "eth", "\u00f0" );
574             parser.defineEntityReplacementText( "ntilde", "\u00f1" );
575             parser.defineEntityReplacementText( "ograve", "\u00f2" );
576             parser.defineEntityReplacementText( "oacute", "\u00f3" );
577             parser.defineEntityReplacementText( "ocirc", "\u00f4" );
578             parser.defineEntityReplacementText( "otilde", "\u00f5" );
579             parser.defineEntityReplacementText( "ouml", "\u00f6" );
580             parser.defineEntityReplacementText( "divide", "\u00f7" );
581             parser.defineEntityReplacementText( "oslash", "\u00f8" );
582             parser.defineEntityReplacementText( "ugrave", "\u00f9" );
583             parser.defineEntityReplacementText( "uacute", "\u00fa" );
584             parser.defineEntityReplacementText( "ucirc", "\u00fb" );
585             parser.defineEntityReplacementText( "uuml", "\u00fc" );
586             parser.defineEntityReplacementText( "yacute", "\u00fd" );
587             parser.defineEntityReplacementText( "thorn", "\u00fe" );
588             parser.defineEntityReplacementText( "yuml", "\u00ff" );
589 
590             // ----------------------------------------------------------------------
591             // Special entities
592             // ----------------------------------------------------------------------
593 
594             parser.defineEntityReplacementText( "OElig", "\u0152" );
595             parser.defineEntityReplacementText( "oelig", "\u0153" );
596             parser.defineEntityReplacementText( "Scaron", "\u0160" );
597             parser.defineEntityReplacementText( "scaron", "\u0161" );
598             parser.defineEntityReplacementText( "Yuml", "\u0178" );
599             parser.defineEntityReplacementText( "circ", "\u02c6" );
600             parser.defineEntityReplacementText( "tilde", "\u02dc" );
601             parser.defineEntityReplacementText( "ensp", "\u2002" );
602             parser.defineEntityReplacementText( "emsp", "\u2003" );
603             parser.defineEntityReplacementText( "thinsp", "\u2009" );
604             parser.defineEntityReplacementText( "zwnj", "\u200c" );
605             parser.defineEntityReplacementText( "zwj", "\u200d" );
606             parser.defineEntityReplacementText( "lrm", "\u200e" );
607             parser.defineEntityReplacementText( "rlm", "\u200f" );
608             parser.defineEntityReplacementText( "ndash", "\u2013" );
609             parser.defineEntityReplacementText( "mdash", "\u2014" );
610             parser.defineEntityReplacementText( "lsquo", "\u2018" );
611             parser.defineEntityReplacementText( "rsquo", "\u2019" );
612             parser.defineEntityReplacementText( "sbquo", "\u201a" );
613             parser.defineEntityReplacementText( "ldquo", "\u201c" );
614             parser.defineEntityReplacementText( "rdquo", "\u201d" );
615             parser.defineEntityReplacementText( "bdquo", "\u201e" );
616             parser.defineEntityReplacementText( "dagger", "\u2020" );
617             parser.defineEntityReplacementText( "Dagger", "\u2021" );
618             parser.defineEntityReplacementText( "permil", "\u2030" );
619             parser.defineEntityReplacementText( "lsaquo", "\u2039" );
620             parser.defineEntityReplacementText( "rsaquo", "\u203a" );
621             parser.defineEntityReplacementText( "euro", "\u20ac" );
622 
623             // ----------------------------------------------------------------------
624             // Symbol entities
625             // ----------------------------------------------------------------------
626 
627             parser.defineEntityReplacementText( "fnof", "\u0192" );
628             parser.defineEntityReplacementText( "Alpha", "\u0391" );
629             parser.defineEntityReplacementText( "Beta", "\u0392" );
630             parser.defineEntityReplacementText( "Gamma", "\u0393" );
631             parser.defineEntityReplacementText( "Delta", "\u0394" );
632             parser.defineEntityReplacementText( "Epsilon", "\u0395" );
633             parser.defineEntityReplacementText( "Zeta", "\u0396" );
634             parser.defineEntityReplacementText( "Eta", "\u0397" );
635             parser.defineEntityReplacementText( "Theta", "\u0398" );
636             parser.defineEntityReplacementText( "Iota", "\u0399" );
637             parser.defineEntityReplacementText( "Kappa", "\u039a" );
638             parser.defineEntityReplacementText( "Lambda", "\u039b" );
639             parser.defineEntityReplacementText( "Mu", "\u039c" );
640             parser.defineEntityReplacementText( "Nu", "\u039d" );
641             parser.defineEntityReplacementText( "Xi", "\u039e" );
642             parser.defineEntityReplacementText( "Omicron", "\u039f" );
643             parser.defineEntityReplacementText( "Pi", "\u03a0" );
644             parser.defineEntityReplacementText( "Rho", "\u03a1" );
645             parser.defineEntityReplacementText( "Sigma", "\u03a3" );
646             parser.defineEntityReplacementText( "Tau", "\u03a4" );
647             parser.defineEntityReplacementText( "Upsilon", "\u03a5" );
648             parser.defineEntityReplacementText( "Phi", "\u03a6" );
649             parser.defineEntityReplacementText( "Chi", "\u03a7" );
650             parser.defineEntityReplacementText( "Psi", "\u03a8" );
651             parser.defineEntityReplacementText( "Omega", "\u03a9" );
652             parser.defineEntityReplacementText( "alpha", "\u03b1" );
653             parser.defineEntityReplacementText( "beta", "\u03b2" );
654             parser.defineEntityReplacementText( "gamma", "\u03b3" );
655             parser.defineEntityReplacementText( "delta", "\u03b4" );
656             parser.defineEntityReplacementText( "epsilon", "\u03b5" );
657             parser.defineEntityReplacementText( "zeta", "\u03b6" );
658             parser.defineEntityReplacementText( "eta", "\u03b7" );
659             parser.defineEntityReplacementText( "theta", "\u03b8" );
660             parser.defineEntityReplacementText( "iota", "\u03b9" );
661             parser.defineEntityReplacementText( "kappa", "\u03ba" );
662             parser.defineEntityReplacementText( "lambda", "\u03bb" );
663             parser.defineEntityReplacementText( "mu", "\u03bc" );
664             parser.defineEntityReplacementText( "nu", "\u03bd" );
665             parser.defineEntityReplacementText( "xi", "\u03be" );
666             parser.defineEntityReplacementText( "omicron", "\u03bf" );
667             parser.defineEntityReplacementText( "pi", "\u03c0" );
668             parser.defineEntityReplacementText( "rho", "\u03c1" );
669             parser.defineEntityReplacementText( "sigmaf", "\u03c2" );
670             parser.defineEntityReplacementText( "sigma", "\u03c3" );
671             parser.defineEntityReplacementText( "tau", "\u03c4" );
672             parser.defineEntityReplacementText( "upsilon", "\u03c5" );
673             parser.defineEntityReplacementText( "phi", "\u03c6" );
674             parser.defineEntityReplacementText( "chi", "\u03c7" );
675             parser.defineEntityReplacementText( "psi", "\u03c8" );
676             parser.defineEntityReplacementText( "omega", "\u03c9" );
677             parser.defineEntityReplacementText( "thetasym", "\u03d1" );
678             parser.defineEntityReplacementText( "upsih", "\u03d2" );
679             parser.defineEntityReplacementText( "piv", "\u03d6" );
680             parser.defineEntityReplacementText( "bull", "\u2022" );
681             parser.defineEntityReplacementText( "hellip", "\u2026" );
682             parser.defineEntityReplacementText( "prime", "\u2032" );
683             parser.defineEntityReplacementText( "Prime", "\u2033" );
684             parser.defineEntityReplacementText( "oline", "\u203e" );
685             parser.defineEntityReplacementText( "frasl", "\u2044" );
686             parser.defineEntityReplacementText( "weierp", "\u2118" );
687             parser.defineEntityReplacementText( "image", "\u2111" );
688             parser.defineEntityReplacementText( "real", "\u211c" );
689             parser.defineEntityReplacementText( "trade", "\u2122" );
690             parser.defineEntityReplacementText( "alefsym", "\u2135" );
691             parser.defineEntityReplacementText( "larr", "\u2190" );
692             parser.defineEntityReplacementText( "uarr", "\u2191" );
693             parser.defineEntityReplacementText( "rarr", "\u2192" );
694             parser.defineEntityReplacementText( "darr", "\u2193" );
695             parser.defineEntityReplacementText( "harr", "\u2194" );
696             parser.defineEntityReplacementText( "crarr", "\u21b5" );
697             parser.defineEntityReplacementText( "lArr", "\u21d0" );
698             parser.defineEntityReplacementText( "uArr", "\u21d1" );
699             parser.defineEntityReplacementText( "rArr", "\u21d2" );
700             parser.defineEntityReplacementText( "dArr", "\u21d3" );
701             parser.defineEntityReplacementText( "hArr", "\u21d4" );
702             parser.defineEntityReplacementText( "forall", "\u2200" );
703             parser.defineEntityReplacementText( "part", "\u2202" );
704             parser.defineEntityReplacementText( "exist", "\u2203" );
705             parser.defineEntityReplacementText( "empty", "\u2205" );
706             parser.defineEntityReplacementText( "nabla", "\u2207" );
707             parser.defineEntityReplacementText( "isin", "\u2208" );
708             parser.defineEntityReplacementText( "notin", "\u2209" );
709             parser.defineEntityReplacementText( "ni", "\u220b" );
710             parser.defineEntityReplacementText( "prod", "\u220f" );
711             parser.defineEntityReplacementText( "sum", "\u2211" );
712             parser.defineEntityReplacementText( "minus", "\u2212" );
713             parser.defineEntityReplacementText( "lowast", "\u2217" );
714             parser.defineEntityReplacementText( "radic", "\u221a" );
715             parser.defineEntityReplacementText( "prop", "\u221d" );
716             parser.defineEntityReplacementText( "infin", "\u221e" );
717             parser.defineEntityReplacementText( "ang", "\u2220" );
718             parser.defineEntityReplacementText( "and", "\u2227" );
719             parser.defineEntityReplacementText( "or", "\u2228" );
720             parser.defineEntityReplacementText( "cap", "\u2229" );
721             parser.defineEntityReplacementText( "cup", "\u222a" );
722             parser.defineEntityReplacementText( "int", "\u222b" );
723             parser.defineEntityReplacementText( "there4", "\u2234" );
724             parser.defineEntityReplacementText( "sim", "\u223c" );
725             parser.defineEntityReplacementText( "cong", "\u2245" );
726             parser.defineEntityReplacementText( "asymp", "\u2248" );
727             parser.defineEntityReplacementText( "ne", "\u2260" );
728             parser.defineEntityReplacementText( "equiv", "\u2261" );
729             parser.defineEntityReplacementText( "le", "\u2264" );
730             parser.defineEntityReplacementText( "ge", "\u2265" );
731             parser.defineEntityReplacementText( "sub", "\u2282" );
732             parser.defineEntityReplacementText( "sup", "\u2283" );
733             parser.defineEntityReplacementText( "nsub", "\u2284" );
734             parser.defineEntityReplacementText( "sube", "\u2286" );
735             parser.defineEntityReplacementText( "supe", "\u2287" );
736             parser.defineEntityReplacementText( "oplus", "\u2295" );
737             parser.defineEntityReplacementText( "otimes", "\u2297" );
738             parser.defineEntityReplacementText( "perp", "\u22a5" );
739             parser.defineEntityReplacementText( "sdot", "\u22c5" );
740             parser.defineEntityReplacementText( "lceil", "\u2308" );
741             parser.defineEntityReplacementText( "rceil", "\u2309" );
742             parser.defineEntityReplacementText( "lfloor", "\u230a" );
743             parser.defineEntityReplacementText( "rfloor", "\u230b" );
744             parser.defineEntityReplacementText( "lang", "\u2329" );
745             parser.defineEntityReplacementText( "rang", "\u232a" );
746             parser.defineEntityReplacementText( "loz", "\u25ca" );
747             parser.defineEntityReplacementText( "spades", "\u2660" );
748             parser.defineEntityReplacementText( "clubs", "\u2663" );
749             parser.defineEntityReplacementText( "hearts", "\u2665" );
750             parser.defineEntityReplacementText( "diams", "\u2666" );
751 
752         }
753     } //-- void initParser( XmlPullParser )
754 
755     /**
756      * Method nextTag.
757      * 
758      * @param parser
759      * @throws IOException
760      * @throws XmlPullParserException
761      * @return int
762      */
763     private int nextTag( XmlPullParser parser )
764         throws IOException, XmlPullParserException
765     {
766         int eventType = parser.next();
767         if ( eventType == XmlPullParser.TEXT )
768         {
769             eventType = parser.next();
770         }
771         if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
772         {
773             throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
774         }
775         return eventType;
776     } //-- int nextTag( XmlPullParser )
777 
778     /**
779      * Method parseArchetype.
780      * 
781      * @param parser
782      * @param strict
783      * @throws IOException
784      * @throws XmlPullParserException
785      * @return Archetype
786      */
787     private Archetype parseArchetype( XmlPullParser parser, boolean strict )
788         throws IOException, XmlPullParserException
789     {
790         String tagName = parser.getName();
791         Archetype archetype = new Archetype();
792         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
793         {
794             String name = parser.getAttributeName( i );
795             String value = parser.getAttributeValue( i );
796 
797             if ( name.indexOf( ':' ) >= 0 )
798             {
799                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
800             }
801             else
802             {
803                 checkUnknownAttribute( parser, name, tagName, strict );
804             }
805         }
806         java.util.Set parsed = new java.util.HashSet();
807         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
808         {
809             if ( checkFieldWithDuplicate( parser, "groupId", null, parsed ) )
810             {
811                 archetype.setGroupId( getTrimmedValue( parser.nextText() ) );
812             }
813             else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) )
814             {
815                 archetype.setArtifactId( getTrimmedValue( parser.nextText() ) );
816             }
817             else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
818             {
819                 archetype.setVersion( getTrimmedValue( parser.nextText() ) );
820             }
821             else if ( checkFieldWithDuplicate( parser, "repository", null, parsed ) )
822             {
823                 archetype.setRepository( getTrimmedValue( parser.nextText() ) );
824             }
825             else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
826             {
827                 archetype.setDescription( getTrimmedValue( parser.nextText() ) );
828             }
829             else
830             {
831                 checkUnknownElement( parser, strict );
832             }
833         }
834         return archetype;
835     } //-- Archetype parseArchetype( XmlPullParser, boolean )
836 
837     /**
838      * Method parseArchetypeCatalog.
839      * 
840      * @param parser
841      * @param strict
842      * @throws IOException
843      * @throws XmlPullParserException
844      * @return ArchetypeCatalog
845      */
846     private ArchetypeCatalog parseArchetypeCatalog( XmlPullParser parser, boolean strict )
847         throws IOException, XmlPullParserException
848     {
849         String tagName = parser.getName();
850         ArchetypeCatalog archetypeCatalog = new ArchetypeCatalog();
851         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
852         {
853             String name = parser.getAttributeName( i );
854             String value = parser.getAttributeValue( i );
855 
856             if ( name.indexOf( ':' ) >= 0 )
857             {
858                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
859             }
860             else if ( "xmlns".equals( name ) )
861             {
862                 // ignore xmlns attribute in root class, which is a reserved attribute name
863             }
864             else
865             {
866                 checkUnknownAttribute( parser, name, tagName, strict );
867             }
868         }
869         java.util.Set parsed = new java.util.HashSet();
870         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
871         {
872             if ( checkFieldWithDuplicate( parser, "archetypes", null, parsed ) )
873             {
874                 java.util.List archetypes = new java.util.ArrayList/*<Archetype>*/();
875                 archetypeCatalog.setArchetypes( archetypes );
876                 while ( parser.nextTag() == XmlPullParser.START_TAG )
877                 {
878                     if ( "archetype".equals( parser.getName() ) )
879                     {
880                         archetypes.add( parseArchetype( parser, strict ) );
881                     }
882                     else
883                     {
884                         checkUnknownElement( parser, strict );
885                     }
886                 }
887             }
888             else
889             {
890                 checkUnknownElement( parser, strict );
891             }
892         }
893         return archetypeCatalog;
894     } //-- ArchetypeCatalog parseArchetypeCatalog( XmlPullParser, boolean )
895 
896     /**
897      * @see ReaderFactory#newXmlReader
898      * 
899      * @param reader
900      * @param strict
901      * @throws IOException
902      * @throws XmlPullParserException
903      * @return ArchetypeCatalog
904      */
905     public ArchetypeCatalog read( Reader reader, boolean strict )
906         throws IOException, XmlPullParserException
907     {
908         XmlPullParser parser = new MXParser();
909 
910         parser.setInput( reader );
911 
912         initParser( parser );
913 
914         return read( parser, strict );
915     } //-- ArchetypeCatalog read( Reader, boolean )
916 
917     /**
918      * @see ReaderFactory#newXmlReader
919      * 
920      * @param reader
921      * @throws IOException
922      * @throws XmlPullParserException
923      * @return ArchetypeCatalog
924      */
925     public ArchetypeCatalog read( Reader reader )
926         throws IOException, XmlPullParserException
927     {
928         return read( reader, true );
929     } //-- ArchetypeCatalog read( Reader )
930 
931     /**
932      * Method read.
933      * 
934      * @param in
935      * @param strict
936      * @throws IOException
937      * @throws XmlPullParserException
938      * @return ArchetypeCatalog
939      */
940     public ArchetypeCatalog read( InputStream in, boolean strict )
941         throws IOException, XmlPullParserException
942     {
943         return read( ReaderFactory.newXmlReader( in ), strict );
944     } //-- ArchetypeCatalog read( InputStream, boolean )
945 
946     /**
947      * Method read.
948      * 
949      * @param in
950      * @throws IOException
951      * @throws XmlPullParserException
952      * @return ArchetypeCatalog
953      */
954     public ArchetypeCatalog read( InputStream in )
955         throws IOException, XmlPullParserException
956     {
957         return read( ReaderFactory.newXmlReader( in ) );
958     } //-- ArchetypeCatalog read( InputStream )
959 
960     /**
961      * Method read.
962      * 
963      * @param parser
964      * @param strict
965      * @throws IOException
966      * @throws XmlPullParserException
967      * @return ArchetypeCatalog
968      */
969     private ArchetypeCatalog read( XmlPullParser parser, boolean strict )
970         throws IOException, XmlPullParserException
971     {
972         int eventType = parser.getEventType();
973         while ( eventType != XmlPullParser.END_DOCUMENT )
974         {
975             if ( eventType == XmlPullParser.START_TAG )
976             {
977                 if ( strict && ! "archetype-catalog".equals( parser.getName() ) )
978                 {
979                     throw new XmlPullParserException( "Expected root element 'archetype-catalog' but found '" + parser.getName() + "'", parser, null );
980                 }
981                 ArchetypeCatalog archetypeCatalog = parseArchetypeCatalog( parser, strict );
982                 archetypeCatalog.setModelEncoding( parser.getInputEncoding() );
983                 return archetypeCatalog;
984             }
985             eventType = parser.next();
986         }
987         throw new XmlPullParserException( "Expected root element 'archetype-catalog' but found no element at all: invalid XML document", parser, null );
988     } //-- ArchetypeCatalog read( XmlPullParser, boolean )
989 
990     /**
991      * Sets the state of the "add default entities" flag.
992      * 
993      * @param addDefaultEntities
994      */
995     public void setAddDefaultEntities( boolean addDefaultEntities )
996     {
997         this.addDefaultEntities = addDefaultEntities;
998     } //-- void setAddDefaultEntities( boolean )
999 
1000 }