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.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.Banner;
17  import org.apache.maven.doxia.site.Body;
18  import org.apache.maven.doxia.site.LinkItem;
19  import org.apache.maven.doxia.site.Logo;
20  import org.apache.maven.doxia.site.Menu;
21  import org.apache.maven.doxia.site.MenuItem;
22  import org.apache.maven.doxia.site.PublishDate;
23  import org.apache.maven.doxia.site.SiteModel;
24  import org.apache.maven.doxia.site.Skin;
25  import org.apache.maven.doxia.site.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 SiteXpp3Reader.
34   * 
35   * @version $Revision$ $Date$
36   */
37  @SuppressWarnings( "all" )
38  public class SiteXpp3Reader
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 SiteXpp3Reader()
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.io.xpp3.SiteXpp3Reader()
77  
78      public SiteXpp3Reader(ContentTransformer contentTransformer)
79      {
80          this.contentTransformer = contentTransformer;
81      } //-- org.apache.maven.doxia.site.io.xpp3.SiteXpp3Reader(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 SiteModel
570      */
571     public SiteModel 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     } //-- SiteModel 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 SiteModel
590      */
591     public SiteModel read( Reader reader )
592         throws IOException, XmlPullParserException
593     {
594         return read( reader, true );
595     } //-- SiteModel 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 SiteModel
606      */
607     public SiteModel read( InputStream in, boolean strict )
608         throws IOException, XmlPullParserException
609     {
610         return read( ReaderFactory.newXmlReader( in ), strict );
611     } //-- SiteModel 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 SiteModel
621      */
622     public SiteModel read( InputStream in )
623         throws IOException, XmlPullParserException
624     {
625         return read( ReaderFactory.newXmlReader( in ) );
626     } //-- SiteModel 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 parseLinkItem.
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 LinkItem
799      */
800     private LinkItem parseLinkItem( XmlPullParser parser, boolean strict )
801         throws IOException, XmlPullParserException
802     {
803         String tagName = parser.getName();
804         LinkItem linkItem = new LinkItem();
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 ( "name".equals( name ) )
815             {
816                 linkItem.setName( interpolatedTrimmed( value, "name" ) );
817             }
818             else if ( "href".equals( name ) )
819             {
820                 linkItem.setHref( interpolatedTrimmed( value, "href" ) );
821             }
822             else if ( "img".equals( name ) )
823             {
824                 linkItem.setImg( interpolatedTrimmed( value, "img" ) );
825             }
826             else if ( "position".equals( name ) )
827             {
828                 linkItem.setPosition( interpolatedTrimmed( value, "position" ) );
829             }
830             else if ( "alt".equals( name ) )
831             {
832                 linkItem.setAlt( interpolatedTrimmed( value, "alt" ) );
833             }
834             else if ( "border".equals( name ) )
835             {
836                 linkItem.setBorder( interpolatedTrimmed( value, "border" ) );
837             }
838             else if ( "width".equals( name ) )
839             {
840                 linkItem.setWidth( interpolatedTrimmed( value, "width" ) );
841             }
842             else if ( "height".equals( name ) )
843             {
844                 linkItem.setHeight( interpolatedTrimmed( value, "height" ) );
845             }
846             else if ( "target".equals( name ) )
847             {
848                 linkItem.setTarget( interpolatedTrimmed( value, "target" ) );
849             }
850             else if ( "title".equals( name ) )
851             {
852                 linkItem.setTitle( interpolatedTrimmed( value, "title" ) );
853             }
854             else
855             {
856                 checkUnknownAttribute( parser, name, tagName, strict );
857             }
858         }
859         java.util.Set parsed = new java.util.HashSet();
860         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
861         {
862             checkUnknownElement( parser, strict );
863         }
864         return linkItem;
865     } //-- LinkItem parseLinkItem( XmlPullParser, boolean )
866 
867     /**
868      * Method parseLogo.
869      * 
870      * @param parser a parser object.
871      * @param strict a strict object.
872      * @throws IOException IOException if any.
873      * @throws XmlPullParserException XmlPullParserException if
874      * any.
875      * @return Logo
876      */
877     private Logo parseLogo( XmlPullParser parser, boolean strict )
878         throws IOException, XmlPullParserException
879     {
880         String tagName = parser.getName();
881         Logo logo = new Logo();
882         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
883         {
884             String name = parser.getAttributeName( i );
885             String value = parser.getAttributeValue( i );
886 
887             if ( name.indexOf( ':' ) >= 0 )
888             {
889                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
890             }
891             else if ( "name".equals( name ) )
892             {
893                 logo.setName( interpolatedTrimmed( value, "name" ) );
894             }
895             else if ( "href".equals( name ) )
896             {
897                 logo.setHref( interpolatedTrimmed( value, "href" ) );
898             }
899             else if ( "img".equals( name ) )
900             {
901                 logo.setImg( interpolatedTrimmed( value, "img" ) );
902             }
903             else if ( "position".equals( name ) )
904             {
905                 logo.setPosition( interpolatedTrimmed( value, "position" ) );
906             }
907             else if ( "alt".equals( name ) )
908             {
909                 logo.setAlt( interpolatedTrimmed( value, "alt" ) );
910             }
911             else if ( "border".equals( name ) )
912             {
913                 logo.setBorder( interpolatedTrimmed( value, "border" ) );
914             }
915             else if ( "width".equals( name ) )
916             {
917                 logo.setWidth( interpolatedTrimmed( value, "width" ) );
918             }
919             else if ( "height".equals( name ) )
920             {
921                 logo.setHeight( interpolatedTrimmed( value, "height" ) );
922             }
923             else if ( "target".equals( name ) )
924             {
925                 logo.setTarget( interpolatedTrimmed( value, "target" ) );
926             }
927             else if ( "title".equals( name ) )
928             {
929                 logo.setTitle( interpolatedTrimmed( value, "title" ) );
930             }
931             else
932             {
933                 checkUnknownAttribute( parser, name, tagName, strict );
934             }
935         }
936         java.util.Set parsed = new java.util.HashSet();
937         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
938         {
939             checkUnknownElement( parser, strict );
940         }
941         return logo;
942     } //-- Logo parseLogo( XmlPullParser, boolean )
943 
944     /**
945      * Method parseMenu.
946      * 
947      * @param parser a parser object.
948      * @param strict a strict object.
949      * @throws IOException IOException if any.
950      * @throws XmlPullParserException XmlPullParserException if
951      * any.
952      * @return Menu
953      */
954     private Menu parseMenu( XmlPullParser parser, boolean strict )
955         throws IOException, XmlPullParserException
956     {
957         String tagName = parser.getName();
958         Menu menu = new Menu();
959         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
960         {
961             String name = parser.getAttributeName( i );
962             String value = parser.getAttributeValue( i );
963 
964             if ( name.indexOf( ':' ) >= 0 )
965             {
966                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
967             }
968             else if ( "name".equals( name ) )
969             {
970                 menu.setName( interpolatedTrimmed( value, "name" ) );
971             }
972             else if ( "inherit".equals( name ) )
973             {
974                 menu.setInherit( interpolatedTrimmed( value, "inherit" ) );
975             }
976             else if ( "inheritAsRef".equals( name ) )
977             {
978                 menu.setInheritAsRef( getBooleanValue( interpolatedTrimmed( value, "inheritAsRef" ), "inheritAsRef", parser, "false" ) );
979             }
980             else if ( "ref".equals( name ) )
981             {
982                 menu.setRef( interpolatedTrimmed( value, "ref" ) );
983             }
984             else if ( "img".equals( name ) )
985             {
986                 menu.setImg( interpolatedTrimmed( value, "img" ) );
987             }
988             else if ( "alt".equals( name ) )
989             {
990                 menu.setAlt( interpolatedTrimmed( value, "alt" ) );
991             }
992             else if ( "position".equals( name ) )
993             {
994                 menu.setPosition( interpolatedTrimmed( value, "position" ) );
995             }
996             else if ( "border".equals( name ) )
997             {
998                 menu.setBorder( interpolatedTrimmed( value, "border" ) );
999             }
1000             else if ( "width".equals( name ) )
1001             {
1002                 menu.setWidth( interpolatedTrimmed( value, "width" ) );
1003             }
1004             else if ( "height".equals( name ) )
1005             {
1006                 menu.setHeight( interpolatedTrimmed( value, "height" ) );
1007             }
1008             else if ( "title".equals( name ) )
1009             {
1010                 menu.setTitle( interpolatedTrimmed( value, "title" ) );
1011             }
1012             else
1013             {
1014                 checkUnknownAttribute( parser, name, tagName, strict );
1015             }
1016         }
1017         java.util.Set parsed = new java.util.HashSet();
1018         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1019         {
1020             if ( "item".equals( parser.getName() ) )
1021             {
1022                 java.util.List<MenuItem> items = menu.getItems();
1023                 if ( items == null )
1024                 {
1025                     items = new java.util.ArrayList<MenuItem>();
1026                     menu.setItems( items );
1027                 }
1028                 items.add( parseMenuItem( parser, strict ) );
1029             }
1030             else
1031             {
1032                 checkUnknownElement( parser, strict );
1033             }
1034         }
1035         return menu;
1036     } //-- Menu parseMenu( XmlPullParser, boolean )
1037 
1038     /**
1039      * Method parseMenuItem.
1040      * 
1041      * @param parser a parser object.
1042      * @param strict a strict object.
1043      * @throws IOException IOException if any.
1044      * @throws XmlPullParserException XmlPullParserException if
1045      * any.
1046      * @return MenuItem
1047      */
1048     private MenuItem parseMenuItem( XmlPullParser parser, boolean strict )
1049         throws IOException, XmlPullParserException
1050     {
1051         String tagName = parser.getName();
1052         MenuItem menuItem = new MenuItem();
1053         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1054         {
1055             String name = parser.getAttributeName( i );
1056             String value = parser.getAttributeValue( i );
1057 
1058             if ( name.indexOf( ':' ) >= 0 )
1059             {
1060                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1061             }
1062             else if ( "collapse".equals( name ) )
1063             {
1064                 menuItem.setCollapse( getBooleanValue( interpolatedTrimmed( value, "collapse" ), "collapse", parser, "false" ) );
1065             }
1066             else if ( "ref".equals( name ) )
1067             {
1068                 menuItem.setRef( interpolatedTrimmed( value, "ref" ) );
1069             }
1070             else if ( "name".equals( name ) )
1071             {
1072                 menuItem.setName( interpolatedTrimmed( value, "name" ) );
1073             }
1074             else if ( "href".equals( name ) )
1075             {
1076                 menuItem.setHref( interpolatedTrimmed( value, "href" ) );
1077             }
1078             else if ( "img".equals( name ) )
1079             {
1080                 menuItem.setImg( interpolatedTrimmed( value, "img" ) );
1081             }
1082             else if ( "position".equals( name ) )
1083             {
1084                 menuItem.setPosition( interpolatedTrimmed( value, "position" ) );
1085             }
1086             else if ( "alt".equals( name ) )
1087             {
1088                 menuItem.setAlt( interpolatedTrimmed( value, "alt" ) );
1089             }
1090             else if ( "border".equals( name ) )
1091             {
1092                 menuItem.setBorder( interpolatedTrimmed( value, "border" ) );
1093             }
1094             else if ( "width".equals( name ) )
1095             {
1096                 menuItem.setWidth( interpolatedTrimmed( value, "width" ) );
1097             }
1098             else if ( "height".equals( name ) )
1099             {
1100                 menuItem.setHeight( interpolatedTrimmed( value, "height" ) );
1101             }
1102             else if ( "target".equals( name ) )
1103             {
1104                 menuItem.setTarget( interpolatedTrimmed( value, "target" ) );
1105             }
1106             else if ( "title".equals( name ) )
1107             {
1108                 menuItem.setTitle( interpolatedTrimmed( value, "title" ) );
1109             }
1110             else
1111             {
1112                 checkUnknownAttribute( parser, name, tagName, strict );
1113             }
1114         }
1115         java.util.Set parsed = new java.util.HashSet();
1116         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1117         {
1118             if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
1119             {
1120                 menuItem.setDescription( interpolatedTrimmed( parser.nextText(), "description" ) );
1121             }
1122             else if ( "item".equals( parser.getName() ) )
1123             {
1124                 java.util.List<MenuItem> items = menuItem.getItems();
1125                 if ( items == null )
1126                 {
1127                     items = new java.util.ArrayList<MenuItem>();
1128                     menuItem.setItems( items );
1129                 }
1130                 items.add( parseMenuItem( parser, strict ) );
1131             }
1132             else
1133             {
1134                 checkUnknownElement( parser, strict );
1135             }
1136         }
1137         return menuItem;
1138     } //-- MenuItem parseMenuItem( XmlPullParser, boolean )
1139 
1140     /**
1141      * Method parsePublishDate.
1142      * 
1143      * @param parser a parser object.
1144      * @param strict a strict object.
1145      * @throws IOException IOException if any.
1146      * @throws XmlPullParserException XmlPullParserException if
1147      * any.
1148      * @return PublishDate
1149      */
1150     private PublishDate parsePublishDate( XmlPullParser parser, boolean strict )
1151         throws IOException, XmlPullParserException
1152     {
1153         String tagName = parser.getName();
1154         PublishDate publishDate = new PublishDate();
1155         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1156         {
1157             String name = parser.getAttributeName( i );
1158             String value = parser.getAttributeValue( i );
1159 
1160             if ( name.indexOf( ':' ) >= 0 )
1161             {
1162                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1163             }
1164             else if ( "position".equals( name ) )
1165             {
1166                 publishDate.setPosition( interpolatedTrimmed( value, "position" ) );
1167             }
1168             else if ( "format".equals( name ) )
1169             {
1170                 publishDate.setFormat( interpolatedTrimmed( value, "format" ) );
1171             }
1172             else if ( "timezone".equals( name ) )
1173             {
1174                 publishDate.setTimezone( interpolatedTrimmed( value, "timezone" ) );
1175             }
1176             else
1177             {
1178                 checkUnknownAttribute( parser, name, tagName, strict );
1179             }
1180         }
1181         java.util.Set parsed = new java.util.HashSet();
1182         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1183         {
1184             checkUnknownElement( parser, strict );
1185         }
1186         return publishDate;
1187     } //-- PublishDate parsePublishDate( XmlPullParser, boolean )
1188 
1189     /**
1190      * Method parseSiteModel.
1191      * 
1192      * @param parser a parser object.
1193      * @param strict a strict object.
1194      * @throws IOException IOException if any.
1195      * @throws XmlPullParserException XmlPullParserException if
1196      * any.
1197      * @return SiteModel
1198      */
1199     private SiteModel parseSiteModel( XmlPullParser parser, boolean strict )
1200         throws IOException, XmlPullParserException
1201     {
1202         String tagName = parser.getName();
1203         SiteModel siteModel = new SiteModel();
1204         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1205         {
1206             String name = parser.getAttributeName( i );
1207             String value = parser.getAttributeValue( i );
1208 
1209             if ( name.indexOf( ':' ) >= 0 )
1210             {
1211                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
1212             }
1213             else if ( "xmlns".equals( name ) )
1214             {
1215                 // ignore xmlns attribute in root class, which is a reserved attribute name
1216             }
1217             else if ( "name".equals( name ) )
1218             {
1219                 siteModel.setName( interpolatedTrimmed( value, "name" ) );
1220             }
1221             else if ( "combine.self".equals( name ) )
1222             {
1223                 siteModel.setCombineSelf( interpolatedTrimmed( value, "combine.self" ) );
1224             }
1225             else
1226             {
1227                 checkUnknownAttribute( parser, name, tagName, strict );
1228             }
1229         }
1230         java.util.Set parsed = new java.util.HashSet();
1231         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1232         {
1233             if ( checkFieldWithDuplicate( parser, "bannerLeft", null, parsed ) )
1234             {
1235                 siteModel.setBannerLeft( parseBanner( parser, strict ) );
1236             }
1237             else if ( checkFieldWithDuplicate( parser, "bannerRight", null, parsed ) )
1238             {
1239                 siteModel.setBannerRight( parseBanner( parser, strict ) );
1240             }
1241             else if ( checkFieldWithDuplicate( parser, "publishDate", null, parsed ) )
1242             {
1243                 siteModel.setPublishDate( parsePublishDate( parser, strict ) );
1244             }
1245             else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
1246             {
1247                 siteModel.setVersion( parseVersion( parser, strict ) );
1248             }
1249             else if ( checkFieldWithDuplicate( parser, "edit", null, parsed ) )
1250             {
1251                 siteModel.setEdit( interpolatedTrimmed( parser.nextText(), "edit" ) );
1252             }
1253             else if ( checkFieldWithDuplicate( parser, "poweredBy", null, parsed ) )
1254             {
1255                 java.util.List<Logo> poweredBy = new java.util.ArrayList<Logo>();
1256                 siteModel.setPoweredBy( poweredBy );
1257                 while ( parser.nextTag() == XmlPullParser.START_TAG )
1258                 {
1259                     if ( "logo".equals( parser.getName() ) )
1260                     {
1261                         poweredBy.add( parseLogo( parser, strict ) );
1262                     }
1263                     else
1264                     {
1265                         checkUnknownElement( parser, strict );
1266                     }
1267                 }
1268             }
1269             else if ( checkFieldWithDuplicate( parser, "skin", null, parsed ) )
1270             {
1271                 siteModel.setSkin( parseSkin( parser, strict ) );
1272             }
1273             else if ( checkFieldWithDuplicate( parser, "body", null, parsed ) )
1274             {
1275                 siteModel.setBody( parseBody( parser, strict ) );
1276             }
1277             else if ( checkFieldWithDuplicate( parser, "custom", null, parsed ) )
1278             {
1279                 siteModel.setCustom( org.codehaus.plexus.util.xml.Xpp3DomBuilder.build( parser, true ) );
1280             }
1281             else
1282             {
1283                 checkUnknownElement( parser, strict );
1284             }
1285         }
1286         return siteModel;
1287     } //-- SiteModel parseSiteModel( 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 SiteModel
1391      */
1392     private SiteModel read( XmlPullParser parser, boolean strict )
1393         throws IOException, XmlPullParserException
1394     {
1395         SiteModel siteModel = 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                 siteModel = parseSiteModel( parser, strict );
1412                 siteModel.setModelEncoding( parser.getInputEncoding() );
1413                 parsed = true;
1414             }
1415             eventType = parser.next();
1416         }
1417         if ( parsed )
1418         {
1419             return siteModel;
1420         }
1421         throw new XmlPullParserException( "Expected root element 'project' but found no element at all: invalid XML document", parser, null );
1422     } //-- SiteModel 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 }