View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 2.3.0,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.plugins.pmd.model.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.plugins.pmd.model.CpdErrorDetail;
17  import org.apache.maven.plugins.pmd.model.CpdFile;
18  import org.apache.maven.plugins.pmd.model.Duplication;
19  import org.codehaus.plexus.util.xml.XmlStreamReader;
20  import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
21  import org.codehaus.plexus.util.xml.pull.MXParser;
22  import org.codehaus.plexus.util.xml.pull.XmlPullParser;
23  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
24  
25  /**
26   * Class CpdXpp3Reader.
27   * 
28   * @version $Revision$ $Date$
29   */
30  @SuppressWarnings( "all" )
31  public class CpdXpp3Reader
32  {
33  
34        //--------------------------/
35       //- Class/Member Variables -/
36      //--------------------------/
37  
38      /**
39       * If set the parser will be loaded with all single characters
40       * from the XHTML specification.
41       * The entities used:
42       * <ul>
43       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</li>
44       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent</li>
45       * <li>http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent</li>
46       * </ul>
47       */
48      private boolean addDefaultEntities = true;
49  
50      /**
51       * Field contentTransformer.
52       */
53      public final ContentTransformer contentTransformer;
54  
55  
56        //----------------/
57       //- Constructors -/
58      //----------------/
59  
60      public CpdXpp3Reader()
61      {
62          this( new ContentTransformer()
63          {
64              public String transform( String source, String fieldName )
65              {
66                  return source;
67              }
68          } );
69      } //-- org.apache.maven.plugins.pmd.model.io.xpp3.CpdXpp3Reader()
70  
71      public CpdXpp3Reader(ContentTransformer contentTransformer)
72      {
73          this.contentTransformer = contentTransformer;
74      } //-- org.apache.maven.plugins.pmd.model.io.xpp3.CpdXpp3Reader(ContentTransformer)
75  
76  
77        //-----------/
78       //- Methods -/
79      //-----------/
80  
81      /**
82       * Method checkFieldWithDuplicate.
83       * 
84       * @param parser a parser object.
85       * @param parsed a parsed object.
86       * @param alias a alias object.
87       * @param tagName a tagName object.
88       * @throws XmlPullParserException XmlPullParserException if
89       * any.
90       * @return boolean
91       */
92      private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set<String> parsed )
93          throws XmlPullParserException
94      {
95          if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
96          {
97              return false;
98          }
99          if ( !parsed.add( tagName ) )
100         {
101             throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
102         }
103         return true;
104     } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set )
105 
106     /**
107      * Method checkUnknownAttribute.
108      * 
109      * @param parser a parser object.
110      * @param strict a strict object.
111      * @param tagName a tagName object.
112      * @param attribute a attribute object.
113      * @throws XmlPullParserException XmlPullParserException if
114      * any.
115      * @throws IOException IOException if any.
116      */
117     private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
118         throws XmlPullParserException, IOException
119     {
120         // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
121         if ( strict )
122         {
123             throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
124         }
125     } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
126 
127     /**
128      * Method checkUnknownElement.
129      * 
130      * @param parser a parser object.
131      * @param strict a strict object.
132      * @throws XmlPullParserException XmlPullParserException if
133      * any.
134      * @throws IOException IOException if any.
135      */
136     private void checkUnknownElement( XmlPullParser parser, boolean strict )
137         throws XmlPullParserException, IOException
138     {
139         if ( strict )
140         {
141             throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
142         }
143 
144         for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
145         {
146             int eventType = parser.next();
147             if ( eventType == XmlPullParser.START_TAG )
148             {
149                 unrecognizedTagCount++;
150             }
151             else if ( eventType == XmlPullParser.END_TAG )
152             {
153                 unrecognizedTagCount--;
154             }
155         }
156     } //-- void checkUnknownElement( XmlPullParser, boolean )
157 
158     /**
159      * Returns the state of the "add default entities" flag.
160      * 
161      * @return boolean
162      */
163     public boolean getAddDefaultEntities()
164     {
165         return addDefaultEntities;
166     } //-- boolean getAddDefaultEntities()
167 
168     /**
169      * Method getBooleanValue.
170      * 
171      * @param s a s object.
172      * @param parser a parser object.
173      * @param attribute a attribute object.
174      * @throws XmlPullParserException XmlPullParserException if
175      * any.
176      * @return boolean
177      */
178     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
179         throws XmlPullParserException
180     {
181         return getBooleanValue( s, attribute, parser, null );
182     } //-- boolean getBooleanValue( String, String, XmlPullParser )
183 
184     /**
185      * Method getBooleanValue.
186      * 
187      * @param s a s object.
188      * @param defaultValue a defaultValue object.
189      * @param parser a parser object.
190      * @param attribute a attribute object.
191      * @throws XmlPullParserException XmlPullParserException if
192      * any.
193      * @return boolean
194      */
195     private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
196         throws XmlPullParserException
197     {
198         if ( s != null && s.length() != 0 )
199         {
200             return Boolean.valueOf( s ).booleanValue();
201         }
202         if ( defaultValue != null )
203         {
204             return Boolean.valueOf( defaultValue ).booleanValue();
205         }
206         return false;
207     } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
208 
209     /**
210      * Method getByteValue.
211      * 
212      * @param s a s object.
213      * @param strict a strict object.
214      * @param parser a parser object.
215      * @param attribute a attribute object.
216      * @throws XmlPullParserException XmlPullParserException if
217      * any.
218      * @return byte
219      */
220     private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
221         throws XmlPullParserException
222     {
223         if ( s != null )
224         {
225             try
226             {
227                 return Byte.valueOf( s ).byteValue();
228             }
229             catch ( NumberFormatException nfe )
230             {
231                 if ( strict )
232                 {
233                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
234                 }
235             }
236         }
237         return 0;
238     } //-- byte getByteValue( String, String, XmlPullParser, boolean )
239 
240     /**
241      * Method getCharacterValue.
242      * 
243      * @param s a s object.
244      * @param parser a parser object.
245      * @param attribute a attribute object.
246      * @throws XmlPullParserException XmlPullParserException if
247      * any.
248      * @return char
249      */
250     private char getCharacterValue( String s, String attribute, XmlPullParser parser )
251         throws XmlPullParserException
252     {
253         if ( s != null )
254         {
255             return s.charAt( 0 );
256         }
257         return 0;
258     } //-- char getCharacterValue( String, String, XmlPullParser )
259 
260     /**
261      * Method getDateValue.
262      * 
263      * @param s a s object.
264      * @param parser a parser object.
265      * @param attribute a attribute object.
266      * @throws XmlPullParserException XmlPullParserException if
267      * any.
268      * @return Date
269      */
270     private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
271         throws XmlPullParserException
272     {
273         return getDateValue( s, attribute, null, parser );
274     } //-- java.util.Date getDateValue( String, String, XmlPullParser )
275 
276     /**
277      * Method getDateValue.
278      * 
279      * @param s a s object.
280      * @param parser a parser object.
281      * @param dateFormat a dateFormat object.
282      * @param attribute a attribute object.
283      * @throws XmlPullParserException XmlPullParserException if
284      * any.
285      * @return Date
286      */
287     private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
288         throws XmlPullParserException
289     {
290         if ( s != null )
291         {
292             String effectiveDateFormat = dateFormat;
293             if ( dateFormat == null )
294             {
295                 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
296             }
297             if ( "long".equals( effectiveDateFormat ) )
298             {
299                 try
300                 {
301                     return new java.util.Date( Long.parseLong( s ) );
302                 }
303                 catch ( NumberFormatException e )
304                 {
305                     throw new XmlPullParserException( e.getMessage(), parser, e );
306                 }
307             }
308             else
309             {
310                 try
311                 {
312                     DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
313                     return dateParser.parse( s );
314                 }
315                 catch ( java.text.ParseException e )
316                 {
317                     throw new XmlPullParserException( e.getMessage(), parser, e );
318                 }
319             }
320         }
321         return null;
322     } //-- java.util.Date getDateValue( String, String, String, XmlPullParser )
323 
324     /**
325      * Method getDoubleValue.
326      * 
327      * @param s a s object.
328      * @param strict a strict object.
329      * @param parser a parser object.
330      * @param attribute a attribute object.
331      * @throws XmlPullParserException XmlPullParserException if
332      * any.
333      * @return double
334      */
335     private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
336         throws XmlPullParserException
337     {
338         if ( s != null )
339         {
340             try
341             {
342                 return Double.valueOf( s ).doubleValue();
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     } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
354 
355     /**
356      * Method getFloatValue.
357      * 
358      * @param s a s object.
359      * @param strict a strict object.
360      * @param parser a parser object.
361      * @param attribute a attribute object.
362      * @throws XmlPullParserException XmlPullParserException if
363      * any.
364      * @return float
365      */
366     private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
367         throws XmlPullParserException
368     {
369         if ( s != null )
370         {
371             try
372             {
373                 return Float.valueOf( s ).floatValue();
374             }
375             catch ( NumberFormatException nfe )
376             {
377                 if ( strict )
378                 {
379                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
380                 }
381             }
382         }
383         return 0;
384     } //-- float getFloatValue( String, String, XmlPullParser, boolean )
385 
386     /**
387      * Method getIntegerValue.
388      * 
389      * @param s a s object.
390      * @param strict a strict object.
391      * @param parser a parser object.
392      * @param attribute a attribute object.
393      * @throws XmlPullParserException XmlPullParserException if
394      * any.
395      * @return int
396      */
397     private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
398         throws XmlPullParserException
399     {
400         if ( s != null )
401         {
402             try
403             {
404                 return Integer.valueOf( s ).intValue();
405             }
406             catch ( NumberFormatException nfe )
407             {
408                 if ( strict )
409                 {
410                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
411                 }
412             }
413         }
414         return 0;
415     } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
416 
417     /**
418      * Method getLongValue.
419      * 
420      * @param s a s object.
421      * @param strict a strict object.
422      * @param parser a parser object.
423      * @param attribute a attribute object.
424      * @throws XmlPullParserException XmlPullParserException if
425      * any.
426      * @return long
427      */
428     private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
429         throws XmlPullParserException
430     {
431         if ( s != null )
432         {
433             try
434             {
435                 return Long.valueOf( s ).longValue();
436             }
437             catch ( NumberFormatException nfe )
438             {
439                 if ( strict )
440                 {
441                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
442                 }
443             }
444         }
445         return 0;
446     } //-- long getLongValue( String, String, XmlPullParser, boolean )
447 
448     /**
449      * Method getRequiredAttributeValue.
450      * 
451      * @param s a s object.
452      * @param strict a strict object.
453      * @param parser a parser object.
454      * @param attribute a attribute object.
455      * @throws XmlPullParserException XmlPullParserException if
456      * any.
457      * @return String
458      */
459     private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
460         throws XmlPullParserException
461     {
462         if ( s == null )
463         {
464             if ( strict )
465             {
466                 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
467             }
468         }
469         return s;
470     } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
471 
472     /**
473      * Method getShortValue.
474      * 
475      * @param s a s object.
476      * @param strict a strict object.
477      * @param parser a parser object.
478      * @param attribute a attribute object.
479      * @throws XmlPullParserException XmlPullParserException if
480      * any.
481      * @return short
482      */
483     private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
484         throws XmlPullParserException
485     {
486         if ( s != null )
487         {
488             try
489             {
490                 return Short.valueOf( s ).shortValue();
491             }
492             catch ( NumberFormatException nfe )
493             {
494                 if ( strict )
495                 {
496                     throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
497                 }
498             }
499         }
500         return 0;
501     } //-- short getShortValue( String, String, XmlPullParser, boolean )
502 
503     /**
504      * Method getTrimmedValue.
505      * 
506      * @param s a s object.
507      * @return String
508      */
509     private String getTrimmedValue( String s )
510     {
511         if ( s != null )
512         {
513             s = s.trim();
514         }
515         return s;
516     } //-- String getTrimmedValue( String )
517 
518     /**
519      * Method interpolatedTrimmed.
520      * 
521      * @param value a value object.
522      * @param context a context object.
523      * @return String
524      */
525     private String interpolatedTrimmed( String value, String context )
526     {
527         return getTrimmedValue( contentTransformer.transform( value, context ) );
528     } //-- String interpolatedTrimmed( String, String )
529 
530     /**
531      * Method nextTag.
532      * 
533      * @param parser a parser object.
534      * @throws IOException IOException if any.
535      * @throws XmlPullParserException XmlPullParserException if
536      * any.
537      * @return int
538      */
539     private int nextTag( XmlPullParser parser )
540         throws IOException, XmlPullParserException
541     {
542         int eventType = parser.next();
543         if ( eventType == XmlPullParser.TEXT )
544         {
545             eventType = parser.next();
546         }
547         if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
548         {
549             throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
550         }
551         return eventType;
552     } //-- int nextTag( XmlPullParser )
553 
554     /**
555      * Method read.
556      * 
557      * @param parser a parser object.
558      * @param strict a strict object.
559      * @throws IOException IOException if any.
560      * @throws XmlPullParserException XmlPullParserException if
561      * any.
562      * @return CpdErrorDetail
563      */
564     public CpdErrorDetail read( XmlPullParser parser, boolean strict )
565         throws IOException, XmlPullParserException
566     {
567         CpdErrorDetail cpdErrorDetail = null;
568         int eventType = parser.getEventType();
569         boolean parsed = false;
570         while ( eventType != XmlPullParser.END_DOCUMENT )
571         {
572             if ( eventType == XmlPullParser.START_TAG )
573             {
574                 if ( strict && ! "pmd-cpd".equals( parser.getName() ) )
575                 {
576                     throw new XmlPullParserException( "Expected root element 'pmd-cpd' but found '" + parser.getName() + "'", parser, null );
577                 }
578                 else if ( parsed )
579                 {
580                     // fallback, already expected a XmlPullParserException due to invalid XML
581                     throw new XmlPullParserException( "Duplicated tag: 'pmd-cpd'", parser, null );
582                 }
583                 cpdErrorDetail = parseCpdErrorDetail( parser, strict );
584                 cpdErrorDetail.setModelEncoding( parser.getInputEncoding() );
585                 parsed = true;
586             }
587             eventType = parser.next();
588         }
589         if ( parsed )
590         {
591             return cpdErrorDetail;
592         }
593         throw new XmlPullParserException( "Expected root element 'pmd-cpd' but found no element at all: invalid XML document", parser, null );
594     } //-- CpdErrorDetail read( XmlPullParser, boolean )
595 
596     /**
597      * @see XmlStreamReader
598      * 
599      * @param reader a reader object.
600      * @param strict a strict object.
601      * @throws IOException IOException if any.
602      * @throws XmlPullParserException XmlPullParserException if
603      * any.
604      * @return CpdErrorDetail
605      */
606     public CpdErrorDetail read( Reader reader, boolean strict )
607         throws IOException, XmlPullParserException
608     {
609         XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
610 
611         parser.setInput( reader );
612 
613 
614         return read( parser, strict );
615     } //-- CpdErrorDetail read( Reader, boolean )
616 
617     /**
618      * @see XmlStreamReader
619      * 
620      * @param reader a reader object.
621      * @throws IOException IOException if any.
622      * @throws XmlPullParserException XmlPullParserException if
623      * any.
624      * @return CpdErrorDetail
625      */
626     public CpdErrorDetail read( Reader reader )
627         throws IOException, XmlPullParserException
628     {
629         return read( reader, true );
630     } //-- CpdErrorDetail read( Reader )
631 
632     /**
633      * Method read.
634      * 
635      * @param in a in object.
636      * @param strict a strict object.
637      * @throws IOException IOException if any.
638      * @throws XmlPullParserException XmlPullParserException if
639      * any.
640      * @return CpdErrorDetail
641      */
642     public CpdErrorDetail read( InputStream in, boolean strict )
643         throws IOException, XmlPullParserException
644     {
645         return read( new XmlStreamReader( in ), strict );
646     } //-- CpdErrorDetail read( InputStream, boolean )
647 
648     /**
649      * Method read.
650      * 
651      * @param in a in object.
652      * @throws IOException IOException if any.
653      * @throws XmlPullParserException XmlPullParserException if
654      * any.
655      * @return CpdErrorDetail
656      */
657     public CpdErrorDetail read( InputStream in )
658         throws IOException, XmlPullParserException
659     {
660         return read( new XmlStreamReader( in ) );
661     } //-- CpdErrorDetail read( InputStream )
662 
663     /**
664      * Method parseCpdErrorDetail.
665      * 
666      * @param parser a parser object.
667      * @param strict a strict object.
668      * @throws IOException IOException if any.
669      * @throws XmlPullParserException XmlPullParserException if
670      * any.
671      * @return CpdErrorDetail
672      */
673     private CpdErrorDetail parseCpdErrorDetail( XmlPullParser parser, boolean strict )
674         throws IOException, XmlPullParserException
675     {
676         String tagName = parser.getName();
677         CpdErrorDetail cpdErrorDetail = new CpdErrorDetail();
678         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
679         {
680             String name = parser.getAttributeName( i );
681             String value = parser.getAttributeValue( i );
682 
683             if ( name.indexOf( ':' ) >= 0 )
684             {
685                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
686             }
687             else if ( "xmlns".equals( name ) )
688             {
689                 // ignore xmlns attribute in root class, which is a reserved attribute name
690             }
691             else
692             {
693                 checkUnknownAttribute( parser, name, tagName, strict );
694             }
695         }
696         java.util.Set<String> parsed = new java.util.HashSet<String>();
697         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
698         {
699             if ( "duplication".equals( parser.getName() ) )
700             {
701                 java.util.List<Duplication> duplications = cpdErrorDetail.getDuplications();
702                 if ( duplications == null )
703                 {
704                     duplications = new java.util.ArrayList<Duplication>();
705                 }
706                 duplications.add( parseDuplication( parser, strict ) );
707                 cpdErrorDetail.setDuplications( duplications );
708             }
709             else
710             {
711                 checkUnknownElement( parser, strict );
712             }
713         }
714         return cpdErrorDetail;
715     } //-- CpdErrorDetail parseCpdErrorDetail( XmlPullParser, boolean )
716 
717     /**
718      * Method parseCpdFile.
719      * 
720      * @param parser a parser object.
721      * @param strict a strict object.
722      * @throws IOException IOException if any.
723      * @throws XmlPullParserException XmlPullParserException if
724      * any.
725      * @return CpdFile
726      */
727     private CpdFile parseCpdFile( XmlPullParser parser, boolean strict )
728         throws IOException, XmlPullParserException
729     {
730         String tagName = parser.getName();
731         CpdFile cpdFile = new CpdFile();
732         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
733         {
734             String name = parser.getAttributeName( i );
735             String value = parser.getAttributeValue( i );
736 
737             if ( name.indexOf( ':' ) >= 0 )
738             {
739                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
740             }
741             else if ( "line".equals( name ) )
742             {
743                 cpdFile.setLine( getIntegerValue( interpolatedTrimmed( value, "line" ), "line", parser, strict ) );
744             }
745             else if ( "path".equals( name ) )
746             {
747                 cpdFile.setPath( interpolatedTrimmed( value, "path" ) );
748             }
749             else
750             {
751                 checkUnknownAttribute( parser, name, tagName, strict );
752             }
753         }
754         java.util.Set<String> parsed = new java.util.HashSet<String>();
755         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
756         {
757             checkUnknownElement( parser, strict );
758         }
759         return cpdFile;
760     } //-- CpdFile parseCpdFile( XmlPullParser, boolean )
761 
762     /**
763      * Method parseDuplication.
764      * 
765      * @param parser a parser object.
766      * @param strict a strict object.
767      * @throws IOException IOException if any.
768      * @throws XmlPullParserException XmlPullParserException if
769      * any.
770      * @return Duplication
771      */
772     private Duplication parseDuplication( XmlPullParser parser, boolean strict )
773         throws IOException, XmlPullParserException
774     {
775         String tagName = parser.getName();
776         Duplication duplication = new Duplication();
777         for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
778         {
779             String name = parser.getAttributeName( i );
780             String value = parser.getAttributeValue( i );
781 
782             if ( name.indexOf( ':' ) >= 0 )
783             {
784                 // just ignore attributes with non-default namespace (for example: xmlns:xsi)
785             }
786             else if ( "lines".equals( name ) )
787             {
788                 duplication.setLines( getIntegerValue( interpolatedTrimmed( value, "lines" ), "lines", parser, strict ) );
789             }
790             else if ( "tokens".equals( name ) )
791             {
792                 duplication.setTokens( getIntegerValue( interpolatedTrimmed( value, "tokens" ), "tokens", parser, strict ) );
793             }
794             else
795             {
796                 checkUnknownAttribute( parser, name, tagName, strict );
797             }
798         }
799         java.util.Set<String> parsed = new java.util.HashSet<String>();
800         while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
801         {
802             if ( "file".equals( parser.getName() ) )
803             {
804                 java.util.List<CpdFile> files = duplication.getFiles();
805                 if ( files == null )
806                 {
807                     files = new java.util.ArrayList<CpdFile>();
808                 }
809                 files.add( parseCpdFile( parser, strict ) );
810                 duplication.setFiles( files );
811             }
812             else if ( checkFieldWithDuplicate( parser, "codefragment", null, parsed ) )
813             {
814                 duplication.setCodefragment( interpolatedTrimmed( parser.nextText(), "codefragment" ) );
815             }
816             else
817             {
818                 checkUnknownElement( parser, strict );
819             }
820         }
821         return duplication;
822     } //-- Duplication parseDuplication( XmlPullParser, boolean )
823 
824     /**
825      * Sets the state of the "add default entities" flag.
826      * 
827      * @param addDefaultEntities a addDefaultEntities object.
828      */
829     public void setAddDefaultEntities( boolean addDefaultEntities )
830     {
831         this.addDefaultEntities = addDefaultEntities;
832     } //-- void setAddDefaultEntities( boolean )
833 
834     public static interface ContentTransformer
835 {
836     /**
837      * Interpolate the value read from the xpp3 document
838      * @param source The source value
839      * @param fieldName A description of the field being interpolated. The implementation may use this to
840      *                           log stuff.
841      * @return The interpolated value.
842      */
843     String transform( String source, String fieldName );
844 }
845 
846 }