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