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