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