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