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 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 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( Reader reader, boolean strict )
576 throws IOException, XmlPullParserException
577 {
578 XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
579
580 parser.setInput( reader );
581
582
583 return read( parser, strict );
584 }
585
586
587
588
589
590
591
592
593
594
595 public Settings read( Reader reader )
596 throws IOException, XmlPullParserException
597 {
598 return read( reader, true );
599 }
600
601
602
603
604
605
606
607
608
609
610
611 public Settings read( InputStream in, boolean strict )
612 throws IOException, XmlPullParserException
613 {
614 return read( ReaderFactory.newXmlReader( in ), strict );
615 }
616
617
618
619
620
621
622
623
624
625
626 public Settings read( InputStream in )
627 throws IOException, XmlPullParserException
628 {
629 return read( ReaderFactory.newXmlReader( in ) );
630 }
631
632
633
634
635
636
637
638
639
640
641
642 private Activation parseActivation( XmlPullParser parser, boolean strict )
643 throws IOException, XmlPullParserException
644 {
645 String tagName = parser.getName();
646 Activation activation = new Activation();
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, "activeByDefault", null, parsed ) )
665 {
666 activation.setActiveByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "activeByDefault" ), "activeByDefault", parser, "false" ) );
667 }
668 else if ( checkFieldWithDuplicate( parser, "jdk", null, parsed ) )
669 {
670 activation.setJdk( interpolatedTrimmed( parser.nextText(), "jdk" ) );
671 }
672 else if ( checkFieldWithDuplicate( parser, "os", null, parsed ) )
673 {
674 activation.setOs( parseActivationOS( parser, strict ) );
675 }
676 else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) )
677 {
678 activation.setProperty( parseActivationProperty( parser, strict ) );
679 }
680 else if ( checkFieldWithDuplicate( parser, "file", null, parsed ) )
681 {
682 activation.setFile( parseActivationFile( parser, strict ) );
683 }
684 else
685 {
686 checkUnknownElement( parser, strict );
687 }
688 }
689 return activation;
690 }
691
692
693
694
695
696
697
698
699
700
701
702 private ActivationFile parseActivationFile( XmlPullParser parser, boolean strict )
703 throws IOException, XmlPullParserException
704 {
705 String tagName = parser.getName();
706 ActivationFile activationFile = new ActivationFile();
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 parsed = new java.util.HashSet();
722 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
723 {
724 if ( checkFieldWithDuplicate( parser, "missing", null, parsed ) )
725 {
726 activationFile.setMissing( interpolatedTrimmed( parser.nextText(), "missing" ) );
727 }
728 else if ( checkFieldWithDuplicate( parser, "exists", null, parsed ) )
729 {
730 activationFile.setExists( interpolatedTrimmed( parser.nextText(), "exists" ) );
731 }
732 else
733 {
734 checkUnknownElement( parser, strict );
735 }
736 }
737 return activationFile;
738 }
739
740
741
742
743
744
745
746
747
748
749
750 private ActivationOS parseActivationOS( XmlPullParser parser, boolean strict )
751 throws IOException, XmlPullParserException
752 {
753 String tagName = parser.getName();
754 ActivationOS activationOS = new ActivationOS();
755 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
756 {
757 String name = parser.getAttributeName( i );
758 String value = parser.getAttributeValue( i );
759
760 if ( name.indexOf( ':' ) >= 0 )
761 {
762
763 }
764 else
765 {
766 checkUnknownAttribute( parser, name, tagName, strict );
767 }
768 }
769 java.util.Set parsed = new java.util.HashSet();
770 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
771 {
772 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
773 {
774 activationOS.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
775 }
776 else if ( checkFieldWithDuplicate( parser, "family", null, parsed ) )
777 {
778 activationOS.setFamily( interpolatedTrimmed( parser.nextText(), "family" ) );
779 }
780 else if ( checkFieldWithDuplicate( parser, "arch", null, parsed ) )
781 {
782 activationOS.setArch( interpolatedTrimmed( parser.nextText(), "arch" ) );
783 }
784 else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
785 {
786 activationOS.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) );
787 }
788 else
789 {
790 checkUnknownElement( parser, strict );
791 }
792 }
793 return activationOS;
794 }
795
796
797
798
799
800
801
802
803
804
805
806 private ActivationProperty parseActivationProperty( XmlPullParser parser, boolean strict )
807 throws IOException, XmlPullParserException
808 {
809 String tagName = parser.getName();
810 ActivationProperty activationProperty = new ActivationProperty();
811 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
812 {
813 String name = parser.getAttributeName( i );
814 String value = parser.getAttributeValue( i );
815
816 if ( name.indexOf( ':' ) >= 0 )
817 {
818
819 }
820 else
821 {
822 checkUnknownAttribute( parser, name, tagName, strict );
823 }
824 }
825 java.util.Set parsed = new java.util.HashSet();
826 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
827 {
828 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
829 {
830 activationProperty.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
831 }
832 else if ( checkFieldWithDuplicate( parser, "value", null, parsed ) )
833 {
834 activationProperty.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
835 }
836 else
837 {
838 checkUnknownElement( parser, strict );
839 }
840 }
841 return activationProperty;
842 }
843
844
845
846
847
848
849
850
851
852
853
854 private IdentifiableBase parseIdentifiableBase( XmlPullParser parser, boolean strict )
855 throws IOException, XmlPullParserException
856 {
857 String tagName = parser.getName();
858 IdentifiableBase identifiableBase = new IdentifiableBase();
859 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
860 {
861 String name = parser.getAttributeName( i );
862 String value = parser.getAttributeValue( i );
863
864 if ( name.indexOf( ':' ) >= 0 )
865 {
866
867 }
868 else
869 {
870 checkUnknownAttribute( parser, name, tagName, strict );
871 }
872 }
873 java.util.Set parsed = new java.util.HashSet();
874 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
875 {
876 if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
877 {
878 identifiableBase.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
879 }
880 else
881 {
882 checkUnknownElement( parser, strict );
883 }
884 }
885 return identifiableBase;
886 }
887
888
889
890
891
892
893
894
895
896
897
898 private Mirror parseMirror( XmlPullParser parser, boolean strict )
899 throws IOException, XmlPullParserException
900 {
901 String tagName = parser.getName();
902 Mirror mirror = new Mirror();
903 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
904 {
905 String name = parser.getAttributeName( i );
906 String value = parser.getAttributeValue( i );
907
908 if ( name.indexOf( ':' ) >= 0 )
909 {
910
911 }
912 else
913 {
914 checkUnknownAttribute( parser, name, tagName, strict );
915 }
916 }
917 java.util.Set parsed = new java.util.HashSet();
918 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
919 {
920 if ( checkFieldWithDuplicate( parser, "mirrorOf", null, parsed ) )
921 {
922 mirror.setMirrorOf( interpolatedTrimmed( parser.nextText(), "mirrorOf" ) );
923 }
924 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
925 {
926 mirror.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
927 }
928 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
929 {
930 mirror.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
931 }
932 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
933 {
934 mirror.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
935 }
936 else if ( checkFieldWithDuplicate( parser, "mirrorOfLayouts", null, parsed ) )
937 {
938 mirror.setMirrorOfLayouts( interpolatedTrimmed( parser.nextText(), "mirrorOfLayouts" ) );
939 }
940 else if ( checkFieldWithDuplicate( parser, "blocked", null, parsed ) )
941 {
942 mirror.setBlocked( getBooleanValue( interpolatedTrimmed( parser.nextText(), "blocked" ), "blocked", parser, "false" ) );
943 }
944 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
945 {
946 mirror.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
947 }
948 else
949 {
950 checkUnknownElement( parser, strict );
951 }
952 }
953 return mirror;
954 }
955
956
957
958
959
960
961
962
963
964
965
966 private Profile parseProfile( XmlPullParser parser, boolean strict )
967 throws IOException, XmlPullParserException
968 {
969 String tagName = parser.getName();
970 Profile profile = new Profile();
971 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
972 {
973 String name = parser.getAttributeName( i );
974 String value = parser.getAttributeValue( i );
975
976 if ( name.indexOf( ':' ) >= 0 )
977 {
978
979 }
980 else
981 {
982 checkUnknownAttribute( parser, name, tagName, strict );
983 }
984 }
985 java.util.Set parsed = new java.util.HashSet();
986 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
987 {
988 if ( checkFieldWithDuplicate( parser, "activation", null, parsed ) )
989 {
990 profile.setActivation( parseActivation( parser, strict ) );
991 }
992 else if ( checkFieldWithDuplicate( parser, "properties", null, parsed ) )
993 {
994 while ( parser.nextTag() == XmlPullParser.START_TAG )
995 {
996 String key = parser.getName();
997 String value = parser.nextText().trim();
998 profile.addProperty( key, value );
999 }
1000 }
1001 else if ( checkFieldWithDuplicate( parser, "repositories", null, parsed ) )
1002 {
1003 java.util.List<Repository> repositories = new java.util.ArrayList<Repository>();
1004 profile.setRepositories( repositories );
1005 while ( parser.nextTag() == XmlPullParser.START_TAG )
1006 {
1007 if ( "repository".equals( parser.getName() ) )
1008 {
1009 repositories.add( parseRepository( parser, strict ) );
1010 }
1011 else
1012 {
1013 checkUnknownElement( parser, strict );
1014 }
1015 }
1016 }
1017 else if ( checkFieldWithDuplicate( parser, "pluginRepositories", null, parsed ) )
1018 {
1019 java.util.List<Repository> pluginRepositories = new java.util.ArrayList<Repository>();
1020 profile.setPluginRepositories( pluginRepositories );
1021 while ( parser.nextTag() == XmlPullParser.START_TAG )
1022 {
1023 if ( "pluginRepository".equals( parser.getName() ) )
1024 {
1025 pluginRepositories.add( parseRepository( parser, strict ) );
1026 }
1027 else
1028 {
1029 checkUnknownElement( parser, strict );
1030 }
1031 }
1032 }
1033 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1034 {
1035 profile.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1036 }
1037 else
1038 {
1039 checkUnknownElement( parser, strict );
1040 }
1041 }
1042 return profile;
1043 }
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055 private Proxy parseProxy( XmlPullParser parser, boolean strict )
1056 throws IOException, XmlPullParserException
1057 {
1058 String tagName = parser.getName();
1059 Proxy proxy = new Proxy();
1060 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1061 {
1062 String name = parser.getAttributeName( i );
1063 String value = parser.getAttributeValue( i );
1064
1065 if ( name.indexOf( ':' ) >= 0 )
1066 {
1067
1068 }
1069 else
1070 {
1071 checkUnknownAttribute( parser, name, tagName, strict );
1072 }
1073 }
1074 java.util.Set parsed = new java.util.HashSet();
1075 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1076 {
1077 if ( checkFieldWithDuplicate( parser, "active", null, parsed ) )
1078 {
1079 proxy.setActive( getBooleanValue( interpolatedTrimmed( parser.nextText(), "active" ), "active", parser, "true" ) );
1080 }
1081 else if ( checkFieldWithDuplicate( parser, "protocol", null, parsed ) )
1082 {
1083 proxy.setProtocol( interpolatedTrimmed( parser.nextText(), "protocol" ) );
1084 }
1085 else if ( checkFieldWithDuplicate( parser, "username", null, parsed ) )
1086 {
1087 proxy.setUsername( interpolatedTrimmed( parser.nextText(), "username" ) );
1088 }
1089 else if ( checkFieldWithDuplicate( parser, "password", null, parsed ) )
1090 {
1091 proxy.setPassword( interpolatedTrimmed( parser.nextText(), "password" ) );
1092 }
1093 else if ( checkFieldWithDuplicate( parser, "port", null, parsed ) )
1094 {
1095 proxy.setPort( getIntegerValue( interpolatedTrimmed( parser.nextText(), "port" ), "port", parser, strict ) );
1096 }
1097 else if ( checkFieldWithDuplicate( parser, "host", null, parsed ) )
1098 {
1099 proxy.setHost( interpolatedTrimmed( parser.nextText(), "host" ) );
1100 }
1101 else if ( checkFieldWithDuplicate( parser, "nonProxyHosts", null, parsed ) )
1102 {
1103 proxy.setNonProxyHosts( interpolatedTrimmed( parser.nextText(), "nonProxyHosts" ) );
1104 }
1105 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1106 {
1107 proxy.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1108 }
1109 else
1110 {
1111 checkUnknownElement( parser, strict );
1112 }
1113 }
1114 return proxy;
1115 }
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127 private Repository parseRepository( XmlPullParser parser, boolean strict )
1128 throws IOException, XmlPullParserException
1129 {
1130 String tagName = parser.getName();
1131 Repository repository = new Repository();
1132 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1133 {
1134 String name = parser.getAttributeName( i );
1135 String value = parser.getAttributeValue( i );
1136
1137 if ( name.indexOf( ':' ) >= 0 )
1138 {
1139
1140 }
1141 else
1142 {
1143 checkUnknownAttribute( parser, name, tagName, strict );
1144 }
1145 }
1146 java.util.Set parsed = new java.util.HashSet();
1147 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1148 {
1149 if ( checkFieldWithDuplicate( parser, "releases", null, parsed ) )
1150 {
1151 repository.setReleases( parseRepositoryPolicy( parser, strict ) );
1152 }
1153 else if ( checkFieldWithDuplicate( parser, "snapshots", null, parsed ) )
1154 {
1155 repository.setSnapshots( parseRepositoryPolicy( parser, strict ) );
1156 }
1157 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1158 {
1159 repository.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1160 }
1161 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1162 {
1163 repository.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1164 }
1165 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1166 {
1167 repository.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1168 }
1169 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1170 {
1171 repository.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1172 }
1173 else
1174 {
1175 checkUnknownElement( parser, strict );
1176 }
1177 }
1178 return repository;
1179 }
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191 private RepositoryBase parseRepositoryBase( XmlPullParser parser, boolean strict )
1192 throws IOException, XmlPullParserException
1193 {
1194 String tagName = parser.getName();
1195 RepositoryBase repositoryBase = new RepositoryBase();
1196 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1197 {
1198 String name = parser.getAttributeName( i );
1199 String value = parser.getAttributeValue( i );
1200
1201 if ( name.indexOf( ':' ) >= 0 )
1202 {
1203
1204 }
1205 else
1206 {
1207 checkUnknownAttribute( parser, name, tagName, strict );
1208 }
1209 }
1210 java.util.Set parsed = new java.util.HashSet();
1211 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1212 {
1213 if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1214 {
1215 repositoryBase.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1216 }
1217 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1218 {
1219 repositoryBase.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1220 }
1221 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1222 {
1223 repositoryBase.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1224 }
1225 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1226 {
1227 repositoryBase.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1228 }
1229 else
1230 {
1231 checkUnknownElement( parser, strict );
1232 }
1233 }
1234 return repositoryBase;
1235 }
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247 private RepositoryPolicy parseRepositoryPolicy( XmlPullParser parser, boolean strict )
1248 throws IOException, XmlPullParserException
1249 {
1250 String tagName = parser.getName();
1251 RepositoryPolicy repositoryPolicy = new RepositoryPolicy();
1252 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1253 {
1254 String name = parser.getAttributeName( i );
1255 String value = parser.getAttributeValue( i );
1256
1257 if ( name.indexOf( ':' ) >= 0 )
1258 {
1259
1260 }
1261 else
1262 {
1263 checkUnknownAttribute( parser, name, tagName, strict );
1264 }
1265 }
1266 java.util.Set parsed = new java.util.HashSet();
1267 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1268 {
1269 if ( checkFieldWithDuplicate( parser, "enabled", null, parsed ) )
1270 {
1271 repositoryPolicy.setEnabled( getBooleanValue( interpolatedTrimmed( parser.nextText(), "enabled" ), "enabled", parser, "true" ) );
1272 }
1273 else if ( checkFieldWithDuplicate( parser, "updatePolicy", null, parsed ) )
1274 {
1275 repositoryPolicy.setUpdatePolicy( interpolatedTrimmed( parser.nextText(), "updatePolicy" ) );
1276 }
1277 else if ( checkFieldWithDuplicate( parser, "checksumPolicy", null, parsed ) )
1278 {
1279 repositoryPolicy.setChecksumPolicy( interpolatedTrimmed( parser.nextText(), "checksumPolicy" ) );
1280 }
1281 else
1282 {
1283 checkUnknownElement( parser, strict );
1284 }
1285 }
1286 return repositoryPolicy;
1287 }
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299 private Server parseServer( XmlPullParser parser, boolean strict )
1300 throws IOException, XmlPullParserException
1301 {
1302 String tagName = parser.getName();
1303 Server server = new Server();
1304 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1305 {
1306 String name = parser.getAttributeName( i );
1307 String value = parser.getAttributeValue( i );
1308
1309 if ( name.indexOf( ':' ) >= 0 )
1310 {
1311
1312 }
1313 else
1314 {
1315 checkUnknownAttribute( parser, name, tagName, strict );
1316 }
1317 }
1318 java.util.Set parsed = new java.util.HashSet();
1319 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1320 {
1321 if ( checkFieldWithDuplicate( parser, "username", null, parsed ) )
1322 {
1323 server.setUsername( interpolatedTrimmed( parser.nextText(), "username" ) );
1324 }
1325 else if ( checkFieldWithDuplicate( parser, "password", null, parsed ) )
1326 {
1327 server.setPassword( interpolatedTrimmed( parser.nextText(), "password" ) );
1328 }
1329 else if ( checkFieldWithDuplicate( parser, "privateKey", null, parsed ) )
1330 {
1331 server.setPrivateKey( interpolatedTrimmed( parser.nextText(), "privateKey" ) );
1332 }
1333 else if ( checkFieldWithDuplicate( parser, "passphrase", null, parsed ) )
1334 {
1335 server.setPassphrase( interpolatedTrimmed( parser.nextText(), "passphrase" ) );
1336 }
1337 else if ( checkFieldWithDuplicate( parser, "filePermissions", null, parsed ) )
1338 {
1339 server.setFilePermissions( interpolatedTrimmed( parser.nextText(), "filePermissions" ) );
1340 }
1341 else if ( checkFieldWithDuplicate( parser, "directoryPermissions", null, parsed ) )
1342 {
1343 server.setDirectoryPermissions( interpolatedTrimmed( parser.nextText(), "directoryPermissions" ) );
1344 }
1345 else if ( checkFieldWithDuplicate( parser, "configuration", null, parsed ) )
1346 {
1347 server.setConfiguration( org.codehaus.plexus.util.xml.Xpp3DomBuilder.build( parser, true ) );
1348 }
1349 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1350 {
1351 server.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1352 }
1353 else
1354 {
1355 checkUnknownElement( parser, strict );
1356 }
1357 }
1358 return server;
1359 }
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371 private Settings parseSettings( XmlPullParser parser, boolean strict )
1372 throws IOException, XmlPullParserException
1373 {
1374 String tagName = parser.getName();
1375 Settings settings = new Settings();
1376 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1377 {
1378 String name = parser.getAttributeName( i );
1379 String value = parser.getAttributeValue( i );
1380
1381 if ( name.indexOf( ':' ) >= 0 )
1382 {
1383
1384 }
1385 else if ( "xmlns".equals( name ) )
1386 {
1387
1388 }
1389 else
1390 {
1391 checkUnknownAttribute( parser, name, tagName, strict );
1392 }
1393 }
1394 java.util.Set parsed = new java.util.HashSet();
1395 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1396 {
1397 if ( checkFieldWithDuplicate( parser, "localRepository", null, parsed ) )
1398 {
1399 settings.setLocalRepository( interpolatedTrimmed( parser.nextText(), "localRepository" ) );
1400 }
1401 else if ( checkFieldWithDuplicate( parser, "interactiveMode", null, parsed ) )
1402 {
1403 settings.setInteractiveMode( getBooleanValue( interpolatedTrimmed( parser.nextText(), "interactiveMode" ), "interactiveMode", parser, "true" ) );
1404 }
1405 else if ( checkFieldWithDuplicate( parser, "usePluginRegistry", null, parsed ) )
1406 {
1407 settings.setUsePluginRegistry( getBooleanValue( interpolatedTrimmed( parser.nextText(), "usePluginRegistry" ), "usePluginRegistry", parser, "false" ) );
1408 }
1409 else if ( checkFieldWithDuplicate( parser, "offline", null, parsed ) )
1410 {
1411 settings.setOffline( getBooleanValue( interpolatedTrimmed( parser.nextText(), "offline" ), "offline", parser, "false" ) );
1412 }
1413 else if ( checkFieldWithDuplicate( parser, "proxies", null, parsed ) )
1414 {
1415 java.util.List<Proxy> proxies = new java.util.ArrayList<Proxy>();
1416 settings.setProxies( proxies );
1417 while ( parser.nextTag() == XmlPullParser.START_TAG )
1418 {
1419 if ( "proxy".equals( parser.getName() ) )
1420 {
1421 proxies.add( parseProxy( parser, strict ) );
1422 }
1423 else
1424 {
1425 checkUnknownElement( parser, strict );
1426 }
1427 }
1428 }
1429 else if ( checkFieldWithDuplicate( parser, "servers", null, parsed ) )
1430 {
1431 java.util.List<Server> servers = new java.util.ArrayList<Server>();
1432 settings.setServers( servers );
1433 while ( parser.nextTag() == XmlPullParser.START_TAG )
1434 {
1435 if ( "server".equals( parser.getName() ) )
1436 {
1437 servers.add( parseServer( parser, strict ) );
1438 }
1439 else
1440 {
1441 checkUnknownElement( parser, strict );
1442 }
1443 }
1444 }
1445 else if ( checkFieldWithDuplicate( parser, "mirrors", null, parsed ) )
1446 {
1447 java.util.List<Mirror> mirrors = new java.util.ArrayList<Mirror>();
1448 settings.setMirrors( mirrors );
1449 while ( parser.nextTag() == XmlPullParser.START_TAG )
1450 {
1451 if ( "mirror".equals( parser.getName() ) )
1452 {
1453 mirrors.add( parseMirror( parser, strict ) );
1454 }
1455 else
1456 {
1457 checkUnknownElement( parser, strict );
1458 }
1459 }
1460 }
1461 else if ( checkFieldWithDuplicate( parser, "profiles", null, parsed ) )
1462 {
1463 java.util.List<Profile> profiles = new java.util.ArrayList<Profile>();
1464 settings.setProfiles( profiles );
1465 while ( parser.nextTag() == XmlPullParser.START_TAG )
1466 {
1467 if ( "profile".equals( parser.getName() ) )
1468 {
1469 profiles.add( parseProfile( parser, strict ) );
1470 }
1471 else
1472 {
1473 checkUnknownElement( parser, strict );
1474 }
1475 }
1476 }
1477 else if ( checkFieldWithDuplicate( parser, "activeProfiles", null, parsed ) )
1478 {
1479 java.util.List<String> activeProfiles = new java.util.ArrayList<String>();
1480 settings.setActiveProfiles( activeProfiles );
1481 while ( parser.nextTag() == XmlPullParser.START_TAG )
1482 {
1483 if ( "activeProfile".equals( parser.getName() ) )
1484 {
1485 activeProfiles.add( interpolatedTrimmed( parser.nextText(), "activeProfiles" ) );
1486 }
1487 else
1488 {
1489 checkUnknownElement( parser, strict );
1490 }
1491 }
1492 }
1493 else if ( checkFieldWithDuplicate( parser, "pluginGroups", null, parsed ) )
1494 {
1495 java.util.List<String> pluginGroups = new java.util.ArrayList<String>();
1496 settings.setPluginGroups( pluginGroups );
1497 while ( parser.nextTag() == XmlPullParser.START_TAG )
1498 {
1499 if ( "pluginGroup".equals( parser.getName() ) )
1500 {
1501 pluginGroups.add( interpolatedTrimmed( parser.nextText(), "pluginGroups" ) );
1502 }
1503 else
1504 {
1505 checkUnknownElement( parser, strict );
1506 }
1507 }
1508 }
1509 else
1510 {
1511 checkUnknownElement( parser, strict );
1512 }
1513 }
1514 return settings;
1515 }
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527 private TrackableBase parseTrackableBase( XmlPullParser parser, boolean strict )
1528 throws IOException, XmlPullParserException
1529 {
1530 String tagName = parser.getName();
1531 TrackableBase trackableBase = new TrackableBase();
1532 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1533 {
1534 String name = parser.getAttributeName( i );
1535 String value = parser.getAttributeValue( i );
1536
1537 if ( name.indexOf( ':' ) >= 0 )
1538 {
1539
1540 }
1541 else
1542 {
1543 checkUnknownAttribute( parser, name, tagName, strict );
1544 }
1545 }
1546 java.util.Set parsed = new java.util.HashSet();
1547 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1548 {
1549 checkUnknownElement( parser, strict );
1550 }
1551 return trackableBase;
1552 }
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564 private Settings read( XmlPullParser parser, boolean strict )
1565 throws IOException, XmlPullParserException
1566 {
1567 Settings settings = null;
1568 int eventType = parser.getEventType();
1569 boolean parsed = false;
1570 while ( eventType != XmlPullParser.END_DOCUMENT )
1571 {
1572 if ( eventType == XmlPullParser.START_TAG )
1573 {
1574 if ( strict && ! "settings".equals( parser.getName() ) )
1575 {
1576 throw new XmlPullParserException( "Expected root element 'settings' but found '" + parser.getName() + "'", parser, null );
1577 }
1578 else if ( parsed )
1579 {
1580
1581 throw new XmlPullParserException( "Duplicated tag: 'settings'", parser, null );
1582 }
1583 settings = parseSettings( parser, strict );
1584 settings.setModelEncoding( parser.getInputEncoding() );
1585 parsed = true;
1586 }
1587 eventType = parser.next();
1588 }
1589 if ( parsed )
1590 {
1591 return settings;
1592 }
1593 throw new XmlPullParserException( "Expected root element 'settings' but found no element at all: invalid XML document", parser, null );
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 }