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