1
2
3
4
5
6 package org.apache.maven.settings.io.xpp3;
7
8
9
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.settings.Activation;
17 import org.apache.maven.settings.ActivationFile;
18 import org.apache.maven.settings.ActivationOS;
19 import org.apache.maven.settings.ActivationProperty;
20 import org.apache.maven.settings.IdentifiableBase;
21 import org.apache.maven.settings.Mirror;
22 import org.apache.maven.settings.Profile;
23 import org.apache.maven.settings.Proxy;
24 import org.apache.maven.settings.Repository;
25 import org.apache.maven.settings.RepositoryBase;
26 import org.apache.maven.settings.RepositoryPolicy;
27 import org.apache.maven.settings.Server;
28 import org.apache.maven.settings.Settings;
29 import org.apache.maven.settings.TrackableBase;
30 import org.codehaus.plexus.util.xml.XmlStreamReader;
31 import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
32 import org.codehaus.plexus.util.xml.pull.MXParser;
33 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
34 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
35
36
37
38
39
40
41 @SuppressWarnings( "all" )
42 public class SettingsXpp3Reader
43 {
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 private boolean addDefaultEntities = true;
60
61
62
63
64 public final ContentTransformer contentTransformer;
65
66
67
68
69
70
71 public SettingsXpp3Reader()
72 {
73 this( new ContentTransformer()
74 {
75 public String transform( String source, String fieldName )
76 {
77 return source;
78 }
79 } );
80 }
81
82 public SettingsXpp3Reader(ContentTransformer contentTransformer)
83 {
84 this.contentTransformer = contentTransformer;
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set<String> parsed )
104 throws XmlPullParserException
105 {
106 if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
107 {
108 return false;
109 }
110 if ( !parsed.add( tagName ) )
111 {
112 throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
113 }
114 return true;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128 private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
129 throws XmlPullParserException, IOException
130 {
131
132 if ( strict )
133 {
134 throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
135 }
136 }
137
138
139
140
141
142
143
144
145
146
147 private void checkUnknownElement( XmlPullParser parser, boolean strict )
148 throws XmlPullParserException, IOException
149 {
150 if ( strict )
151 {
152 throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
153 }
154
155 for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
156 {
157 int eventType = parser.next();
158 if ( eventType == XmlPullParser.START_TAG )
159 {
160 unrecognizedTagCount++;
161 }
162 else if ( eventType == XmlPullParser.END_TAG )
163 {
164 unrecognizedTagCount--;
165 }
166 }
167 }
168
169
170
171
172
173
174 public boolean getAddDefaultEntities()
175 {
176 return addDefaultEntities;
177 }
178
179
180
181
182
183
184
185
186
187
188
189 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
190 throws XmlPullParserException
191 {
192 return getBooleanValue( s, attribute, parser, null );
193 }
194
195
196
197
198
199
200
201
202
203
204
205
206 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
207 throws XmlPullParserException
208 {
209 if ( s != null && s.length() != 0 )
210 {
211 return Boolean.valueOf( s ).booleanValue();
212 }
213 if ( defaultValue != null )
214 {
215 return Boolean.valueOf( defaultValue ).booleanValue();
216 }
217 return false;
218 }
219
220
221
222
223
224
225
226
227
228
229
230
231 private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
232 throws XmlPullParserException
233 {
234 if ( s != null )
235 {
236 try
237 {
238 return Byte.valueOf( s ).byteValue();
239 }
240 catch ( NumberFormatException nfe )
241 {
242 if ( strict )
243 {
244 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
245 }
246 }
247 }
248 return 0;
249 }
250
251
252
253
254
255
256
257
258
259
260
261 private char getCharacterValue( String s, String attribute, XmlPullParser parser )
262 throws XmlPullParserException
263 {
264 if ( s != null )
265 {
266 return s.charAt( 0 );
267 }
268 return 0;
269 }
270
271
272
273
274
275
276
277
278
279
280
281 private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
282 throws XmlPullParserException
283 {
284 return getDateValue( s, attribute, null, parser );
285 }
286
287
288
289
290
291
292
293
294
295
296
297
298 private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
299 throws XmlPullParserException
300 {
301 if ( s != null )
302 {
303 String effectiveDateFormat = dateFormat;
304 if ( dateFormat == null )
305 {
306 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
307 }
308 if ( "long".equals( effectiveDateFormat ) )
309 {
310 try
311 {
312 return new java.util.Date( Long.parseLong( s ) );
313 }
314 catch ( NumberFormatException e )
315 {
316 throw new XmlPullParserException( e.getMessage(), parser, e );
317 }
318 }
319 else
320 {
321 try
322 {
323 DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
324 return dateParser.parse( s );
325 }
326 catch ( java.text.ParseException e )
327 {
328 throw new XmlPullParserException( e.getMessage(), parser, e );
329 }
330 }
331 }
332 return null;
333 }
334
335
336
337
338
339
340
341
342
343
344
345
346 private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
347 throws XmlPullParserException
348 {
349 if ( s != null )
350 {
351 try
352 {
353 return Double.valueOf( s ).doubleValue();
354 }
355 catch ( NumberFormatException nfe )
356 {
357 if ( strict )
358 {
359 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
360 }
361 }
362 }
363 return 0;
364 }
365
366
367
368
369
370
371
372
373
374
375
376
377 private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
378 throws XmlPullParserException
379 {
380 if ( s != null )
381 {
382 try
383 {
384 return Float.valueOf( s ).floatValue();
385 }
386 catch ( NumberFormatException nfe )
387 {
388 if ( strict )
389 {
390 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
391 }
392 }
393 }
394 return 0;
395 }
396
397
398
399
400
401
402
403
404
405
406
407
408 private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
409 throws XmlPullParserException
410 {
411 if ( s != null )
412 {
413 try
414 {
415 return Integer.valueOf( s ).intValue();
416 }
417 catch ( NumberFormatException nfe )
418 {
419 if ( strict )
420 {
421 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
422 }
423 }
424 }
425 return 0;
426 }
427
428
429
430
431
432
433
434
435
436
437
438
439 private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
440 throws XmlPullParserException
441 {
442 if ( s != null )
443 {
444 try
445 {
446 return Long.valueOf( s ).longValue();
447 }
448 catch ( NumberFormatException nfe )
449 {
450 if ( strict )
451 {
452 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
453 }
454 }
455 }
456 return 0;
457 }
458
459
460
461
462
463
464
465
466
467
468
469
470 private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
471 throws XmlPullParserException
472 {
473 if ( s == null )
474 {
475 if ( strict )
476 {
477 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
478 }
479 }
480 return s;
481 }
482
483
484
485
486
487
488
489
490
491
492
493
494 private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
495 throws XmlPullParserException
496 {
497 if ( s != null )
498 {
499 try
500 {
501 return Short.valueOf( s ).shortValue();
502 }
503 catch ( NumberFormatException nfe )
504 {
505 if ( strict )
506 {
507 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
508 }
509 }
510 }
511 return 0;
512 }
513
514
515
516
517
518
519
520 private String getTrimmedValue( String s )
521 {
522 if ( s != null )
523 {
524 s = s.trim();
525 }
526 return s;
527 }
528
529
530
531
532
533
534
535
536 private String interpolatedTrimmed( String value, String context )
537 {
538 return getTrimmedValue( contentTransformer.transform( value, context ) );
539 }
540
541
542
543
544
545
546
547
548
549
550 private int nextTag( XmlPullParser parser )
551 throws IOException, XmlPullParserException
552 {
553 int eventType = parser.next();
554 if ( eventType == XmlPullParser.TEXT )
555 {
556 eventType = parser.next();
557 }
558 if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
559 {
560 throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
561 }
562 return eventType;
563 }
564
565
566
567
568
569
570
571
572
573
574
575 public Settings read( XmlPullParser parser, boolean strict )
576 throws IOException, XmlPullParserException
577 {
578 Settings settings = null;
579 int eventType = parser.getEventType();
580 boolean parsed = false;
581 while ( eventType != XmlPullParser.END_DOCUMENT )
582 {
583 if ( eventType == XmlPullParser.START_TAG )
584 {
585 if ( strict && ! "settings".equals( parser.getName() ) )
586 {
587 throw new XmlPullParserException( "Expected root element 'settings' but found '" + parser.getName() + "'", parser, null );
588 }
589 else if ( parsed )
590 {
591
592 throw new XmlPullParserException( "Duplicated tag: 'settings'", parser, null );
593 }
594 settings = parseSettings( parser, strict );
595 settings.setModelEncoding( parser.getInputEncoding() );
596 parsed = true;
597 }
598 eventType = parser.next();
599 }
600 if ( parsed )
601 {
602 return settings;
603 }
604 throw new XmlPullParserException( "Expected root element 'settings' but found no element at all: invalid XML document", parser, null );
605 }
606
607
608
609
610
611
612
613
614
615
616
617 public Settings read( Reader reader, boolean strict )
618 throws IOException, XmlPullParserException
619 {
620 XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
621
622 parser.setInput( reader );
623
624
625 return read( parser, strict );
626 }
627
628
629
630
631
632
633
634
635
636
637 public Settings read( Reader reader )
638 throws IOException, XmlPullParserException
639 {
640 return read( reader, true );
641 }
642
643
644
645
646
647
648
649
650
651
652
653 public Settings read( InputStream in, boolean strict )
654 throws IOException, XmlPullParserException
655 {
656 return read( new XmlStreamReader( in ), strict );
657 }
658
659
660
661
662
663
664
665
666
667
668 public Settings read( InputStream in )
669 throws IOException, XmlPullParserException
670 {
671 return read( new XmlStreamReader( in ) );
672 }
673
674
675
676
677
678
679
680
681
682
683
684 private Activation parseActivation( XmlPullParser parser, boolean strict )
685 throws IOException, XmlPullParserException
686 {
687 String tagName = parser.getName();
688 Activation activation = new Activation();
689 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
690 {
691 String name = parser.getAttributeName( i );
692 String value = parser.getAttributeValue( i );
693
694 if ( name.indexOf( ':' ) >= 0 )
695 {
696
697 }
698 else
699 {
700 checkUnknownAttribute( parser, name, tagName, strict );
701 }
702 }
703 java.util.Set<String> parsed = new java.util.HashSet<String>();
704 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
705 {
706 if ( checkFieldWithDuplicate( parser, "activeByDefault", null, parsed ) )
707 {
708 activation.setActiveByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "activeByDefault" ), "activeByDefault", parser, "false" ) );
709 }
710 else if ( checkFieldWithDuplicate( parser, "jdk", null, parsed ) )
711 {
712 activation.setJdk( interpolatedTrimmed( parser.nextText(), "jdk" ) );
713 }
714 else if ( checkFieldWithDuplicate( parser, "os", null, parsed ) )
715 {
716 activation.setOs( parseActivationOS( parser, strict ) );
717 }
718 else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) )
719 {
720 activation.setProperty( parseActivationProperty( parser, strict ) );
721 }
722 else if ( checkFieldWithDuplicate( parser, "file", null, parsed ) )
723 {
724 activation.setFile( parseActivationFile( parser, strict ) );
725 }
726 else
727 {
728 checkUnknownElement( parser, strict );
729 }
730 }
731 return activation;
732 }
733
734
735
736
737
738
739
740
741
742
743
744 private ActivationFile parseActivationFile( XmlPullParser parser, boolean strict )
745 throws IOException, XmlPullParserException
746 {
747 String tagName = parser.getName();
748 ActivationFile activationFile = new ActivationFile();
749 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
750 {
751 String name = parser.getAttributeName( i );
752 String value = parser.getAttributeValue( i );
753
754 if ( name.indexOf( ':' ) >= 0 )
755 {
756
757 }
758 else
759 {
760 checkUnknownAttribute( parser, name, tagName, strict );
761 }
762 }
763 java.util.Set<String> parsed = new java.util.HashSet<String>();
764 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
765 {
766 if ( checkFieldWithDuplicate( parser, "missing", null, parsed ) )
767 {
768 activationFile.setMissing( interpolatedTrimmed( parser.nextText(), "missing" ) );
769 }
770 else if ( checkFieldWithDuplicate( parser, "exists", null, parsed ) )
771 {
772 activationFile.setExists( interpolatedTrimmed( parser.nextText(), "exists" ) );
773 }
774 else
775 {
776 checkUnknownElement( parser, strict );
777 }
778 }
779 return activationFile;
780 }
781
782
783
784
785
786
787
788
789
790
791
792 private ActivationOS parseActivationOS( XmlPullParser parser, boolean strict )
793 throws IOException, XmlPullParserException
794 {
795 String tagName = parser.getName();
796 ActivationOS activationOS = new ActivationOS();
797 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
798 {
799 String name = parser.getAttributeName( i );
800 String value = parser.getAttributeValue( i );
801
802 if ( name.indexOf( ':' ) >= 0 )
803 {
804
805 }
806 else
807 {
808 checkUnknownAttribute( parser, name, tagName, strict );
809 }
810 }
811 java.util.Set<String> parsed = new java.util.HashSet<String>();
812 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
813 {
814 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
815 {
816 activationOS.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
817 }
818 else if ( checkFieldWithDuplicate( parser, "family", null, parsed ) )
819 {
820 activationOS.setFamily( interpolatedTrimmed( parser.nextText(), "family" ) );
821 }
822 else if ( checkFieldWithDuplicate( parser, "arch", null, parsed ) )
823 {
824 activationOS.setArch( interpolatedTrimmed( parser.nextText(), "arch" ) );
825 }
826 else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
827 {
828 activationOS.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) );
829 }
830 else
831 {
832 checkUnknownElement( parser, strict );
833 }
834 }
835 return activationOS;
836 }
837
838
839
840
841
842
843
844
845
846
847
848 private ActivationProperty parseActivationProperty( XmlPullParser parser, boolean strict )
849 throws IOException, XmlPullParserException
850 {
851 String tagName = parser.getName();
852 ActivationProperty activationProperty = new ActivationProperty();
853 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
854 {
855 String name = parser.getAttributeName( i );
856 String value = parser.getAttributeValue( i );
857
858 if ( name.indexOf( ':' ) >= 0 )
859 {
860
861 }
862 else
863 {
864 checkUnknownAttribute( parser, name, tagName, strict );
865 }
866 }
867 java.util.Set<String> parsed = new java.util.HashSet<String>();
868 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
869 {
870 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
871 {
872 activationProperty.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
873 }
874 else if ( checkFieldWithDuplicate( parser, "value", null, parsed ) )
875 {
876 activationProperty.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
877 }
878 else
879 {
880 checkUnknownElement( parser, strict );
881 }
882 }
883 return activationProperty;
884 }
885
886
887
888
889
890
891
892
893
894
895
896 private IdentifiableBase parseIdentifiableBase( XmlPullParser parser, boolean strict )
897 throws IOException, XmlPullParserException
898 {
899 String tagName = parser.getName();
900 IdentifiableBase identifiableBase = new IdentifiableBase();
901 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
902 {
903 String name = parser.getAttributeName( i );
904 String value = parser.getAttributeValue( i );
905
906 if ( name.indexOf( ':' ) >= 0 )
907 {
908
909 }
910 else
911 {
912 checkUnknownAttribute( parser, name, tagName, strict );
913 }
914 }
915 java.util.Set<String> parsed = new java.util.HashSet<String>();
916 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
917 {
918 if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
919 {
920 identifiableBase.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
921 }
922 else
923 {
924 checkUnknownElement( parser, strict );
925 }
926 }
927 return identifiableBase;
928 }
929
930
931
932
933
934
935
936
937
938
939
940 private Mirror parseMirror( XmlPullParser parser, boolean strict )
941 throws IOException, XmlPullParserException
942 {
943 String tagName = parser.getName();
944 Mirror mirror = new Mirror();
945 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
946 {
947 String name = parser.getAttributeName( i );
948 String value = parser.getAttributeValue( i );
949
950 if ( name.indexOf( ':' ) >= 0 )
951 {
952
953 }
954 else
955 {
956 checkUnknownAttribute( parser, name, tagName, strict );
957 }
958 }
959 java.util.Set<String> parsed = new java.util.HashSet<String>();
960 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
961 {
962 if ( checkFieldWithDuplicate( parser, "mirrorOf", null, parsed ) )
963 {
964 mirror.setMirrorOf( interpolatedTrimmed( parser.nextText(), "mirrorOf" ) );
965 }
966 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
967 {
968 mirror.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
969 }
970 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
971 {
972 mirror.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
973 }
974 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
975 {
976 mirror.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
977 }
978 else if ( checkFieldWithDuplicate( parser, "mirrorOfLayouts", null, parsed ) )
979 {
980 mirror.setMirrorOfLayouts( interpolatedTrimmed( parser.nextText(), "mirrorOfLayouts" ) );
981 }
982 else if ( checkFieldWithDuplicate( parser, "blocked", null, parsed ) )
983 {
984 mirror.setBlocked( getBooleanValue( interpolatedTrimmed( parser.nextText(), "blocked" ), "blocked", parser, "false" ) );
985 }
986 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
987 {
988 mirror.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
989 }
990 else
991 {
992 checkUnknownElement( parser, strict );
993 }
994 }
995 return mirror;
996 }
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008 private Profile parseProfile( XmlPullParser parser, boolean strict )
1009 throws IOException, XmlPullParserException
1010 {
1011 String tagName = parser.getName();
1012 Profile profile = new Profile();
1013 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1014 {
1015 String name = parser.getAttributeName( i );
1016 String value = parser.getAttributeValue( i );
1017
1018 if ( name.indexOf( ':' ) >= 0 )
1019 {
1020
1021 }
1022 else
1023 {
1024 checkUnknownAttribute( parser, name, tagName, strict );
1025 }
1026 }
1027 java.util.Set<String> parsed = new java.util.HashSet<String>();
1028 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1029 {
1030 if ( checkFieldWithDuplicate( parser, "activation", null, parsed ) )
1031 {
1032 profile.setActivation( parseActivation( parser, strict ) );
1033 }
1034 else if ( checkFieldWithDuplicate( parser, "properties", null, parsed ) )
1035 {
1036 while ( parser.nextTag() == XmlPullParser.START_TAG )
1037 {
1038 String key = parser.getName();
1039 String value = parser.nextText().trim();
1040 profile.addProperty( key, value );
1041 }
1042 }
1043 else if ( checkFieldWithDuplicate( parser, "repositories", null, parsed ) )
1044 {
1045 java.util.List<Repository> repositories = new java.util.ArrayList<Repository>();
1046 while ( parser.nextTag() == XmlPullParser.START_TAG )
1047 {
1048 if ( "repository".equals( parser.getName() ) )
1049 {
1050 repositories.add( parseRepository( parser, strict ) );
1051 }
1052 else
1053 {
1054 checkUnknownElement( parser, strict );
1055 }
1056 }
1057 profile.setRepositories( repositories );
1058 }
1059 else if ( checkFieldWithDuplicate( parser, "pluginRepositories", null, parsed ) )
1060 {
1061 java.util.List<Repository> pluginRepositories = new java.util.ArrayList<Repository>();
1062 while ( parser.nextTag() == XmlPullParser.START_TAG )
1063 {
1064 if ( "pluginRepository".equals( parser.getName() ) )
1065 {
1066 pluginRepositories.add( parseRepository( parser, strict ) );
1067 }
1068 else
1069 {
1070 checkUnknownElement( parser, strict );
1071 }
1072 }
1073 profile.setPluginRepositories( pluginRepositories );
1074 }
1075 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1076 {
1077 profile.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1078 }
1079 else
1080 {
1081 checkUnknownElement( parser, strict );
1082 }
1083 }
1084 return profile;
1085 }
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097 private Proxy parseProxy( XmlPullParser parser, boolean strict )
1098 throws IOException, XmlPullParserException
1099 {
1100 String tagName = parser.getName();
1101 Proxy proxy = new Proxy();
1102 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1103 {
1104 String name = parser.getAttributeName( i );
1105 String value = parser.getAttributeValue( i );
1106
1107 if ( name.indexOf( ':' ) >= 0 )
1108 {
1109
1110 }
1111 else
1112 {
1113 checkUnknownAttribute( parser, name, tagName, strict );
1114 }
1115 }
1116 java.util.Set<String> parsed = new java.util.HashSet<String>();
1117 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1118 {
1119 if ( checkFieldWithDuplicate( parser, "active", null, parsed ) )
1120 {
1121 proxy.setActive( getBooleanValue( interpolatedTrimmed( parser.nextText(), "active" ), "active", parser, "true" ) );
1122 }
1123 else if ( checkFieldWithDuplicate( parser, "protocol", null, parsed ) )
1124 {
1125 proxy.setProtocol( interpolatedTrimmed( parser.nextText(), "protocol" ) );
1126 }
1127 else if ( checkFieldWithDuplicate( parser, "username", null, parsed ) )
1128 {
1129 proxy.setUsername( interpolatedTrimmed( parser.nextText(), "username" ) );
1130 }
1131 else if ( checkFieldWithDuplicate( parser, "password", null, parsed ) )
1132 {
1133 proxy.setPassword( interpolatedTrimmed( parser.nextText(), "password" ) );
1134 }
1135 else if ( checkFieldWithDuplicate( parser, "port", null, parsed ) )
1136 {
1137 proxy.setPort( getIntegerValue( interpolatedTrimmed( parser.nextText(), "port" ), "port", parser, strict ) );
1138 }
1139 else if ( checkFieldWithDuplicate( parser, "host", null, parsed ) )
1140 {
1141 proxy.setHost( interpolatedTrimmed( parser.nextText(), "host" ) );
1142 }
1143 else if ( checkFieldWithDuplicate( parser, "nonProxyHosts", null, parsed ) )
1144 {
1145 proxy.setNonProxyHosts( interpolatedTrimmed( parser.nextText(), "nonProxyHosts" ) );
1146 }
1147 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1148 {
1149 proxy.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1150 }
1151 else
1152 {
1153 checkUnknownElement( parser, strict );
1154 }
1155 }
1156 return proxy;
1157 }
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169 private Repository parseRepository( XmlPullParser parser, boolean strict )
1170 throws IOException, XmlPullParserException
1171 {
1172 String tagName = parser.getName();
1173 Repository repository = new Repository();
1174 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1175 {
1176 String name = parser.getAttributeName( i );
1177 String value = parser.getAttributeValue( i );
1178
1179 if ( name.indexOf( ':' ) >= 0 )
1180 {
1181
1182 }
1183 else
1184 {
1185 checkUnknownAttribute( parser, name, tagName, strict );
1186 }
1187 }
1188 java.util.Set<String> parsed = new java.util.HashSet<String>();
1189 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1190 {
1191 if ( checkFieldWithDuplicate( parser, "releases", null, parsed ) )
1192 {
1193 repository.setReleases( parseRepositoryPolicy( parser, strict ) );
1194 }
1195 else if ( checkFieldWithDuplicate( parser, "snapshots", null, parsed ) )
1196 {
1197 repository.setSnapshots( parseRepositoryPolicy( parser, strict ) );
1198 }
1199 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1200 {
1201 repository.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1202 }
1203 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1204 {
1205 repository.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1206 }
1207 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1208 {
1209 repository.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1210 }
1211 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1212 {
1213 repository.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1214 }
1215 else
1216 {
1217 checkUnknownElement( parser, strict );
1218 }
1219 }
1220 return repository;
1221 }
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233 private RepositoryBase parseRepositoryBase( XmlPullParser parser, boolean strict )
1234 throws IOException, XmlPullParserException
1235 {
1236 String tagName = parser.getName();
1237 RepositoryBase repositoryBase = new RepositoryBase();
1238 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1239 {
1240 String name = parser.getAttributeName( i );
1241 String value = parser.getAttributeValue( i );
1242
1243 if ( name.indexOf( ':' ) >= 0 )
1244 {
1245
1246 }
1247 else
1248 {
1249 checkUnknownAttribute( parser, name, tagName, strict );
1250 }
1251 }
1252 java.util.Set<String> parsed = new java.util.HashSet<String>();
1253 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1254 {
1255 if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1256 {
1257 repositoryBase.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1258 }
1259 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1260 {
1261 repositoryBase.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1262 }
1263 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1264 {
1265 repositoryBase.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1266 }
1267 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1268 {
1269 repositoryBase.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1270 }
1271 else
1272 {
1273 checkUnknownElement( parser, strict );
1274 }
1275 }
1276 return repositoryBase;
1277 }
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289 private RepositoryPolicy parseRepositoryPolicy( XmlPullParser parser, boolean strict )
1290 throws IOException, XmlPullParserException
1291 {
1292 String tagName = parser.getName();
1293 RepositoryPolicy repositoryPolicy = new RepositoryPolicy();
1294 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1295 {
1296 String name = parser.getAttributeName( i );
1297 String value = parser.getAttributeValue( i );
1298
1299 if ( name.indexOf( ':' ) >= 0 )
1300 {
1301
1302 }
1303 else
1304 {
1305 checkUnknownAttribute( parser, name, tagName, strict );
1306 }
1307 }
1308 java.util.Set<String> parsed = new java.util.HashSet<String>();
1309 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1310 {
1311 if ( checkFieldWithDuplicate( parser, "enabled", null, parsed ) )
1312 {
1313 repositoryPolicy.setEnabled( getBooleanValue( interpolatedTrimmed( parser.nextText(), "enabled" ), "enabled", parser, "true" ) );
1314 }
1315 else if ( checkFieldWithDuplicate( parser, "updatePolicy", null, parsed ) )
1316 {
1317 repositoryPolicy.setUpdatePolicy( interpolatedTrimmed( parser.nextText(), "updatePolicy" ) );
1318 }
1319 else if ( checkFieldWithDuplicate( parser, "checksumPolicy", null, parsed ) )
1320 {
1321 repositoryPolicy.setChecksumPolicy( interpolatedTrimmed( parser.nextText(), "checksumPolicy" ) );
1322 }
1323 else
1324 {
1325 checkUnknownElement( parser, strict );
1326 }
1327 }
1328 return repositoryPolicy;
1329 }
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341 private Server parseServer( XmlPullParser parser, boolean strict )
1342 throws IOException, XmlPullParserException
1343 {
1344 String tagName = parser.getName();
1345 Server server = new Server();
1346 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1347 {
1348 String name = parser.getAttributeName( i );
1349 String value = parser.getAttributeValue( i );
1350
1351 if ( name.indexOf( ':' ) >= 0 )
1352 {
1353
1354 }
1355 else
1356 {
1357 checkUnknownAttribute( parser, name, tagName, strict );
1358 }
1359 }
1360 java.util.Set<String> parsed = new java.util.HashSet<String>();
1361 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1362 {
1363 if ( checkFieldWithDuplicate( parser, "username", null, parsed ) )
1364 {
1365 server.setUsername( interpolatedTrimmed( parser.nextText(), "username" ) );
1366 }
1367 else if ( checkFieldWithDuplicate( parser, "password", null, parsed ) )
1368 {
1369 server.setPassword( interpolatedTrimmed( parser.nextText(), "password" ) );
1370 }
1371 else if ( checkFieldWithDuplicate( parser, "privateKey", null, parsed ) )
1372 {
1373 server.setPrivateKey( interpolatedTrimmed( parser.nextText(), "privateKey" ) );
1374 }
1375 else if ( checkFieldWithDuplicate( parser, "passphrase", null, parsed ) )
1376 {
1377 server.setPassphrase( interpolatedTrimmed( parser.nextText(), "passphrase" ) );
1378 }
1379 else if ( checkFieldWithDuplicate( parser, "filePermissions", null, parsed ) )
1380 {
1381 server.setFilePermissions( interpolatedTrimmed( parser.nextText(), "filePermissions" ) );
1382 }
1383 else if ( checkFieldWithDuplicate( parser, "directoryPermissions", null, parsed ) )
1384 {
1385 server.setDirectoryPermissions( interpolatedTrimmed( parser.nextText(), "directoryPermissions" ) );
1386 }
1387 else if ( checkFieldWithDuplicate( parser, "configuration", null, parsed ) )
1388 {
1389 server.setConfiguration( org.codehaus.plexus.util.xml.Xpp3DomBuilder.build( parser, true ) );
1390 }
1391 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1392 {
1393 server.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1394 }
1395 else
1396 {
1397 checkUnknownElement( parser, strict );
1398 }
1399 }
1400 return server;
1401 }
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413 private Settings parseSettings( XmlPullParser parser, boolean strict )
1414 throws IOException, XmlPullParserException
1415 {
1416 String tagName = parser.getName();
1417 Settings settings = new Settings();
1418 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1419 {
1420 String name = parser.getAttributeName( i );
1421 String value = parser.getAttributeValue( i );
1422
1423 if ( name.indexOf( ':' ) >= 0 )
1424 {
1425
1426 }
1427 else if ( "xmlns".equals( name ) )
1428 {
1429
1430 }
1431 else
1432 {
1433 checkUnknownAttribute( parser, name, tagName, strict );
1434 }
1435 }
1436 java.util.Set<String> parsed = new java.util.HashSet<String>();
1437 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1438 {
1439 if ( checkFieldWithDuplicate( parser, "localRepository", null, parsed ) )
1440 {
1441 settings.setLocalRepository( interpolatedTrimmed( parser.nextText(), "localRepository" ) );
1442 }
1443 else if ( checkFieldWithDuplicate( parser, "interactiveMode", null, parsed ) )
1444 {
1445 settings.setInteractiveMode( getBooleanValue( interpolatedTrimmed( parser.nextText(), "interactiveMode" ), "interactiveMode", parser, "true" ) );
1446 }
1447 else if ( checkFieldWithDuplicate( parser, "usePluginRegistry", null, parsed ) )
1448 {
1449 settings.setUsePluginRegistry( getBooleanValue( interpolatedTrimmed( parser.nextText(), "usePluginRegistry" ), "usePluginRegistry", parser, "false" ) );
1450 }
1451 else if ( checkFieldWithDuplicate( parser, "offline", null, parsed ) )
1452 {
1453 settings.setOffline( getBooleanValue( interpolatedTrimmed( parser.nextText(), "offline" ), "offline", parser, "false" ) );
1454 }
1455 else if ( checkFieldWithDuplicate( parser, "proxies", null, parsed ) )
1456 {
1457 java.util.List<Proxy> proxies = new java.util.ArrayList<Proxy>();
1458 while ( parser.nextTag() == XmlPullParser.START_TAG )
1459 {
1460 if ( "proxy".equals( parser.getName() ) )
1461 {
1462 proxies.add( parseProxy( parser, strict ) );
1463 }
1464 else
1465 {
1466 checkUnknownElement( parser, strict );
1467 }
1468 }
1469 settings.setProxies( proxies );
1470 }
1471 else if ( checkFieldWithDuplicate( parser, "servers", null, parsed ) )
1472 {
1473 java.util.List<Server> servers = new java.util.ArrayList<Server>();
1474 while ( parser.nextTag() == XmlPullParser.START_TAG )
1475 {
1476 if ( "server".equals( parser.getName() ) )
1477 {
1478 servers.add( parseServer( parser, strict ) );
1479 }
1480 else
1481 {
1482 checkUnknownElement( parser, strict );
1483 }
1484 }
1485 settings.setServers( servers );
1486 }
1487 else if ( checkFieldWithDuplicate( parser, "mirrors", null, parsed ) )
1488 {
1489 java.util.List<Mirror> mirrors = new java.util.ArrayList<Mirror>();
1490 while ( parser.nextTag() == XmlPullParser.START_TAG )
1491 {
1492 if ( "mirror".equals( parser.getName() ) )
1493 {
1494 mirrors.add( parseMirror( parser, strict ) );
1495 }
1496 else
1497 {
1498 checkUnknownElement( parser, strict );
1499 }
1500 }
1501 settings.setMirrors( mirrors );
1502 }
1503 else if ( checkFieldWithDuplicate( parser, "profiles", null, parsed ) )
1504 {
1505 java.util.List<Profile> profiles = new java.util.ArrayList<Profile>();
1506 while ( parser.nextTag() == XmlPullParser.START_TAG )
1507 {
1508 if ( "profile".equals( parser.getName() ) )
1509 {
1510 profiles.add( parseProfile( parser, strict ) );
1511 }
1512 else
1513 {
1514 checkUnknownElement( parser, strict );
1515 }
1516 }
1517 settings.setProfiles( profiles );
1518 }
1519 else if ( checkFieldWithDuplicate( parser, "activeProfiles", null, parsed ) )
1520 {
1521 java.util.List<String> activeProfiles = new java.util.ArrayList<String>();
1522 while ( parser.nextTag() == XmlPullParser.START_TAG )
1523 {
1524 if ( "activeProfile".equals( parser.getName() ) )
1525 {
1526 activeProfiles.add( interpolatedTrimmed( parser.nextText(), "activeProfiles" ) );
1527 }
1528 else
1529 {
1530 checkUnknownElement( parser, strict );
1531 }
1532 }
1533 settings.setActiveProfiles( activeProfiles );
1534 }
1535 else if ( checkFieldWithDuplicate( parser, "pluginGroups", null, parsed ) )
1536 {
1537 java.util.List<String> pluginGroups = new java.util.ArrayList<String>();
1538 while ( parser.nextTag() == XmlPullParser.START_TAG )
1539 {
1540 if ( "pluginGroup".equals( parser.getName() ) )
1541 {
1542 pluginGroups.add( interpolatedTrimmed( parser.nextText(), "pluginGroups" ) );
1543 }
1544 else
1545 {
1546 checkUnknownElement( parser, strict );
1547 }
1548 }
1549 settings.setPluginGroups( pluginGroups );
1550 }
1551 else
1552 {
1553 checkUnknownElement( parser, strict );
1554 }
1555 }
1556 return settings;
1557 }
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569 private TrackableBase parseTrackableBase( XmlPullParser parser, boolean strict )
1570 throws IOException, XmlPullParserException
1571 {
1572 String tagName = parser.getName();
1573 TrackableBase trackableBase = new TrackableBase();
1574 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1575 {
1576 String name = parser.getAttributeName( i );
1577 String value = parser.getAttributeValue( i );
1578
1579 if ( name.indexOf( ':' ) >= 0 )
1580 {
1581
1582 }
1583 else
1584 {
1585 checkUnknownAttribute( parser, name, tagName, strict );
1586 }
1587 }
1588 java.util.Set<String> parsed = new java.util.HashSet<String>();
1589 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1590 {
1591 checkUnknownElement( parser, strict );
1592 }
1593 return trackableBase;
1594 }
1595
1596
1597
1598
1599
1600
1601 public void setAddDefaultEntities( boolean addDefaultEntities )
1602 {
1603 this.addDefaultEntities = addDefaultEntities;
1604 }
1605
1606 public static interface ContentTransformer
1607 {
1608
1609
1610
1611
1612
1613
1614
1615 String transform( String source, String fieldName );
1616 }
1617
1618 }