1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.apache.maven.profiles.io.xpp3;
25
26
27
28
29
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.Reader;
33 import java.text.DateFormat;
34 import org.apache.maven.profiles.Activation;
35 import org.apache.maven.profiles.ActivationFile;
36 import org.apache.maven.profiles.ActivationOS;
37 import org.apache.maven.profiles.ActivationProperty;
38 import org.apache.maven.profiles.Profile;
39 import org.apache.maven.profiles.ProfilesRoot;
40 import org.apache.maven.profiles.Repository;
41 import org.apache.maven.profiles.RepositoryBase;
42 import org.apache.maven.profiles.RepositoryPolicy;
43 import org.codehaus.plexus.util.xml.XmlStreamReader;
44 import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
45 import org.codehaus.plexus.util.xml.pull.MXParser;
46 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
47 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
48
49
50
51
52
53
54 @SuppressWarnings( "all" )
55 public class ProfilesXpp3Reader
56 {
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 private boolean addDefaultEntities = true;
73
74
75
76
77 public final ContentTransformer contentTransformer;
78
79
80
81
82
83
84 public ProfilesXpp3Reader()
85 {
86 this( new ContentTransformer()
87 {
88 public String transform( String source, String fieldName )
89 {
90 return source;
91 }
92 } );
93 }
94
95 public ProfilesXpp3Reader(ContentTransformer contentTransformer)
96 {
97 this.contentTransformer = contentTransformer;
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set<String> parsed )
117 throws XmlPullParserException
118 {
119 if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
120 {
121 return false;
122 }
123 if ( !parsed.add( tagName ) )
124 {
125 throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
126 }
127 return true;
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141 private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
142 throws XmlPullParserException, IOException
143 {
144
145 if ( strict )
146 {
147 throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
148 }
149 }
150
151
152
153
154
155
156
157
158
159
160 private void checkUnknownElement( XmlPullParser parser, boolean strict )
161 throws XmlPullParserException, IOException
162 {
163 if ( strict )
164 {
165 throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
166 }
167
168 for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
169 {
170 int eventType = parser.next();
171 if ( eventType == XmlPullParser.START_TAG )
172 {
173 unrecognizedTagCount++;
174 }
175 else if ( eventType == XmlPullParser.END_TAG )
176 {
177 unrecognizedTagCount--;
178 }
179 }
180 }
181
182
183
184
185
186
187 public boolean getAddDefaultEntities()
188 {
189 return addDefaultEntities;
190 }
191
192
193
194
195
196
197
198
199
200
201
202 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
203 throws XmlPullParserException
204 {
205 return getBooleanValue( s, attribute, parser, null );
206 }
207
208
209
210
211
212
213
214
215
216
217
218
219 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
220 throws XmlPullParserException
221 {
222 if ( s != null && s.length() != 0 )
223 {
224 return Boolean.valueOf( s ).booleanValue();
225 }
226 if ( defaultValue != null )
227 {
228 return Boolean.valueOf( defaultValue ).booleanValue();
229 }
230 return false;
231 }
232
233
234
235
236
237
238
239
240
241
242
243
244 private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
245 throws XmlPullParserException
246 {
247 if ( s != null )
248 {
249 try
250 {
251 return Byte.valueOf( s ).byteValue();
252 }
253 catch ( NumberFormatException nfe )
254 {
255 if ( strict )
256 {
257 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
258 }
259 }
260 }
261 return 0;
262 }
263
264
265
266
267
268
269
270
271
272
273
274 private char getCharacterValue( String s, String attribute, XmlPullParser parser )
275 throws XmlPullParserException
276 {
277 if ( s != null )
278 {
279 return s.charAt( 0 );
280 }
281 return 0;
282 }
283
284
285
286
287
288
289
290
291
292
293
294 private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
295 throws XmlPullParserException
296 {
297 return getDateValue( s, attribute, null, parser );
298 }
299
300
301
302
303
304
305
306
307
308
309
310
311 private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
312 throws XmlPullParserException
313 {
314 if ( s != null )
315 {
316 String effectiveDateFormat = dateFormat;
317 if ( dateFormat == null )
318 {
319 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
320 }
321 if ( "long".equals( effectiveDateFormat ) )
322 {
323 try
324 {
325 return new java.util.Date( Long.parseLong( s ) );
326 }
327 catch ( NumberFormatException e )
328 {
329 throw new XmlPullParserException( e.getMessage(), parser, e );
330 }
331 }
332 else
333 {
334 try
335 {
336 DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
337 return dateParser.parse( s );
338 }
339 catch ( java.text.ParseException e )
340 {
341 throw new XmlPullParserException( e.getMessage(), parser, e );
342 }
343 }
344 }
345 return null;
346 }
347
348
349
350
351
352
353
354
355
356
357
358
359 private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
360 throws XmlPullParserException
361 {
362 if ( s != null )
363 {
364 try
365 {
366 return Double.valueOf( s ).doubleValue();
367 }
368 catch ( NumberFormatException nfe )
369 {
370 if ( strict )
371 {
372 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
373 }
374 }
375 }
376 return 0;
377 }
378
379
380
381
382
383
384
385
386
387
388
389
390 private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
391 throws XmlPullParserException
392 {
393 if ( s != null )
394 {
395 try
396 {
397 return Float.valueOf( s ).floatValue();
398 }
399 catch ( NumberFormatException nfe )
400 {
401 if ( strict )
402 {
403 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
404 }
405 }
406 }
407 return 0;
408 }
409
410
411
412
413
414
415
416
417
418
419
420
421 private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
422 throws XmlPullParserException
423 {
424 if ( s != null )
425 {
426 try
427 {
428 return Integer.valueOf( s ).intValue();
429 }
430 catch ( NumberFormatException nfe )
431 {
432 if ( strict )
433 {
434 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
435 }
436 }
437 }
438 return 0;
439 }
440
441
442
443
444
445
446
447
448
449
450
451
452 private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
453 throws XmlPullParserException
454 {
455 if ( s != null )
456 {
457 try
458 {
459 return Long.valueOf( s ).longValue();
460 }
461 catch ( NumberFormatException nfe )
462 {
463 if ( strict )
464 {
465 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
466 }
467 }
468 }
469 return 0;
470 }
471
472
473
474
475
476
477
478
479
480
481
482
483 private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
484 throws XmlPullParserException
485 {
486 if ( s == null )
487 {
488 if ( strict )
489 {
490 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
491 }
492 }
493 return s;
494 }
495
496
497
498
499
500
501
502
503
504
505
506
507 private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
508 throws XmlPullParserException
509 {
510 if ( s != null )
511 {
512 try
513 {
514 return Short.valueOf( s ).shortValue();
515 }
516 catch ( NumberFormatException nfe )
517 {
518 if ( strict )
519 {
520 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
521 }
522 }
523 }
524 return 0;
525 }
526
527
528
529
530
531
532
533 private String getTrimmedValue( String s )
534 {
535 if ( s != null )
536 {
537 s = s.trim();
538 }
539 return s;
540 }
541
542
543
544
545
546
547
548
549 private String interpolatedTrimmed( String value, String context )
550 {
551 return getTrimmedValue( contentTransformer.transform( value, context ) );
552 }
553
554
555
556
557
558
559
560
561
562
563 private int nextTag( XmlPullParser parser )
564 throws IOException, XmlPullParserException
565 {
566 int eventType = parser.next();
567 if ( eventType == XmlPullParser.TEXT )
568 {
569 eventType = parser.next();
570 }
571 if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
572 {
573 throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
574 }
575 return eventType;
576 }
577
578
579
580
581
582
583
584
585
586
587
588 public ProfilesRoot read( XmlPullParser parser, boolean strict )
589 throws IOException, XmlPullParserException
590 {
591 ProfilesRoot profilesRoot = null;
592 int eventType = parser.getEventType();
593 boolean parsed = false;
594 while ( eventType != XmlPullParser.END_DOCUMENT )
595 {
596 if ( eventType == XmlPullParser.START_TAG )
597 {
598 if ( strict && ! "profilesXml".equals( parser.getName() ) )
599 {
600 throw new XmlPullParserException( "Expected root element 'profilesXml' but found '" + parser.getName() + "'", parser, null );
601 }
602 else if ( parsed )
603 {
604
605 throw new XmlPullParserException( "Duplicated tag: 'profilesXml'", parser, null );
606 }
607 profilesRoot = parseProfilesRoot( parser, strict );
608 profilesRoot.setModelEncoding( parser.getInputEncoding() );
609 parsed = true;
610 }
611 eventType = parser.next();
612 }
613 if ( parsed )
614 {
615 return profilesRoot;
616 }
617 throw new XmlPullParserException( "Expected root element 'profilesXml' but found no element at all: invalid XML document", parser, null );
618 }
619
620
621
622
623
624
625
626
627
628
629
630 public ProfilesRoot read( Reader reader, boolean strict )
631 throws IOException, XmlPullParserException
632 {
633 XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
634
635 parser.setInput( reader );
636
637
638 return read( parser, strict );
639 }
640
641
642
643
644
645
646
647
648
649
650 public ProfilesRoot read( Reader reader )
651 throws IOException, XmlPullParserException
652 {
653 return read( reader, true );
654 }
655
656
657
658
659
660
661
662
663
664
665
666 public ProfilesRoot read( InputStream in, boolean strict )
667 throws IOException, XmlPullParserException
668 {
669 return read( new XmlStreamReader( in ), strict );
670 }
671
672
673
674
675
676
677
678
679
680
681 public ProfilesRoot read( InputStream in )
682 throws IOException, XmlPullParserException
683 {
684 return read( new XmlStreamReader( in ) );
685 }
686
687
688
689
690
691
692
693
694
695
696
697 private Activation parseActivation( XmlPullParser parser, boolean strict )
698 throws IOException, XmlPullParserException
699 {
700 String tagName = parser.getName();
701 Activation activation = new Activation();
702 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
703 {
704 String name = parser.getAttributeName( i );
705 String value = parser.getAttributeValue( i );
706
707 if ( name.indexOf( ':' ) >= 0 )
708 {
709
710 }
711 else
712 {
713 checkUnknownAttribute( parser, name, tagName, strict );
714 }
715 }
716 java.util.Set<String> parsed = new java.util.HashSet<String>();
717 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
718 {
719 if ( checkFieldWithDuplicate( parser, "activeByDefault", null, parsed ) )
720 {
721 activation.setActiveByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "activeByDefault" ), "activeByDefault", parser, "false" ) );
722 }
723 else if ( checkFieldWithDuplicate( parser, "jdk", null, parsed ) )
724 {
725 activation.setJdk( interpolatedTrimmed( parser.nextText(), "jdk" ) );
726 }
727 else if ( checkFieldWithDuplicate( parser, "os", null, parsed ) )
728 {
729 activation.setOs( parseActivationOS( parser, strict ) );
730 }
731 else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) )
732 {
733 activation.setProperty( parseActivationProperty( parser, strict ) );
734 }
735 else if ( checkFieldWithDuplicate( parser, "file", null, parsed ) )
736 {
737 activation.setFile( parseActivationFile( parser, strict ) );
738 }
739 else
740 {
741 checkUnknownElement( parser, strict );
742 }
743 }
744 return activation;
745 }
746
747
748
749
750
751
752
753
754
755
756
757 private ActivationFile parseActivationFile( XmlPullParser parser, boolean strict )
758 throws IOException, XmlPullParserException
759 {
760 String tagName = parser.getName();
761 ActivationFile activationFile = new ActivationFile();
762 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
763 {
764 String name = parser.getAttributeName( i );
765 String value = parser.getAttributeValue( i );
766
767 if ( name.indexOf( ':' ) >= 0 )
768 {
769
770 }
771 else
772 {
773 checkUnknownAttribute( parser, name, tagName, strict );
774 }
775 }
776 java.util.Set<String> parsed = new java.util.HashSet<String>();
777 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
778 {
779 if ( checkFieldWithDuplicate( parser, "missing", null, parsed ) )
780 {
781 activationFile.setMissing( interpolatedTrimmed( parser.nextText(), "missing" ) );
782 }
783 else if ( checkFieldWithDuplicate( parser, "exists", null, parsed ) )
784 {
785 activationFile.setExists( interpolatedTrimmed( parser.nextText(), "exists" ) );
786 }
787 else
788 {
789 checkUnknownElement( parser, strict );
790 }
791 }
792 return activationFile;
793 }
794
795
796
797
798
799
800
801
802
803
804
805 private ActivationOS parseActivationOS( XmlPullParser parser, boolean strict )
806 throws IOException, XmlPullParserException
807 {
808 String tagName = parser.getName();
809 ActivationOS activationOS = new ActivationOS();
810 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
811 {
812 String name = parser.getAttributeName( i );
813 String value = parser.getAttributeValue( i );
814
815 if ( name.indexOf( ':' ) >= 0 )
816 {
817
818 }
819 else
820 {
821 checkUnknownAttribute( parser, name, tagName, strict );
822 }
823 }
824 java.util.Set<String> parsed = new java.util.HashSet<String>();
825 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
826 {
827 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
828 {
829 activationOS.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
830 }
831 else if ( checkFieldWithDuplicate( parser, "family", null, parsed ) )
832 {
833 activationOS.setFamily( interpolatedTrimmed( parser.nextText(), "family" ) );
834 }
835 else if ( checkFieldWithDuplicate( parser, "arch", null, parsed ) )
836 {
837 activationOS.setArch( interpolatedTrimmed( parser.nextText(), "arch" ) );
838 }
839 else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
840 {
841 activationOS.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) );
842 }
843 else
844 {
845 checkUnknownElement( parser, strict );
846 }
847 }
848 return activationOS;
849 }
850
851
852
853
854
855
856
857
858
859
860
861 private ActivationProperty parseActivationProperty( XmlPullParser parser, boolean strict )
862 throws IOException, XmlPullParserException
863 {
864 String tagName = parser.getName();
865 ActivationProperty activationProperty = new ActivationProperty();
866 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
867 {
868 String name = parser.getAttributeName( i );
869 String value = parser.getAttributeValue( i );
870
871 if ( name.indexOf( ':' ) >= 0 )
872 {
873
874 }
875 else
876 {
877 checkUnknownAttribute( parser, name, tagName, strict );
878 }
879 }
880 java.util.Set<String> parsed = new java.util.HashSet<String>();
881 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
882 {
883 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
884 {
885 activationProperty.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
886 }
887 else if ( checkFieldWithDuplicate( parser, "value", null, parsed ) )
888 {
889 activationProperty.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
890 }
891 else
892 {
893 checkUnknownElement( parser, strict );
894 }
895 }
896 return activationProperty;
897 }
898
899
900
901
902
903
904
905
906
907
908
909 private Profile parseProfile( XmlPullParser parser, boolean strict )
910 throws IOException, XmlPullParserException
911 {
912 String tagName = parser.getName();
913 Profile profile = new Profile();
914 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
915 {
916 String name = parser.getAttributeName( i );
917 String value = parser.getAttributeValue( i );
918
919 if ( name.indexOf( ':' ) >= 0 )
920 {
921
922 }
923 else
924 {
925 checkUnknownAttribute( parser, name, tagName, strict );
926 }
927 }
928 java.util.Set<String> parsed = new java.util.HashSet<String>();
929 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
930 {
931 if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
932 {
933 profile.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
934 }
935 else if ( checkFieldWithDuplicate( parser, "activation", null, parsed ) )
936 {
937 profile.setActivation( parseActivation( parser, strict ) );
938 }
939 else if ( checkFieldWithDuplicate( parser, "properties", null, parsed ) )
940 {
941 while ( parser.nextTag() == XmlPullParser.START_TAG )
942 {
943 String key = parser.getName();
944 String value = parser.nextText().trim();
945 profile.addProperty( key, value );
946 }
947 }
948 else if ( checkFieldWithDuplicate( parser, "repositories", null, parsed ) )
949 {
950 java.util.List<Repository> repositories = new java.util.ArrayList<Repository>();
951 while ( parser.nextTag() == XmlPullParser.START_TAG )
952 {
953 if ( "repository".equals( parser.getName() ) )
954 {
955 repositories.add( parseRepository( parser, strict ) );
956 }
957 else
958 {
959 checkUnknownElement( parser, strict );
960 }
961 }
962 profile.setRepositories( repositories );
963 }
964 else if ( checkFieldWithDuplicate( parser, "pluginRepositories", null, parsed ) )
965 {
966 java.util.List<Repository> pluginRepositories = new java.util.ArrayList<Repository>();
967 while ( parser.nextTag() == XmlPullParser.START_TAG )
968 {
969 if ( "pluginRepository".equals( parser.getName() ) )
970 {
971 pluginRepositories.add( parseRepository( parser, strict ) );
972 }
973 else
974 {
975 checkUnknownElement( parser, strict );
976 }
977 }
978 profile.setPluginRepositories( pluginRepositories );
979 }
980 else
981 {
982 checkUnknownElement( parser, strict );
983 }
984 }
985 return profile;
986 }
987
988
989
990
991
992
993
994
995
996
997
998 private ProfilesRoot parseProfilesRoot( XmlPullParser parser, boolean strict )
999 throws IOException, XmlPullParserException
1000 {
1001 String tagName = parser.getName();
1002 ProfilesRoot profilesRoot = new ProfilesRoot();
1003 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1004 {
1005 String name = parser.getAttributeName( i );
1006 String value = parser.getAttributeValue( i );
1007
1008 if ( name.indexOf( ':' ) >= 0 )
1009 {
1010
1011 }
1012 else if ( "xmlns".equals( name ) )
1013 {
1014
1015 }
1016 else
1017 {
1018 checkUnknownAttribute( parser, name, tagName, strict );
1019 }
1020 }
1021 java.util.Set<String> parsed = new java.util.HashSet<String>();
1022 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1023 {
1024 if ( checkFieldWithDuplicate( parser, "profiles", null, parsed ) )
1025 {
1026 java.util.List<Profile> profiles = new java.util.ArrayList<Profile>();
1027 while ( parser.nextTag() == XmlPullParser.START_TAG )
1028 {
1029 if ( "profile".equals( parser.getName() ) )
1030 {
1031 profiles.add( parseProfile( parser, strict ) );
1032 }
1033 else
1034 {
1035 checkUnknownElement( parser, strict );
1036 }
1037 }
1038 profilesRoot.setProfiles( profiles );
1039 }
1040 else if ( checkFieldWithDuplicate( parser, "activeProfiles", null, parsed ) )
1041 {
1042 java.util.List<String> activeProfiles = new java.util.ArrayList<String>();
1043 while ( parser.nextTag() == XmlPullParser.START_TAG )
1044 {
1045 if ( "activeProfile".equals( parser.getName() ) )
1046 {
1047 activeProfiles.add( interpolatedTrimmed( parser.nextText(), "activeProfiles" ) );
1048 }
1049 else
1050 {
1051 checkUnknownElement( parser, strict );
1052 }
1053 }
1054 profilesRoot.setActiveProfiles( activeProfiles );
1055 }
1056 else
1057 {
1058 checkUnknownElement( parser, strict );
1059 }
1060 }
1061 return profilesRoot;
1062 }
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074 private Repository parseRepository( XmlPullParser parser, boolean strict )
1075 throws IOException, XmlPullParserException
1076 {
1077 String tagName = parser.getName();
1078 Repository repository = new Repository();
1079 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1080 {
1081 String name = parser.getAttributeName( i );
1082 String value = parser.getAttributeValue( i );
1083
1084 if ( name.indexOf( ':' ) >= 0 )
1085 {
1086
1087 }
1088 else
1089 {
1090 checkUnknownAttribute( parser, name, tagName, strict );
1091 }
1092 }
1093 java.util.Set<String> parsed = new java.util.HashSet<String>();
1094 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1095 {
1096 if ( checkFieldWithDuplicate( parser, "releases", null, parsed ) )
1097 {
1098 repository.setReleases( parseRepositoryPolicy( parser, strict ) );
1099 }
1100 else if ( checkFieldWithDuplicate( parser, "snapshots", null, parsed ) )
1101 {
1102 repository.setSnapshots( parseRepositoryPolicy( parser, strict ) );
1103 }
1104 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1105 {
1106 repository.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1107 }
1108 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1109 {
1110 repository.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1111 }
1112 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1113 {
1114 repository.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1115 }
1116 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1117 {
1118 repository.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1119 }
1120 else
1121 {
1122 checkUnknownElement( parser, strict );
1123 }
1124 }
1125 return repository;
1126 }
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138 private RepositoryBase parseRepositoryBase( XmlPullParser parser, boolean strict )
1139 throws IOException, XmlPullParserException
1140 {
1141 String tagName = parser.getName();
1142 RepositoryBase repositoryBase = new RepositoryBase();
1143 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1144 {
1145 String name = parser.getAttributeName( i );
1146 String value = parser.getAttributeValue( i );
1147
1148 if ( name.indexOf( ':' ) >= 0 )
1149 {
1150
1151 }
1152 else
1153 {
1154 checkUnknownAttribute( parser, name, tagName, strict );
1155 }
1156 }
1157 java.util.Set<String> parsed = new java.util.HashSet<String>();
1158 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1159 {
1160 if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1161 {
1162 repositoryBase.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1163 }
1164 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1165 {
1166 repositoryBase.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1167 }
1168 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1169 {
1170 repositoryBase.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1171 }
1172 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1173 {
1174 repositoryBase.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1175 }
1176 else
1177 {
1178 checkUnknownElement( parser, strict );
1179 }
1180 }
1181 return repositoryBase;
1182 }
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194 private RepositoryPolicy parseRepositoryPolicy( XmlPullParser parser, boolean strict )
1195 throws IOException, XmlPullParserException
1196 {
1197 String tagName = parser.getName();
1198 RepositoryPolicy repositoryPolicy = new RepositoryPolicy();
1199 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1200 {
1201 String name = parser.getAttributeName( i );
1202 String value = parser.getAttributeValue( i );
1203
1204 if ( name.indexOf( ':' ) >= 0 )
1205 {
1206
1207 }
1208 else
1209 {
1210 checkUnknownAttribute( parser, name, tagName, strict );
1211 }
1212 }
1213 java.util.Set<String> parsed = new java.util.HashSet<String>();
1214 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1215 {
1216 if ( checkFieldWithDuplicate( parser, "enabled", null, parsed ) )
1217 {
1218 repositoryPolicy.setEnabled( getBooleanValue( interpolatedTrimmed( parser.nextText(), "enabled" ), "enabled", parser, "true" ) );
1219 }
1220 else if ( checkFieldWithDuplicate( parser, "updatePolicy", null, parsed ) )
1221 {
1222 repositoryPolicy.setUpdatePolicy( interpolatedTrimmed( parser.nextText(), "updatePolicy" ) );
1223 }
1224 else if ( checkFieldWithDuplicate( parser, "checksumPolicy", null, parsed ) )
1225 {
1226 repositoryPolicy.setChecksumPolicy( interpolatedTrimmed( parser.nextText(), "checksumPolicy" ) );
1227 }
1228 else
1229 {
1230 checkUnknownElement( parser, strict );
1231 }
1232 }
1233 return repositoryPolicy;
1234 }
1235
1236
1237
1238
1239
1240
1241 public void setAddDefaultEntities( boolean addDefaultEntities )
1242 {
1243 this.addDefaultEntities = addDefaultEntities;
1244 }
1245
1246 public static interface ContentTransformer
1247 {
1248
1249
1250
1251
1252
1253
1254
1255 String transform( String source, String fieldName );
1256 }
1257
1258 }