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