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