View Javadoc
1   /*
2    =================== DO NOT EDIT THIS FILE ====================
3    Generated by Modello 1.4.1 on 2014-03-11 21:03:46,
4    any modifications will be overwritten.
5    ==============================================================
6    */
7   
8   package org.apache.maven.plugin.pmd.model.io.xpp3;
9   
10    //---------------------------------/
11   //- Imported classes and packages -/
12  //---------------------------------/
13  
14  import java.io.IOException;
15  import java.io.InputStream;
16  import java.io.Reader;
17  import java.text.DateFormat;
18  import java.util.Locale;
19  import org.apache.maven.plugin.pmd.model.CpdErrorDetail;
20  import org.apache.maven.plugin.pmd.model.CpdFile;
21  import org.apache.maven.plugin.pmd.model.Duplication;
22  import org.codehaus.plexus.util.ReaderFactory;
23  import org.codehaus.plexus.util.xml.pull.MXParser;
24  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
25  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
26  
27  /**
28   * Class CpdXpp3Reader.
29   * 
30   * @version $Revision: 901148 $ $Date: 2014-03-11 20:12:51 +0000 (Tue, 11 Mar 2014) $
31   */
32  @SuppressWarnings( "all" )
33  public class CpdXpp3Reader
34  {
35  
36        //--------------------------/
37       //- Class/Member Variables -/
38      //--------------------------/
39  
40      /**
41       * If set the parser will be loaded with all single characters
42       * from the XHTML specification.
43       * The entities used:
44       * <ul>
45       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>;
46       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>;
47       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>;
48       * </ul>
49       */
50      private boolean addDefaultEntities = true;
51  
52  
53        //-----------/
54       //- Methods -/
55      //-----------/
56  
57      /**
58       * Method checkFieldWithDuplicate.
59       * 
60       * @param parser
61       * @param parsed
62       * @param alias
63       * @param tagName
64       * @throws XmlPullParserException
65       * @return boolean
66       */
67      private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
68          throws XmlPullParserException
69      {
70          if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
71          {
72              return false;
73          }
74          if ( !parsed.add( tagName ) )
75          {
76              throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
77          }
78          return true;
79      } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set )
80  
81      /**
82       * Method checkUnknownAttribute.
83       * 
84       * @param parser
85       * @param strict
86       * @param tagName
87       * @param attribute
88       * @throws XmlPullParserException
89       * @throws IOException
90       */
91      private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
92          throws XmlPullParserException, IOException
93      {
94          // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
95          if ( strict )
96          {
97              throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
98          }
99      } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
100 
101     /**
102      * Method checkUnknownElement.
103      * 
104      * @param parser
105      * @param strict
106      * @throws XmlPullParserException
107      * @throws IOException
108      */
109     private void checkUnknownElement( XmlPullParser parser, boolean strict )
110         throws XmlPullParserException, IOException
111     {
112         if ( strict )
113         {
114             throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
115         }
116 
117         for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
118         {
119             int eventType = parser.next();
120             if ( eventType == XmlPullParser.START_TAG )
121             {
122                 unrecognizedTagCount++;
123             }
124             else if ( eventType == XmlPullParser.END_TAG )
125             {
126                 unrecognizedTagCount--;
127             }
128         }
129     } //-- void checkUnknownElement( XmlPullParser, boolean )
130 
131     /**
132      * Returns the state of the "add default entities" flag.
133      * 
134      * @return boolean
135      */
136     public boolean getAddDefaultEntities()
137     {
138         return addDefaultEntities;
139     } //-- boolean getAddDefaultEntities()
140 
141     /**
142      * Method getBooleanValue.
143      * 
144      * @param s
145      * @param parser
146      * @param attribute
147      * @throws XmlPullParserException
148      * @return boolean
149      */
150     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
151         throws XmlPullParserException
152     {
153         return getBooleanValue( s, attribute, parser, null );
154     } //-- boolean getBooleanValue( String, String, XmlPullParser )
155 
156     /**
157      * Method getBooleanValue.
158      * 
159      * @param s
160      * @param defaultValue
161      * @param parser
162      * @param attribute
163      * @throws XmlPullParserException
164      * @return boolean
165      */
166     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
167         throws XmlPullParserException
168     {
169         if ( s != null && s.length() != 0 )
170         {
171             return Boolean.valueOf( s ).booleanValue();
172         }
173         if ( defaultValue != null )
174         {
175             return Boolean.valueOf( defaultValue ).booleanValue();
176         }
177         return false;
178     } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
179 
180     /**
181      * Method getByteValue.
182      * 
183      * @param s
184      * @param strict
185      * @param parser
186      * @param attribute
187      * @throws XmlPullParserException
188      * @return byte
189      */
190     private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
191         throws XmlPullParserException
192     {
193         if ( s != null )
194         {
195             try
196             {
197                 return Byte.valueOf( s ).byteValue();
198             }
199             catch ( NumberFormatException nfe )
200             {
201                 if ( strict )
202                 {
203                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
204                 }
205             }
206         }
207         return 0;
208     } //-- byte getByteValue( String, String, XmlPullParser, boolean )
209 
210     /**
211      * Method getCharacterValue.
212      * 
213      * @param s
214      * @param parser
215      * @param attribute
216      * @throws XmlPullParserException
217      * @return char
218      */
219     private char getCharacterValue( String s, String attribute, XmlPullParser parser )
220         throws XmlPullParserException
221     {
222         if ( s != null )
223         {
224             return s.charAt( 0 );
225         }
226         return 0;
227     } //-- char getCharacterValue( String, String, XmlPullParser )
228 
229     /**
230      * Method getDateValue.
231      * 
232      * @param s
233      * @param parser
234      * @param attribute
235      * @throws XmlPullParserException
236      * @return Date
237      */
238     private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
239         throws XmlPullParserException
240     {
241         return getDateValue( s, attribute, null, parser );
242     } //-- java.util.Date getDateValue( String, String, XmlPullParser )
243 
244     /**
245      * Method getDateValue.
246      * 
247      * @param s
248      * @param parser
249      * @param dateFormat
250      * @param attribute
251      * @throws XmlPullParserException
252      * @return Date
253      */
254     private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
255         throws XmlPullParserException
256     {
257         if ( s != null )
258         {
259             String effectiveDateFormat = dateFormat;
260             if ( dateFormat == null )
261             {
262                 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
263             }
264             if ( "long".equals( effectiveDateFormat ) )
265             {
266                 try
267                 {
268                     return new java.util.Date( Long.parseLong( s ) );
269                 }
270                 catch ( NumberFormatException e )
271                 {
272                     throw new XmlPullParserException( e.getMessage(), parser, e );
273                 }
274             }
275             else
276             {
277                 try
278                 {
279                     DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, Locale.US );
280                     return dateParser.parse( s );
281                 }
282                 catch ( java.text.ParseException e )
283                 {
284                     throw new XmlPullParserException( e.getMessage(), parser, e );
285                 }
286             }
287         }
288         return null;
289     } //-- java.util.Date getDateValue( String, String, String, XmlPullParser )
290 
291     /**
292      * Method getDoubleValue.
293      * 
294      * @param s
295      * @param strict
296      * @param parser
297      * @param attribute
298      * @throws XmlPullParserException
299      * @return double
300      */
301     private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
302         throws XmlPullParserException
303     {
304         if ( s != null )
305         {
306             try
307             {
308                 return Double.valueOf( s ).doubleValue();
309             }
310             catch ( NumberFormatException nfe )
311             {
312                 if ( strict )
313                 {
314                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
315                 }
316             }
317         }
318         return 0;
319     } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
320 
321     /**
322      * Method getFloatValue.
323      * 
324      * @param s
325      * @param strict
326      * @param parser
327      * @param attribute
328      * @throws XmlPullParserException
329      * @return float
330      */
331     private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
332         throws XmlPullParserException
333     {
334         if ( s != null )
335         {
336             try
337             {
338                 return Float.valueOf( s ).floatValue();
339             }
340             catch ( NumberFormatException nfe )
341             {
342                 if ( strict )
343                 {
344                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
345                 }
346             }
347         }
348         return 0;
349     } //-- float getFloatValue( String, String, XmlPullParser, boolean )
350 
351     /**
352      * Method getIntegerValue.
353      * 
354      * @param s
355      * @param strict
356      * @param parser
357      * @param attribute
358      * @throws XmlPullParserException
359      * @return int
360      */
361     private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
362         throws XmlPullParserException
363     {
364         if ( s != null )
365         {
366             try
367             {
368                 return Integer.valueOf( s ).intValue();
369             }
370             catch ( NumberFormatException nfe )
371             {
372                 if ( strict )
373                 {
374                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
375                 }
376             }
377         }
378         return 0;
379     } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
380 
381     /**
382      * Method getLongValue.
383      * 
384      * @param s
385      * @param strict
386      * @param parser
387      * @param attribute
388      * @throws XmlPullParserException
389      * @return long
390      */
391     private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
392         throws XmlPullParserException
393     {
394         if ( s != null )
395         {
396             try
397             {
398                 return Long.valueOf( s ).longValue();
399             }
400             catch ( NumberFormatException nfe )
401             {
402                 if ( strict )
403                 {
404                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
405                 }
406             }
407         }
408         return 0;
409     } //-- long getLongValue( String, String, XmlPullParser, boolean )
410 
411     /**
412      * Method getRequiredAttributeValue.
413      * 
414      * @param s
415      * @param strict
416      * @param parser
417      * @param attribute
418      * @throws XmlPullParserException
419      * @return String
420      */
421     private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
422         throws XmlPullParserException
423     {
424         if ( s == null )
425         {
426             if ( strict )
427             {
428                 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
429             }
430         }
431         return s;
432     } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
433 
434     /**
435      * Method getShortValue.
436      * 
437      * @param s
438      * @param strict
439      * @param parser
440      * @param attribute
441      * @throws XmlPullParserException
442      * @return short
443      */
444     private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
445         throws XmlPullParserException
446     {
447         if ( s != null )
448         {
449             try
450             {
451                 return Short.valueOf( s ).shortValue();
452             }
453             catch ( NumberFormatException nfe )
454             {
455                 if ( strict )
456                 {
457                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
458                 }
459             }
460         }
461         return 0;
462     } //-- short getShortValue( String, String, XmlPullParser, boolean )
463 
464     /**
465      * Method getTrimmedValue.
466      * 
467      * @param s
468      * @return String
469      */
470     private String getTrimmedValue( String s )
471     {
472         if ( s != null )
473         {
474             s = s.trim();
475         }
476         return s;
477     } //-- String getTrimmedValue( String )
478 
479     /**
480      * Method initParser.
481      * 
482      * @param parser
483      * @throws XmlPullParserException
484      */
485     private void initParser( XmlPullParser parser )
486         throws XmlPullParserException
487     {
488         if ( addDefaultEntities )
489         {
490             // ----------------------------------------------------------------------
491             // Latin 1 entities
492             // ----------------------------------------------------------------------
493 
494             parser.defineEntityReplacementText( "nbsp", "\u00a0" );
495             parser.defineEntityReplacementText( "iexcl", "\u00a1" );
496             parser.defineEntityReplacementText( "cent", "\u00a2" );
497             parser.defineEntityReplacementText( "pound", "\u00a3" );
498             parser.defineEntityReplacementText( "curren", "\u00a4" );
499             parser.defineEntityReplacementText( "yen", "\u00a5" );
500             parser.defineEntityReplacementText( "brvbar", "\u00a6" );
501             parser.defineEntityReplacementText( "sect", "\u00a7" );
502             parser.defineEntityReplacementText( "uml", "\u00a8" );
503             parser.defineEntityReplacementText( "copy", "\u00a9" );
504             parser.defineEntityReplacementText( "ordf", "\u00aa" );
505             parser.defineEntityReplacementText( "laquo", "\u00ab" );
506             parser.defineEntityReplacementText( "not", "\u00ac" );
507             parser.defineEntityReplacementText( "shy", "\u00ad" );
508             parser.defineEntityReplacementText( "reg", "\u00ae" );
509             parser.defineEntityReplacementText( "macr", "\u00af" );
510             parser.defineEntityReplacementText( "deg", "\u00b0" );
511             parser.defineEntityReplacementText( "plusmn", "\u00b1" );
512             parser.defineEntityReplacementText( "sup2", "\u00b2" );
513             parser.defineEntityReplacementText( "sup3", "\u00b3" );
514             parser.defineEntityReplacementText( "acute", "\u00b4" );
515             parser.defineEntityReplacementText( "micro", "\u00b5" );
516             parser.defineEntityReplacementText( "para", "\u00b6" );
517             parser.defineEntityReplacementText( "middot", "\u00b7" );
518             parser.defineEntityReplacementText( "cedil", "\u00b8" );
519             parser.defineEntityReplacementText( "sup1", "\u00b9" );
520             parser.defineEntityReplacementText( "ordm", "\u00ba" );
521             parser.defineEntityReplacementText( "raquo", "\u00bb" );
522             parser.defineEntityReplacementText( "frac14", "\u00bc" );
523             parser.defineEntityReplacementText( "frac12", "\u00bd" );
524             parser.defineEntityReplacementText( "frac34", "\u00be" );
525             parser.defineEntityReplacementText( "iquest", "\u00bf" );
526             parser.defineEntityReplacementText( "Agrave", "\u00c0" );
527             parser.defineEntityReplacementText( "Aacute", "\u00c1" );
528             parser.defineEntityReplacementText( "Acirc", "\u00c2" );
529             parser.defineEntityReplacementText( "Atilde", "\u00c3" );
530             parser.defineEntityReplacementText( "Auml", "\u00c4" );
531             parser.defineEntityReplacementText( "Aring", "\u00c5" );
532             parser.defineEntityReplacementText( "AElig", "\u00c6" );
533             parser.defineEntityReplacementText( "Ccedil", "\u00c7" );
534             parser.defineEntityReplacementText( "Egrave", "\u00c8" );
535             parser.defineEntityReplacementText( "Eacute", "\u00c9" );
536             parser.defineEntityReplacementText( "Ecirc", "\u00ca" );
537             parser.defineEntityReplacementText( "Euml", "\u00cb" );
538             parser.defineEntityReplacementText( "Igrave", "\u00cc" );
539             parser.defineEntityReplacementText( "Iacute", "\u00cd" );
540             parser.defineEntityReplacementText( "Icirc", "\u00ce" );
541             parser.defineEntityReplacementText( "Iuml", "\u00cf" );
542             parser.defineEntityReplacementText( "ETH", "\u00d0" );
543             parser.defineEntityReplacementText( "Ntilde", "\u00d1" );
544             parser.defineEntityReplacementText( "Ograve", "\u00d2" );
545             parser.defineEntityReplacementText( "Oacute", "\u00d3" );
546             parser.defineEntityReplacementText( "Ocirc", "\u00d4" );
547             parser.defineEntityReplacementText( "Otilde", "\u00d5" );
548             parser.defineEntityReplacementText( "Ouml", "\u00d6" );
549             parser.defineEntityReplacementText( "times", "\u00d7" );
550             parser.defineEntityReplacementText( "Oslash", "\u00d8" );
551             parser.defineEntityReplacementText( "Ugrave", "\u00d9" );
552             parser.defineEntityReplacementText( "Uacute", "\u00da" );
553             parser.defineEntityReplacementText( "Ucirc", "\u00db" );
554             parser.defineEntityReplacementText( "Uuml", "\u00dc" );
555             parser.defineEntityReplacementText( "Yacute", "\u00dd" );
556             parser.defineEntityReplacementText( "THORN", "\u00de" );
557             parser.defineEntityReplacementText( "szlig", "\u00df" );
558             parser.defineEntityReplacementText( "agrave", "\u00e0" );
559             parser.defineEntityReplacementText( "aacute", "\u00e1" );
560             parser.defineEntityReplacementText( "acirc", "\u00e2" );
561             parser.defineEntityReplacementText( "atilde", "\u00e3" );
562             parser.defineEntityReplacementText( "auml", "\u00e4" );
563             parser.defineEntityReplacementText( "aring", "\u00e5" );
564             parser.defineEntityReplacementText( "aelig", "\u00e6" );
565             parser.defineEntityReplacementText( "ccedil", "\u00e7" );
566             parser.defineEntityReplacementText( "egrave", "\u00e8" );
567             parser.defineEntityReplacementText( "eacute", "\u00e9" );
568             parser.defineEntityReplacementText( "ecirc", "\u00ea" );
569             parser.defineEntityReplacementText( "euml", "\u00eb" );
570             parser.defineEntityReplacementText( "igrave", "\u00ec" );
571             parser.defineEntityReplacementText( "iacute", "\u00ed" );
572             parser.defineEntityReplacementText( "icirc", "\u00ee" );
573             parser.defineEntityReplacementText( "iuml", "\u00ef" );
574             parser.defineEntityReplacementText( "eth", "\u00f0" );
575             parser.defineEntityReplacementText( "ntilde", "\u00f1" );
576             parser.defineEntityReplacementText( "ograve", "\u00f2" );
577             parser.defineEntityReplacementText( "oacute", "\u00f3" );
578             parser.defineEntityReplacementText( "ocirc", "\u00f4" );
579             parser.defineEntityReplacementText( "otilde", "\u00f5" );
580             parser.defineEntityReplacementText( "ouml", "\u00f6" );
581             parser.defineEntityReplacementText( "divide", "\u00f7" );
582             parser.defineEntityReplacementText( "oslash", "\u00f8" );
583             parser.defineEntityReplacementText( "ugrave", "\u00f9" );
584             parser.defineEntityReplacementText( "uacute", "\u00fa" );
585             parser.defineEntityReplacementText( "ucirc", "\u00fb" );
586             parser.defineEntityReplacementText( "uuml", "\u00fc" );
587             parser.defineEntityReplacementText( "yacute", "\u00fd" );
588             parser.defineEntityReplacementText( "thorn", "\u00fe" );
589             parser.defineEntityReplacementText( "yuml", "\u00ff" );
590 
591             // ----------------------------------------------------------------------
592             // Special entities
593             // ----------------------------------------------------------------------
594 
595             parser.defineEntityReplacementText( "OElig", "\u0152" );
596             parser.defineEntityReplacementText( "oelig", "\u0153" );
597             parser.defineEntityReplacementText( "Scaron", "\u0160" );
598             parser.defineEntityReplacementText( "scaron", "\u0161" );
599             parser.defineEntityReplacementText( "Yuml", "\u0178" );
600             parser.defineEntityReplacementText( "circ", "\u02c6" );
601             parser.defineEntityReplacementText( "tilde", "\u02dc" );
602             parser.defineEntityReplacementText( "ensp", "\u2002" );
603             parser.defineEntityReplacementText( "emsp", "\u2003" );
604             parser.defineEntityReplacementText( "thinsp", "\u2009" );
605             parser.defineEntityReplacementText( "zwnj", "\u200c" );
606             parser.defineEntityReplacementText( "zwj", "\u200d" );
607             parser.defineEntityReplacementText( "lrm", "\u200e" );
608             parser.defineEntityReplacementText( "rlm", "\u200f" );
609             parser.defineEntityReplacementText( "ndash", "\u2013" );
610             parser.defineEntityReplacementText( "mdash", "\u2014" );
611             parser.defineEntityReplacementText( "lsquo", "\u2018" );
612             parser.defineEntityReplacementText( "rsquo", "\u2019" );
613             parser.defineEntityReplacementText( "sbquo", "\u201a" );
614             parser.defineEntityReplacementText( "ldquo", "\u201c" );
615             parser.defineEntityReplacementText( "rdquo", "\u201d" );
616             parser.defineEntityReplacementText( "bdquo", "\u201e" );
617             parser.defineEntityReplacementText( "dagger", "\u2020" );
618             parser.defineEntityReplacementText( "Dagger", "\u2021" );
619             parser.defineEntityReplacementText( "permil", "\u2030" );
620             parser.defineEntityReplacementText( "lsaquo", "\u2039" );
621             parser.defineEntityReplacementText( "rsaquo", "\u203a" );
622             parser.defineEntityReplacementText( "euro", "\u20ac" );
623 
624             // ----------------------------------------------------------------------
625             // Symbol entities
626             // ----------------------------------------------------------------------
627 
628             parser.defineEntityReplacementText( "fnof", "\u0192" );
629             parser.defineEntityReplacementText( "Alpha", "\u0391" );
630             parser.defineEntityReplacementText( "Beta", "\u0392" );
631             parser.defineEntityReplacementText( "Gamma", "\u0393" );
632             parser.defineEntityReplacementText( "Delta", "\u0394" );
633             parser.defineEntityReplacementText( "Epsilon", "\u0395" );
634             parser.defineEntityReplacementText( "Zeta", "\u0396" );
635             parser.defineEntityReplacementText( "Eta", "\u0397" );
636             parser.defineEntityReplacementText( "Theta", "\u0398" );
637             parser.defineEntityReplacementText( "Iota", "\u0399" );
638             parser.defineEntityReplacementText( "Kappa", "\u039a" );
639             parser.defineEntityReplacementText( "Lambda", "\u039b" );
640             parser.defineEntityReplacementText( "Mu", "\u039c" );
641             parser.defineEntityReplacementText( "Nu", "\u039d" );
642             parser.defineEntityReplacementText( "Xi", "\u039e" );
643             parser.defineEntityReplacementText( "Omicron", "\u039f" );
644             parser.defineEntityReplacementText( "Pi", "\u03a0" );
645             parser.defineEntityReplacementText( "Rho", "\u03a1" );
646             parser.defineEntityReplacementText( "Sigma", "\u03a3" );
647             parser.defineEntityReplacementText( "Tau", "\u03a4" );
648             parser.defineEntityReplacementText( "Upsilon", "\u03a5" );
649             parser.defineEntityReplacementText( "Phi", "\u03a6" );
650             parser.defineEntityReplacementText( "Chi", "\u03a7" );
651             parser.defineEntityReplacementText( "Psi", "\u03a8" );
652             parser.defineEntityReplacementText( "Omega", "\u03a9" );
653             parser.defineEntityReplacementText( "alpha", "\u03b1" );
654             parser.defineEntityReplacementText( "beta", "\u03b2" );
655             parser.defineEntityReplacementText( "gamma", "\u03b3" );
656             parser.defineEntityReplacementText( "delta", "\u03b4" );
657             parser.defineEntityReplacementText( "epsilon", "\u03b5" );
658             parser.defineEntityReplacementText( "zeta", "\u03b6" );
659             parser.defineEntityReplacementText( "eta", "\u03b7" );
660             parser.defineEntityReplacementText( "theta", "\u03b8" );
661             parser.defineEntityReplacementText( "iota", "\u03b9" );
662             parser.defineEntityReplacementText( "kappa", "\u03ba" );
663             parser.defineEntityReplacementText( "lambda", "\u03bb" );
664             parser.defineEntityReplacementText( "mu", "\u03bc" );
665             parser.defineEntityReplacementText( "nu", "\u03bd" );
666             parser.defineEntityReplacementText( "xi", "\u03be" );
667             parser.defineEntityReplacementText( "omicron", "\u03bf" );
668             parser.defineEntityReplacementText( "pi", "\u03c0" );
669             parser.defineEntityReplacementText( "rho", "\u03c1" );
670             parser.defineEntityReplacementText( "sigmaf", "\u03c2" );
671             parser.defineEntityReplacementText( "sigma", "\u03c3" );
672             parser.defineEntityReplacementText( "tau", "\u03c4" );
673             parser.defineEntityReplacementText( "upsilon", "\u03c5" );
674             parser.defineEntityReplacementText( "phi", "\u03c6" );
675             parser.defineEntityReplacementText( "chi", "\u03c7" );
676             parser.defineEntityReplacementText( "psi", "\u03c8" );
677             parser.defineEntityReplacementText( "omega", "\u03c9" );
678             parser.defineEntityReplacementText( "thetasym", "\u03d1" );
679             parser.defineEntityReplacementText( "upsih", "\u03d2" );
680             parser.defineEntityReplacementText( "piv", "\u03d6" );
681             parser.defineEntityReplacementText( "bull", "\u2022" );
682             parser.defineEntityReplacementText( "hellip", "\u2026" );
683             parser.defineEntityReplacementText( "prime", "\u2032" );
684             parser.defineEntityReplacementText( "Prime", "\u2033" );
685             parser.defineEntityReplacementText( "oline", "\u203e" );
686             parser.defineEntityReplacementText( "frasl", "\u2044" );
687             parser.defineEntityReplacementText( "weierp", "\u2118" );
688             parser.defineEntityReplacementText( "image", "\u2111" );
689             parser.defineEntityReplacementText( "real", "\u211c" );
690             parser.defineEntityReplacementText( "trade", "\u2122" );
691             parser.defineEntityReplacementText( "alefsym", "\u2135" );
692             parser.defineEntityReplacementText( "larr", "\u2190" );
693             parser.defineEntityReplacementText( "uarr", "\u2191" );
694             parser.defineEntityReplacementText( "rarr", "\u2192" );
695             parser.defineEntityReplacementText( "darr", "\u2193" );
696             parser.defineEntityReplacementText( "harr", "\u2194" );
697             parser.defineEntityReplacementText( "crarr", "\u21b5" );
698             parser.defineEntityReplacementText( "lArr", "\u21d0" );
699             parser.defineEntityReplacementText( "uArr", "\u21d1" );
700             parser.defineEntityReplacementText( "rArr", "\u21d2" );
701             parser.defineEntityReplacementText( "dArr", "\u21d3" );
702             parser.defineEntityReplacementText( "hArr", "\u21d4" );
703             parser.defineEntityReplacementText( "forall", "\u2200" );
704             parser.defineEntityReplacementText( "part", "\u2202" );
705             parser.defineEntityReplacementText( "exist", "\u2203" );
706             parser.defineEntityReplacementText( "empty", "\u2205" );
707             parser.defineEntityReplacementText( "nabla", "\u2207" );
708             parser.defineEntityReplacementText( "isin", "\u2208" );
709             parser.defineEntityReplacementText( "notin", "\u2209" );
710             parser.defineEntityReplacementText( "ni", "\u220b" );
711             parser.defineEntityReplacementText( "prod", "\u220f" );
712             parser.defineEntityReplacementText( "sum", "\u2211" );
713             parser.defineEntityReplacementText( "minus", "\u2212" );
714             parser.defineEntityReplacementText( "lowast", "\u2217" );
715             parser.defineEntityReplacementText( "radic", "\u221a" );
716             parser.defineEntityReplacementText( "prop", "\u221d" );
717             parser.defineEntityReplacementText( "infin", "\u221e" );
718             parser.defineEntityReplacementText( "ang", "\u2220" );
719             parser.defineEntityReplacementText( "and", "\u2227" );
720             parser.defineEntityReplacementText( "or", "\u2228" );
721             parser.defineEntityReplacementText( "cap", "\u2229" );
722             parser.defineEntityReplacementText( "cup", "\u222a" );
723             parser.defineEntityReplacementText( "int", "\u222b" );
724             parser.defineEntityReplacementText( "there4", "\u2234" );
725             parser.defineEntityReplacementText( "sim", "\u223c" );
726             parser.defineEntityReplacementText( "cong", "\u2245" );
727             parser.defineEntityReplacementText( "asymp", "\u2248" );
728             parser.defineEntityReplacementText( "ne", "\u2260" );
729             parser.defineEntityReplacementText( "equiv", "\u2261" );
730             parser.defineEntityReplacementText( "le", "\u2264" );
731             parser.defineEntityReplacementText( "ge", "\u2265" );
732             parser.defineEntityReplacementText( "sub", "\u2282" );
733             parser.defineEntityReplacementText( "sup", "\u2283" );
734             parser.defineEntityReplacementText( "nsub", "\u2284" );
735             parser.defineEntityReplacementText( "sube", "\u2286" );
736             parser.defineEntityReplacementText( "supe", "\u2287" );
737             parser.defineEntityReplacementText( "oplus", "\u2295" );
738             parser.defineEntityReplacementText( "otimes", "\u2297" );
739             parser.defineEntityReplacementText( "perp", "\u22a5" );
740             parser.defineEntityReplacementText( "sdot", "\u22c5" );
741             parser.defineEntityReplacementText( "lceil", "\u2308" );
742             parser.defineEntityReplacementText( "rceil", "\u2309" );
743             parser.defineEntityReplacementText( "lfloor", "\u230a" );
744             parser.defineEntityReplacementText( "rfloor", "\u230b" );
745             parser.defineEntityReplacementText( "lang", "\u2329" );
746             parser.defineEntityReplacementText( "rang", "\u232a" );
747             parser.defineEntityReplacementText( "loz", "\u25ca" );
748             parser.defineEntityReplacementText( "spades", "\u2660" );
749             parser.defineEntityReplacementText( "clubs", "\u2663" );
750             parser.defineEntityReplacementText( "hearts", "\u2665" );
751             parser.defineEntityReplacementText( "diams", "\u2666" );
752 
753         }
754     } //-- void initParser( XmlPullParser )
755 
756     /**
757      * Method nextTag.
758      * 
759      * @param parser
760      * @throws IOException
761      * @throws XmlPullParserException
762      * @return int
763      */
764     private int nextTag( XmlPullParser parser )
765         throws IOException, XmlPullParserException
766     {
767         int eventType = parser.next();
768         if ( eventType == XmlPullParser.TEXT )
769         {
770             eventType = parser.next();
771         }
772         if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
773         {
774             throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
775         }
776         return eventType;
777     } //-- int nextTag( XmlPullParser )
778 
779     /**
780      * Method parseCpdErrorDetail.
781      * 
782      * @param parser
783      * @param strict
784      * @throws IOException
785      * @throws XmlPullParserException
786      * @return CpdErrorDetail
787      */
788     private CpdErrorDetail parseCpdErrorDetail( XmlPullParser parser, boolean strict )
789         throws IOException, XmlPullParserException
790     {
791         String tagName = parser.getName();
792         CpdErrorDetail cpdErrorDetail = new CpdErrorDetail();
793         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
794         {
795             String name = parser.getAttributeName( i );
796             String value = parser.getAttributeValue( i );
797 
798             if ( name.indexOf( ':' ) >= 0 )
799             {
800                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
801             }
802             else if ( "xmlns".equals( name ) )
803             {
804                 // ignore xmlns attribute in root class, which is a reserved attribute name
805             }
806             else
807             {
808                 checkUnknownAttribute( parser, name, tagName, strict );
809             }
810         }
811         java.util.Set parsed = new java.util.HashSet();
812         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
813         {
814             if ( "duplication".equals( parser.getName() ) )
815             {
816                 java.util.List duplications = cpdErrorDetail.getDuplications();
817                 if ( duplications == null )
818                 {
819                     duplications = new java.util.ArrayList/*<Duplication>*/();
820                     cpdErrorDetail.setDuplications( duplications );
821                 }
822                 duplications.add( parseDuplication( parser, strict ) );
823             }
824             else
825             {
826                 checkUnknownElement( parser, strict );
827             }
828         }
829         return cpdErrorDetail;
830     } //-- CpdErrorDetail parseCpdErrorDetail( XmlPullParser, boolean )
831 
832     /**
833      * Method parseCpdFile.
834      * 
835      * @param parser
836      * @param strict
837      * @throws IOException
838      * @throws XmlPullParserException
839      * @return CpdFile
840      */
841     private CpdFile parseCpdFile( XmlPullParser parser, boolean strict )
842         throws IOException, XmlPullParserException
843     {
844         String tagName = parser.getName();
845         CpdFile cpdFile = new CpdFile();
846         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
847         {
848             String name = parser.getAttributeName( i );
849             String value = parser.getAttributeValue( i );
850 
851             if ( name.indexOf( ':' ) >= 0 )
852             {
853                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
854             }
855             else if ( "line".equals( name ) )
856             {
857                 cpdFile.setLine( getIntegerValue( getTrimmedValue( value ), "line", parser, strict ) );
858             }
859             else if ( "path".equals( name ) )
860             {
861                 cpdFile.setPath( getTrimmedValue( value ) );
862             }
863             else
864             {
865                 checkUnknownAttribute( parser, name, tagName, strict );
866             }
867         }
868         java.util.Set parsed = new java.util.HashSet();
869         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
870         {
871             checkUnknownElement( parser, strict );
872         }
873         return cpdFile;
874     } //-- CpdFile parseCpdFile( XmlPullParser, boolean )
875 
876     /**
877      * Method parseDuplication.
878      * 
879      * @param parser
880      * @param strict
881      * @throws IOException
882      * @throws XmlPullParserException
883      * @return Duplication
884      */
885     private Duplication parseDuplication( XmlPullParser parser, boolean strict )
886         throws IOException, XmlPullParserException
887     {
888         String tagName = parser.getName();
889         Duplication duplication = new Duplication();
890         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
891         {
892             String name = parser.getAttributeName( i );
893             String value = parser.getAttributeValue( i );
894 
895             if ( name.indexOf( ':' ) >= 0 )
896             {
897                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
898             }
899             else if ( "lines".equals( name ) )
900             {
901                 duplication.setLines( getIntegerValue( getTrimmedValue( value ), "lines", parser, strict ) );
902             }
903             else if ( "tokens".equals( name ) )
904             {
905                 duplication.setTokens( getIntegerValue( getTrimmedValue( value ), "tokens", parser, strict ) );
906             }
907             else
908             {
909                 checkUnknownAttribute( parser, name, tagName, strict );
910             }
911         }
912         java.util.Set parsed = new java.util.HashSet();
913         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
914         {
915             if ( "file".equals( parser.getName() ) )
916             {
917                 java.util.List files = duplication.getFiles();
918                 if ( files == null )
919                 {
920                     files = new java.util.ArrayList/*<CpdFile>*/();
921                     duplication.setFiles( files );
922                 }
923                 files.add( parseCpdFile( parser, strict ) );
924             }
925             else if ( checkFieldWithDuplicate( parser, "codefragment", null, parsed ) )
926             {
927                 duplication.setCodefragment( getTrimmedValue( parser.nextText() ) );
928             }
929             else
930             {
931                 checkUnknownElement( parser, strict );
932             }
933         }
934         return duplication;
935     } //-- Duplication parseDuplication( XmlPullParser, boolean )
936 
937     /**
938      * @see ReaderFactory#newXmlReader
939      * 
940      * @param reader
941      * @param strict
942      * @throws IOException
943      * @throws XmlPullParserException
944      * @return CpdErrorDetail
945      */
946     public CpdErrorDetail read( Reader reader, boolean strict )
947         throws IOException, XmlPullParserException
948     {
949         XmlPullParser parser = new MXParser();
950 
951         parser.setInput( reader );
952 
953         initParser( parser );
954 
955         return read( parser, strict );
956     } //-- CpdErrorDetail read( Reader, boolean )
957 
958     /**
959      * @see ReaderFactory#newXmlReader
960      * 
961      * @param reader
962      * @throws IOException
963      * @throws XmlPullParserException
964      * @return CpdErrorDetail
965      */
966     public CpdErrorDetail read( Reader reader )
967         throws IOException, XmlPullParserException
968     {
969         return read( reader, true );
970     } //-- CpdErrorDetail read( Reader )
971 
972     /**
973      * Method read.
974      * 
975      * @param in
976      * @param strict
977      * @throws IOException
978      * @throws XmlPullParserException
979      * @return CpdErrorDetail
980      */
981     public CpdErrorDetail read( InputStream in, boolean strict )
982         throws IOException, XmlPullParserException
983     {
984         return read( ReaderFactory.newXmlReader( in ), strict );
985     } //-- CpdErrorDetail read( InputStream, boolean )
986 
987     /**
988      * Method read.
989      * 
990      * @param in
991      * @throws IOException
992      * @throws XmlPullParserException
993      * @return CpdErrorDetail
994      */
995     public CpdErrorDetail read( InputStream in )
996         throws IOException, XmlPullParserException
997     {
998         return read( ReaderFactory.newXmlReader( in ) );
999     } //-- CpdErrorDetail read( InputStream )
1000 
1001     /**
1002      * Method read.
1003      * 
1004      * @param parser
1005      * @param strict
1006      * @throws IOException
1007      * @throws XmlPullParserException
1008      * @return CpdErrorDetail
1009      */
1010     private CpdErrorDetail read( XmlPullParser parser, boolean strict )
1011         throws IOException, XmlPullParserException
1012     {
1013         int eventType = parser.getEventType();
1014         while ( eventType != XmlPullParser.END_DOCUMENT )
1015         {
1016             if ( eventType == XmlPullParser.START_TAG )
1017             {
1018                 if ( strict && ! "pmd-cpd".equals( parser.getName() ) )
1019                 {
1020                     throw new XmlPullParserException( "Expected root element 'pmd-cpd' but found '" + parser.getName() + "'", parser, null );
1021                 }
1022                 CpdErrorDetail cpdErrorDetail = parseCpdErrorDetail( parser, strict );
1023                 cpdErrorDetail.setModelEncoding( parser.getInputEncoding() );
1024                 return cpdErrorDetail;
1025             }
1026             eventType = parser.next();
1027         }
1028         throw new XmlPullParserException( "Expected root element 'pmd-cpd' but found no element at all: invalid XML document", parser, null );
1029     } //-- CpdErrorDetail read( XmlPullParser, boolean )
1030 
1031     /**
1032      * Sets the state of the "add default entities" flag.
1033      * 
1034      * @param addDefaultEntities
1035      */
1036     public void setAddDefaultEntities( boolean addDefaultEntities )
1037     {
1038         this.addDefaultEntities = addDefaultEntities;
1039     } //-- void setAddDefaultEntities( boolean )
1040 
1041 }