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