View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 2.1.2,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.doxia.site.decoration.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.doxia.site.decoration.Banner;
17  import org.apache.maven.doxia.site.decoration.Body;
18  import org.apache.maven.doxia.site.decoration.DecorationModel;
19  import org.apache.maven.doxia.site.decoration.LinkItem;
20  import org.apache.maven.doxia.site.decoration.Logo;
21  import org.apache.maven.doxia.site.decoration.Menu;
22  import org.apache.maven.doxia.site.decoration.MenuItem;
23  import org.apache.maven.doxia.site.decoration.PublishDate;
24  import org.apache.maven.doxia.site.decoration.Skin;
25  import org.apache.maven.doxia.site.decoration.Version;
26  import org.codehaus.plexus.util.ReaderFactory;
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 DecorationXpp3Reader.
34   * 
35   * @version $Revision$ $Date$
36   */
37  @SuppressWarnings( "all" )
38  public class DecorationXpp3Reader
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 DecorationXpp3Reader()
68      {
69          this( new ContentTransformer()
70          {
71              public String transform( String source, String fieldName )
72              {
73                  return source;
74              }
75          } );
76      } //-- org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader()
77  
78      public DecorationXpp3Reader(ContentTransformer contentTransformer)
79      {
80          this.contentTransformer = contentTransformer;
81      } //-- org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader(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 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 DecorationModel
570      */
571     public DecorationModel read( XmlPullParser parser, boolean strict )
572         throws IOException, XmlPullParserException
573     {
574         DecorationModel decorationModel = 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 && ! "project".equals( parser.getName() ) )
582                 {
583                     throw new XmlPullParserException( "Expected root element 'project' 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: 'project'", parser, null );
589                 }
590                 decorationModel = parseDecorationModel( parser, strict );
591                 decorationModel.setModelEncoding( parser.getInputEncoding() );
592                 parsed = true;
593             }
594             eventType = parser.next();
595         }
596         if ( parsed )
597         {
598             return decorationModel;
599         }
600         throw new XmlPullParserException( "Expected root element 'project' but found no element at all: invalid XML document", parser, null );
601     } //-- DecorationModel read( XmlPullParser, boolean )
602 
603     /**
604      * @see ReaderFactory#newXmlReader
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 DecorationModel
612      */
613     public DecorationModel 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     } //-- DecorationModel read( Reader, boolean )
623 
624     /**
625      * @see ReaderFactory#newXmlReader
626      * 
627      * @param reader a reader object.
628      * @throws IOException IOException if any.
629      * @throws XmlPullParserException XmlPullParserException if
630      * any.
631      * @return DecorationModel
632      */
633     public DecorationModel read( Reader reader )
634         throws IOException, XmlPullParserException
635     {
636         return read( reader, true );
637     } //-- DecorationModel 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 DecorationModel
648      */
649     public DecorationModel read( InputStream in, boolean strict )
650         throws IOException, XmlPullParserException
651     {
652         return read( ReaderFactory.newXmlReader( in ), strict );
653     } //-- DecorationModel 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 DecorationModel
663      */
664     public DecorationModel read( InputStream in )
665         throws IOException, XmlPullParserException
666     {
667         return read( ReaderFactory.newXmlReader( in ) );
668     } //-- DecorationModel read( InputStream )
669 
670     /**
671      * Method parseBanner.
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 Banner
679      */
680     private Banner parseBanner( XmlPullParser parser, boolean strict )
681         throws IOException, XmlPullParserException
682     {
683         String tagName = parser.getName();
684         Banner banner = new Banner();
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 parsed = new java.util.HashSet();
700         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
701         {
702             if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
703             {
704                 banner.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
705             }
706             else if ( checkFieldWithDuplicate( parser, "src", null, parsed ) )
707             {
708                 banner.setSrc( interpolatedTrimmed( parser.nextText(), "src" ) );
709             }
710             else if ( checkFieldWithDuplicate( parser, "alt", null, parsed ) )
711             {
712                 banner.setAlt( interpolatedTrimmed( parser.nextText(), "alt" ) );
713             }
714             else if ( checkFieldWithDuplicate( parser, "href", null, parsed ) )
715             {
716                 banner.setHref( interpolatedTrimmed( parser.nextText(), "href" ) );
717             }
718             else if ( checkFieldWithDuplicate( parser, "border", null, parsed ) )
719             {
720                 banner.setBorder( interpolatedTrimmed( parser.nextText(), "border" ) );
721             }
722             else if ( checkFieldWithDuplicate( parser, "width", null, parsed ) )
723             {
724                 banner.setWidth( interpolatedTrimmed( parser.nextText(), "width" ) );
725             }
726             else if ( checkFieldWithDuplicate( parser, "height", null, parsed ) )
727             {
728                 banner.setHeight( interpolatedTrimmed( parser.nextText(), "height" ) );
729             }
730             else if ( checkFieldWithDuplicate( parser, "title", null, parsed ) )
731             {
732                 banner.setTitle( interpolatedTrimmed( parser.nextText(), "title" ) );
733             }
734             else
735             {
736                 checkUnknownElement( parser, strict );
737             }
738         }
739         return banner;
740     } //-- Banner parseBanner( XmlPullParser, boolean )
741 
742     /**
743      * Method parseBody.
744      * 
745      * @param parser a parser object.
746      * @param strict a strict object.
747      * @throws IOException IOException if any.
748      * @throws XmlPullParserException XmlPullParserException if
749      * any.
750      * @return Body
751      */
752     private Body parseBody( XmlPullParser parser, boolean strict )
753         throws IOException, XmlPullParserException
754     {
755         String tagName = parser.getName();
756         Body body = new Body();
757         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
758         {
759             String name = parser.getAttributeName( i );
760             String value = parser.getAttributeValue( i );
761 
762             if ( name.indexOf( ':' ) >= 0 )
763             {
764                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
765             }
766             else
767             {
768                 checkUnknownAttribute( parser, name, tagName, strict );
769             }
770         }
771         java.util.Set parsed = new java.util.HashSet();
772         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
773         {
774             if ( checkFieldWithDuplicate( parser, "head", null, parsed ) )
775             {
776                 body.setHead( interpolatedTrimmed( parser.nextText(), "head" ) );
777             }
778             else if ( checkFieldWithDuplicate( parser, "links", null, parsed ) )
779             {
780                 java.util.List<LinkItem> links = new java.util.ArrayList<LinkItem>();
781                 while ( parser.nextTag() == XmlPullParser.START_TAG )
782                 {
783                     if ( "item".equals( parser.getName() ) )
784                     {
785                         links.add( parseLinkItem( parser, strict ) );
786                     }
787                     else
788                     {
789                         checkUnknownElement( parser, strict );
790                     }
791                 }
792                 body.setLinks( links );
793             }
794             else if ( checkFieldWithDuplicate( parser, "breadcrumbs", null, parsed ) )
795             {
796                 java.util.List<LinkItem> breadcrumbs = new java.util.ArrayList<LinkItem>();
797                 while ( parser.nextTag() == XmlPullParser.START_TAG )
798                 {
799                     if ( "item".equals( parser.getName() ) )
800                     {
801                         breadcrumbs.add( parseLinkItem( parser, strict ) );
802                     }
803                     else
804                     {
805                         checkUnknownElement( parser, strict );
806                     }
807                 }
808                 body.setBreadcrumbs( breadcrumbs );
809             }
810             else if ( "menu".equals( parser.getName() ) )
811             {
812                 java.util.List<Menu> menus = body.getMenus();
813                 if ( menus == null )
814                 {
815                     menus = new java.util.ArrayList<Menu>();
816                 }
817                 menus.add( parseMenu( parser, strict ) );
818                 body.setMenus( menus );
819             }
820             else if ( checkFieldWithDuplicate( parser, "footer", null, parsed ) )
821             {
822                 body.setFooter( interpolatedTrimmed( parser.nextText(), "footer" ) );
823             }
824             else
825             {
826                 checkUnknownElement( parser, strict );
827             }
828         }
829         return body;
830     } //-- Body parseBody( XmlPullParser, boolean )
831 
832     /**
833      * Method parseDecorationModel.
834      * 
835      * @param parser a parser object.
836      * @param strict a strict object.
837      * @throws IOException IOException if any.
838      * @throws XmlPullParserException XmlPullParserException if
839      * any.
840      * @return DecorationModel
841      */
842     private DecorationModel parseDecorationModel( XmlPullParser parser, boolean strict )
843         throws IOException, XmlPullParserException
844     {
845         String tagName = parser.getName();
846         DecorationModel decorationModel = new DecorationModel();
847         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
848         {
849             String name = parser.getAttributeName( i );
850             String value = parser.getAttributeValue( i );
851 
852             if ( name.indexOf( ':' ) >= 0 )
853             {
854                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
855             }
856             else if ( "xmlns".equals( name ) )
857             {
858                 // ignore xmlns attribute in root class, which is a reserved attribute name
859             }
860             else if ( "name".equals( name ) )
861             {
862                 decorationModel.setName( interpolatedTrimmed( value, "name" ) );
863             }
864             else if ( "combine.self".equals( name ) )
865             {
866                 decorationModel.setCombineSelf( interpolatedTrimmed( value, "combine.self" ) );
867             }
868             else
869             {
870                 checkUnknownAttribute( parser, name, tagName, strict );
871             }
872         }
873         java.util.Set parsed = new java.util.HashSet();
874         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
875         {
876             if ( checkFieldWithDuplicate( parser, "bannerLeft", null, parsed ) )
877             {
878                 decorationModel.setBannerLeft( parseBanner( parser, strict ) );
879             }
880             else if ( checkFieldWithDuplicate( parser, "bannerRight", null, parsed ) )
881             {
882                 decorationModel.setBannerRight( parseBanner( parser, strict ) );
883             }
884             else if ( checkFieldWithDuplicate( parser, "publishDate", null, parsed ) )
885             {
886                 decorationModel.setPublishDate( parsePublishDate( parser, strict ) );
887             }
888             else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
889             {
890                 decorationModel.setVersion( parseVersion( parser, strict ) );
891             }
892             else if ( checkFieldWithDuplicate( parser, "edit", null, parsed ) )
893             {
894                 decorationModel.setEdit( interpolatedTrimmed( parser.nextText(), "edit" ) );
895             }
896             else if ( checkFieldWithDuplicate( parser, "poweredBy", null, parsed ) )
897             {
898                 java.util.List<Logo> poweredBy = new java.util.ArrayList<Logo>();
899                 while ( parser.nextTag() == XmlPullParser.START_TAG )
900                 {
901                     if ( "logo".equals( parser.getName() ) )
902                     {
903                         poweredBy.add( parseLogo( parser, strict ) );
904                     }
905                     else
906                     {
907                         checkUnknownElement( parser, strict );
908                     }
909                 }
910                 decorationModel.setPoweredBy( poweredBy );
911             }
912             else if ( checkFieldWithDuplicate( parser, "skin", null, parsed ) )
913             {
914                 decorationModel.setSkin( parseSkin( parser, strict ) );
915             }
916             else if ( checkFieldWithDuplicate( parser, "body", null, parsed ) )
917             {
918                 decorationModel.setBody( parseBody( parser, strict ) );
919             }
920             else if ( checkFieldWithDuplicate( parser, "custom", null, parsed ) )
921             {
922                 decorationModel.setCustom( org.codehaus.plexus.util.xml.Xpp3DomBuilder.build( parser, true ) );
923             }
924             else
925             {
926                 checkUnknownElement( parser, strict );
927             }
928         }
929         return decorationModel;
930     } //-- DecorationModel parseDecorationModel( XmlPullParser, boolean )
931 
932     /**
933      * Method parseLinkItem.
934      * 
935      * @param parser a parser object.
936      * @param strict a strict object.
937      * @throws IOException IOException if any.
938      * @throws XmlPullParserException XmlPullParserException if
939      * any.
940      * @return LinkItem
941      */
942     private LinkItem parseLinkItem( XmlPullParser parser, boolean strict )
943         throws IOException, XmlPullParserException
944     {
945         String tagName = parser.getName();
946         LinkItem linkItem = new LinkItem();
947         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
948         {
949             String name = parser.getAttributeName( i );
950             String value = parser.getAttributeValue( i );
951 
952             if ( name.indexOf( ':' ) >= 0 )
953             {
954                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
955             }
956             else if ( "name".equals( name ) )
957             {
958                 linkItem.setName( interpolatedTrimmed( value, "name" ) );
959             }
960             else if ( "href".equals( name ) )
961             {
962                 linkItem.setHref( interpolatedTrimmed( value, "href" ) );
963             }
964             else if ( "img".equals( name ) )
965             {
966                 linkItem.setImg( interpolatedTrimmed( value, "img" ) );
967             }
968             else if ( "position".equals( name ) )
969             {
970                 linkItem.setPosition( interpolatedTrimmed( value, "position" ) );
971             }
972             else if ( "alt".equals( name ) )
973             {
974                 linkItem.setAlt( interpolatedTrimmed( value, "alt" ) );
975             }
976             else if ( "border".equals( name ) )
977             {
978                 linkItem.setBorder( interpolatedTrimmed( value, "border" ) );
979             }
980             else if ( "width".equals( name ) )
981             {
982                 linkItem.setWidth( interpolatedTrimmed( value, "width" ) );
983             }
984             else if ( "height".equals( name ) )
985             {
986                 linkItem.setHeight( interpolatedTrimmed( value, "height" ) );
987             }
988             else if ( "target".equals( name ) )
989             {
990                 linkItem.setTarget( interpolatedTrimmed( value, "target" ) );
991             }
992             else if ( "title".equals( name ) )
993             {
994                 linkItem.setTitle( interpolatedTrimmed( value, "title" ) );
995             }
996             else
997             {
998                 checkUnknownAttribute( parser, name, tagName, strict );
999             }
1000         }
1001         java.util.Set parsed = new java.util.HashSet();
1002         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1003         {
1004             checkUnknownElement( parser, strict );
1005         }
1006         return linkItem;
1007     } //-- LinkItem parseLinkItem( XmlPullParser, boolean )
1008 
1009     /**
1010      * Method parseLogo.
1011      * 
1012      * @param parser a parser object.
1013      * @param strict a strict object.
1014      * @throws IOException IOException if any.
1015      * @throws XmlPullParserException XmlPullParserException if
1016      * any.
1017      * @return Logo
1018      */
1019     private Logo parseLogo( XmlPullParser parser, boolean strict )
1020         throws IOException, XmlPullParserException
1021     {
1022         String tagName = parser.getName();
1023         Logo logo = new Logo();
1024         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1025         {
1026             String name = parser.getAttributeName( i );
1027             String value = parser.getAttributeValue( i );
1028 
1029             if ( name.indexOf( ':' ) >= 0 )
1030             {
1031                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1032             }
1033             else if ( "name".equals( name ) )
1034             {
1035                 logo.setName( interpolatedTrimmed( value, "name" ) );
1036             }
1037             else if ( "href".equals( name ) )
1038             {
1039                 logo.setHref( interpolatedTrimmed( value, "href" ) );
1040             }
1041             else if ( "img".equals( name ) )
1042             {
1043                 logo.setImg( interpolatedTrimmed( value, "img" ) );
1044             }
1045             else if ( "position".equals( name ) )
1046             {
1047                 logo.setPosition( interpolatedTrimmed( value, "position" ) );
1048             }
1049             else if ( "alt".equals( name ) )
1050             {
1051                 logo.setAlt( interpolatedTrimmed( value, "alt" ) );
1052             }
1053             else if ( "border".equals( name ) )
1054             {
1055                 logo.setBorder( interpolatedTrimmed( value, "border" ) );
1056             }
1057             else if ( "width".equals( name ) )
1058             {
1059                 logo.setWidth( interpolatedTrimmed( value, "width" ) );
1060             }
1061             else if ( "height".equals( name ) )
1062             {
1063                 logo.setHeight( interpolatedTrimmed( value, "height" ) );
1064             }
1065             else if ( "target".equals( name ) )
1066             {
1067                 logo.setTarget( interpolatedTrimmed( value, "target" ) );
1068             }
1069             else if ( "title".equals( name ) )
1070             {
1071                 logo.setTitle( interpolatedTrimmed( value, "title" ) );
1072             }
1073             else
1074             {
1075                 checkUnknownAttribute( parser, name, tagName, strict );
1076             }
1077         }
1078         java.util.Set parsed = new java.util.HashSet();
1079         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1080         {
1081             checkUnknownElement( parser, strict );
1082         }
1083         return logo;
1084     } //-- Logo parseLogo( XmlPullParser, boolean )
1085 
1086     /**
1087      * Method parseMenu.
1088      * 
1089      * @param parser a parser object.
1090      * @param strict a strict object.
1091      * @throws IOException IOException if any.
1092      * @throws XmlPullParserException XmlPullParserException if
1093      * any.
1094      * @return Menu
1095      */
1096     private Menu parseMenu( XmlPullParser parser, boolean strict )
1097         throws IOException, XmlPullParserException
1098     {
1099         String tagName = parser.getName();
1100         Menu menu = new Menu();
1101         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1102         {
1103             String name = parser.getAttributeName( i );
1104             String value = parser.getAttributeValue( i );
1105 
1106             if ( name.indexOf( ':' ) >= 0 )
1107             {
1108                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1109             }
1110             else if ( "name".equals( name ) )
1111             {
1112                 menu.setName( interpolatedTrimmed( value, "name" ) );
1113             }
1114             else if ( "inherit".equals( name ) )
1115             {
1116                 menu.setInherit( interpolatedTrimmed( value, "inherit" ) );
1117             }
1118             else if ( "inheritAsRef".equals( name ) )
1119             {
1120                 menu.setInheritAsRef( getBooleanValue( interpolatedTrimmed( value, "inheritAsRef" ), "inheritAsRef", parser, "false" ) );
1121             }
1122             else if ( "ref".equals( name ) )
1123             {
1124                 menu.setRef( interpolatedTrimmed( value, "ref" ) );
1125             }
1126             else if ( "img".equals( name ) )
1127             {
1128                 menu.setImg( interpolatedTrimmed( value, "img" ) );
1129             }
1130             else if ( "alt".equals( name ) )
1131             {
1132                 menu.setAlt( interpolatedTrimmed( value, "alt" ) );
1133             }
1134             else if ( "position".equals( name ) )
1135             {
1136                 menu.setPosition( interpolatedTrimmed( value, "position" ) );
1137             }
1138             else if ( "border".equals( name ) )
1139             {
1140                 menu.setBorder( interpolatedTrimmed( value, "border" ) );
1141             }
1142             else if ( "width".equals( name ) )
1143             {
1144                 menu.setWidth( interpolatedTrimmed( value, "width" ) );
1145             }
1146             else if ( "height".equals( name ) )
1147             {
1148                 menu.setHeight( interpolatedTrimmed( value, "height" ) );
1149             }
1150             else if ( "title".equals( name ) )
1151             {
1152                 menu.setTitle( interpolatedTrimmed( value, "title" ) );
1153             }
1154             else
1155             {
1156                 checkUnknownAttribute( parser, name, tagName, strict );
1157             }
1158         }
1159         java.util.Set parsed = new java.util.HashSet();
1160         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1161         {
1162             if ( "item".equals( parser.getName() ) )
1163             {
1164                 java.util.List<MenuItem> items = menu.getItems();
1165                 if ( items == null )
1166                 {
1167                     items = new java.util.ArrayList<MenuItem>();
1168                 }
1169                 items.add( parseMenuItem( parser, strict ) );
1170                 menu.setItems( items );
1171             }
1172             else
1173             {
1174                 checkUnknownElement( parser, strict );
1175             }
1176         }
1177         return menu;
1178     } //-- Menu parseMenu( XmlPullParser, boolean )
1179 
1180     /**
1181      * Method parseMenuItem.
1182      * 
1183      * @param parser a parser object.
1184      * @param strict a strict object.
1185      * @throws IOException IOException if any.
1186      * @throws XmlPullParserException XmlPullParserException if
1187      * any.
1188      * @return MenuItem
1189      */
1190     private MenuItem parseMenuItem( XmlPullParser parser, boolean strict )
1191         throws IOException, XmlPullParserException
1192     {
1193         String tagName = parser.getName();
1194         MenuItem menuItem = new MenuItem();
1195         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1196         {
1197             String name = parser.getAttributeName( i );
1198             String value = parser.getAttributeValue( i );
1199 
1200             if ( name.indexOf( ':' ) >= 0 )
1201             {
1202                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1203             }
1204             else if ( "collapse".equals( name ) )
1205             {
1206                 menuItem.setCollapse( getBooleanValue( interpolatedTrimmed( value, "collapse" ), "collapse", parser, "false" ) );
1207             }
1208             else if ( "ref".equals( name ) )
1209             {
1210                 menuItem.setRef( interpolatedTrimmed( value, "ref" ) );
1211             }
1212             else if ( "name".equals( name ) )
1213             {
1214                 menuItem.setName( interpolatedTrimmed( value, "name" ) );
1215             }
1216             else if ( "href".equals( name ) )
1217             {
1218                 menuItem.setHref( interpolatedTrimmed( value, "href" ) );
1219             }
1220             else if ( "img".equals( name ) )
1221             {
1222                 menuItem.setImg( interpolatedTrimmed( value, "img" ) );
1223             }
1224             else if ( "position".equals( name ) )
1225             {
1226                 menuItem.setPosition( interpolatedTrimmed( value, "position" ) );
1227             }
1228             else if ( "alt".equals( name ) )
1229             {
1230                 menuItem.setAlt( interpolatedTrimmed( value, "alt" ) );
1231             }
1232             else if ( "border".equals( name ) )
1233             {
1234                 menuItem.setBorder( interpolatedTrimmed( value, "border" ) );
1235             }
1236             else if ( "width".equals( name ) )
1237             {
1238                 menuItem.setWidth( interpolatedTrimmed( value, "width" ) );
1239             }
1240             else if ( "height".equals( name ) )
1241             {
1242                 menuItem.setHeight( interpolatedTrimmed( value, "height" ) );
1243             }
1244             else if ( "target".equals( name ) )
1245             {
1246                 menuItem.setTarget( interpolatedTrimmed( value, "target" ) );
1247             }
1248             else if ( "title".equals( name ) )
1249             {
1250                 menuItem.setTitle( interpolatedTrimmed( value, "title" ) );
1251             }
1252             else
1253             {
1254                 checkUnknownAttribute( parser, name, tagName, strict );
1255             }
1256         }
1257         java.util.Set parsed = new java.util.HashSet();
1258         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1259         {
1260             if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
1261             {
1262                 menuItem.setDescription( interpolatedTrimmed( parser.nextText(), "description" ) );
1263             }
1264             else if ( "item".equals( parser.getName() ) )
1265             {
1266                 java.util.List<MenuItem> items = menuItem.getItems();
1267                 if ( items == null )
1268                 {
1269                     items = new java.util.ArrayList<MenuItem>();
1270                 }
1271                 items.add( parseMenuItem( parser, strict ) );
1272                 menuItem.setItems( items );
1273             }
1274             else
1275             {
1276                 checkUnknownElement( parser, strict );
1277             }
1278         }
1279         return menuItem;
1280     } //-- MenuItem parseMenuItem( XmlPullParser, boolean )
1281 
1282     /**
1283      * Method parsePublishDate.
1284      * 
1285      * @param parser a parser object.
1286      * @param strict a strict object.
1287      * @throws IOException IOException if any.
1288      * @throws XmlPullParserException XmlPullParserException if
1289      * any.
1290      * @return PublishDate
1291      */
1292     private PublishDate parsePublishDate( XmlPullParser parser, boolean strict )
1293         throws IOException, XmlPullParserException
1294     {
1295         String tagName = parser.getName();
1296         PublishDate publishDate = new PublishDate();
1297         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1298         {
1299             String name = parser.getAttributeName( i );
1300             String value = parser.getAttributeValue( i );
1301 
1302             if ( name.indexOf( ':' ) >= 0 )
1303             {
1304                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1305             }
1306             else if ( "position".equals( name ) )
1307             {
1308                 publishDate.setPosition( interpolatedTrimmed( value, "position" ) );
1309             }
1310             else if ( "format".equals( name ) )
1311             {
1312                 publishDate.setFormat( interpolatedTrimmed( value, "format" ) );
1313             }
1314             else if ( "timezone".equals( name ) )
1315             {
1316                 publishDate.setTimezone( interpolatedTrimmed( value, "timezone" ) );
1317             }
1318             else
1319             {
1320                 checkUnknownAttribute( parser, name, tagName, strict );
1321             }
1322         }
1323         java.util.Set parsed = new java.util.HashSet();
1324         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1325         {
1326             checkUnknownElement( parser, strict );
1327         }
1328         return publishDate;
1329     } //-- PublishDate parsePublishDate( XmlPullParser, boolean )
1330 
1331     /**
1332      * Method parseSkin.
1333      * 
1334      * @param parser a parser object.
1335      * @param strict a strict object.
1336      * @throws IOException IOException if any.
1337      * @throws XmlPullParserException XmlPullParserException if
1338      * any.
1339      * @return Skin
1340      */
1341     private Skin parseSkin( XmlPullParser parser, boolean strict )
1342         throws IOException, XmlPullParserException
1343     {
1344         String tagName = parser.getName();
1345         Skin skin = new Skin();
1346         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1347         {
1348             String name = parser.getAttributeName( i );
1349             String value = parser.getAttributeValue( i );
1350 
1351             if ( name.indexOf( ':' ) >= 0 )
1352             {
1353                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1354             }
1355             else
1356             {
1357                 checkUnknownAttribute( parser, name, tagName, strict );
1358             }
1359         }
1360         java.util.Set parsed = new java.util.HashSet();
1361         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1362         {
1363             if ( checkFieldWithDuplicate( parser, "groupId", null, parsed ) )
1364             {
1365                 skin.setGroupId( interpolatedTrimmed( parser.nextText(), "groupId" ) );
1366             }
1367             else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) )
1368             {
1369                 skin.setArtifactId( interpolatedTrimmed( parser.nextText(), "artifactId" ) );
1370             }
1371             else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
1372             {
1373                 skin.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) );
1374             }
1375             else
1376             {
1377                 checkUnknownElement( parser, strict );
1378             }
1379         }
1380         return skin;
1381     } //-- Skin parseSkin( XmlPullParser, boolean )
1382 
1383     /**
1384      * Method parseVersion.
1385      * 
1386      * @param parser a parser object.
1387      * @param strict a strict object.
1388      * @throws IOException IOException if any.
1389      * @throws XmlPullParserException XmlPullParserException if
1390      * any.
1391      * @return Version
1392      */
1393     private Version parseVersion( XmlPullParser parser, boolean strict )
1394         throws IOException, XmlPullParserException
1395     {
1396         String tagName = parser.getName();
1397         Version version = new Version();
1398         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1399         {
1400             String name = parser.getAttributeName( i );
1401             String value = parser.getAttributeValue( i );
1402 
1403             if ( name.indexOf( ':' ) >= 0 )
1404             {
1405                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1406             }
1407             else if ( "position".equals( name ) )
1408             {
1409                 version.setPosition( interpolatedTrimmed( value, "position" ) );
1410             }
1411             else
1412             {
1413                 checkUnknownAttribute( parser, name, tagName, strict );
1414             }
1415         }
1416         java.util.Set parsed = new java.util.HashSet();
1417         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1418         {
1419             checkUnknownElement( parser, strict );
1420         }
1421         return version;
1422     } //-- Version parseVersion( XmlPullParser, boolean )
1423 
1424     /**
1425      * Sets the state of the "add default entities" flag.
1426      * 
1427      * @param addDefaultEntities a addDefaultEntities object.
1428      */
1429     public void setAddDefaultEntities( boolean addDefaultEntities )
1430     {
1431         this.addDefaultEntities = addDefaultEntities;
1432     } //-- void setAddDefaultEntities( boolean )
1433 
1434     public static interface ContentTransformer
1435 {
1436     /**
1437      * Interpolate the value read from the xpp3 document
1438      * @param source The source value
1439      * @param fieldName A description of the field being interpolated. The implementation may use this to
1440      *                           log stuff.
1441      * @return The interpolated value.
1442      */
1443     String transform( String source, String fieldName );
1444 }
1445 
1446 }