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