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( Reader reader, boolean strict )
571 throws IOException, XmlPullParserException
572 {
573 XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
574
575 parser.setInput( reader );
576
577
578 return read( parser, strict );
579 }
580
581
582
583
584
585
586
587
588
589
590 public ProfilesRoot read( Reader reader )
591 throws IOException, XmlPullParserException
592 {
593 return read( reader, true );
594 }
595
596
597
598
599
600
601
602
603
604
605
606 public ProfilesRoot read( InputStream in, boolean strict )
607 throws IOException, XmlPullParserException
608 {
609 return read( ReaderFactory.newXmlReader( in ), strict );
610 }
611
612
613
614
615
616
617
618
619
620
621 public ProfilesRoot read( InputStream in )
622 throws IOException, XmlPullParserException
623 {
624 return read( ReaderFactory.newXmlReader( in ) );
625 }
626
627
628
629
630
631
632
633
634
635
636
637 private Activation parseActivation( XmlPullParser parser, boolean strict )
638 throws IOException, XmlPullParserException
639 {
640 String tagName = parser.getName();
641 Activation activation = new Activation();
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, "activeByDefault", null, parsed ) )
660 {
661 activation.setActiveByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "activeByDefault" ), "activeByDefault", parser, "false" ) );
662 }
663 else if ( checkFieldWithDuplicate( parser, "jdk", null, parsed ) )
664 {
665 activation.setJdk( interpolatedTrimmed( parser.nextText(), "jdk" ) );
666 }
667 else if ( checkFieldWithDuplicate( parser, "os", null, parsed ) )
668 {
669 activation.setOs( parseActivationOS( parser, strict ) );
670 }
671 else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) )
672 {
673 activation.setProperty( parseActivationProperty( parser, strict ) );
674 }
675 else if ( checkFieldWithDuplicate( parser, "file", null, parsed ) )
676 {
677 activation.setFile( parseActivationFile( parser, strict ) );
678 }
679 else
680 {
681 checkUnknownElement( parser, strict );
682 }
683 }
684 return activation;
685 }
686
687
688
689
690
691
692
693
694
695
696
697 private ActivationFile parseActivationFile( XmlPullParser parser, boolean strict )
698 throws IOException, XmlPullParserException
699 {
700 String tagName = parser.getName();
701 ActivationFile activationFile = new ActivationFile();
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 parsed = new java.util.HashSet();
717 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
718 {
719 if ( checkFieldWithDuplicate( parser, "missing", null, parsed ) )
720 {
721 activationFile.setMissing( interpolatedTrimmed( parser.nextText(), "missing" ) );
722 }
723 else if ( checkFieldWithDuplicate( parser, "exists", null, parsed ) )
724 {
725 activationFile.setExists( interpolatedTrimmed( parser.nextText(), "exists" ) );
726 }
727 else
728 {
729 checkUnknownElement( parser, strict );
730 }
731 }
732 return activationFile;
733 }
734
735
736
737
738
739
740
741
742
743
744
745 private ActivationOS parseActivationOS( XmlPullParser parser, boolean strict )
746 throws IOException, XmlPullParserException
747 {
748 String tagName = parser.getName();
749 ActivationOS activationOS = new ActivationOS();
750 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
751 {
752 String name = parser.getAttributeName( i );
753 String value = parser.getAttributeValue( i );
754
755 if ( name.indexOf( ':' ) >= 0 )
756 {
757
758 }
759 else
760 {
761 checkUnknownAttribute( parser, name, tagName, strict );
762 }
763 }
764 java.util.Set parsed = new java.util.HashSet();
765 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
766 {
767 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
768 {
769 activationOS.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
770 }
771 else if ( checkFieldWithDuplicate( parser, "family", null, parsed ) )
772 {
773 activationOS.setFamily( interpolatedTrimmed( parser.nextText(), "family" ) );
774 }
775 else if ( checkFieldWithDuplicate( parser, "arch", null, parsed ) )
776 {
777 activationOS.setArch( interpolatedTrimmed( parser.nextText(), "arch" ) );
778 }
779 else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
780 {
781 activationOS.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) );
782 }
783 else
784 {
785 checkUnknownElement( parser, strict );
786 }
787 }
788 return activationOS;
789 }
790
791
792
793
794
795
796
797
798
799
800
801 private ActivationProperty parseActivationProperty( XmlPullParser parser, boolean strict )
802 throws IOException, XmlPullParserException
803 {
804 String tagName = parser.getName();
805 ActivationProperty activationProperty = new ActivationProperty();
806 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
807 {
808 String name = parser.getAttributeName( i );
809 String value = parser.getAttributeValue( i );
810
811 if ( name.indexOf( ':' ) >= 0 )
812 {
813
814 }
815 else
816 {
817 checkUnknownAttribute( parser, name, tagName, strict );
818 }
819 }
820 java.util.Set parsed = new java.util.HashSet();
821 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
822 {
823 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
824 {
825 activationProperty.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
826 }
827 else if ( checkFieldWithDuplicate( parser, "value", null, parsed ) )
828 {
829 activationProperty.setValue( interpolatedTrimmed( parser.nextText(), "value" ) );
830 }
831 else
832 {
833 checkUnknownElement( parser, strict );
834 }
835 }
836 return activationProperty;
837 }
838
839
840
841
842
843
844
845
846
847
848
849 private Profile parseProfile( XmlPullParser parser, boolean strict )
850 throws IOException, XmlPullParserException
851 {
852 String tagName = parser.getName();
853 Profile profile = new Profile();
854 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
855 {
856 String name = parser.getAttributeName( i );
857 String value = parser.getAttributeValue( i );
858
859 if ( name.indexOf( ':' ) >= 0 )
860 {
861
862 }
863 else
864 {
865 checkUnknownAttribute( parser, name, tagName, strict );
866 }
867 }
868 java.util.Set parsed = new java.util.HashSet();
869 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
870 {
871 if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
872 {
873 profile.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
874 }
875 else if ( checkFieldWithDuplicate( parser, "activation", null, parsed ) )
876 {
877 profile.setActivation( parseActivation( parser, strict ) );
878 }
879 else if ( checkFieldWithDuplicate( parser, "properties", null, parsed ) )
880 {
881 while ( parser.nextTag() == XmlPullParser.START_TAG )
882 {
883 String key = parser.getName();
884 String value = parser.nextText().trim();
885 profile.addProperty( key, value );
886 }
887 }
888 else if ( checkFieldWithDuplicate( parser, "repositories", null, parsed ) )
889 {
890 java.util.List<Repository> repositories = new java.util.ArrayList<Repository>();
891 profile.setRepositories( repositories );
892 while ( parser.nextTag() == XmlPullParser.START_TAG )
893 {
894 if ( "repository".equals( parser.getName() ) )
895 {
896 repositories.add( parseRepository( parser, strict ) );
897 }
898 else
899 {
900 checkUnknownElement( parser, strict );
901 }
902 }
903 }
904 else if ( checkFieldWithDuplicate( parser, "pluginRepositories", null, parsed ) )
905 {
906 java.util.List<Repository> pluginRepositories = new java.util.ArrayList<Repository>();
907 profile.setPluginRepositories( pluginRepositories );
908 while ( parser.nextTag() == XmlPullParser.START_TAG )
909 {
910 if ( "pluginRepository".equals( parser.getName() ) )
911 {
912 pluginRepositories.add( parseRepository( parser, strict ) );
913 }
914 else
915 {
916 checkUnknownElement( parser, strict );
917 }
918 }
919 }
920 else
921 {
922 checkUnknownElement( parser, strict );
923 }
924 }
925 return profile;
926 }
927
928
929
930
931
932
933
934
935
936
937
938 private ProfilesRoot parseProfilesRoot( XmlPullParser parser, boolean strict )
939 throws IOException, XmlPullParserException
940 {
941 String tagName = parser.getName();
942 ProfilesRoot profilesRoot = new ProfilesRoot();
943 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
944 {
945 String name = parser.getAttributeName( i );
946 String value = parser.getAttributeValue( i );
947
948 if ( name.indexOf( ':' ) >= 0 )
949 {
950
951 }
952 else if ( "xmlns".equals( name ) )
953 {
954
955 }
956 else
957 {
958 checkUnknownAttribute( parser, name, tagName, strict );
959 }
960 }
961 java.util.Set parsed = new java.util.HashSet();
962 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
963 {
964 if ( checkFieldWithDuplicate( parser, "profiles", null, parsed ) )
965 {
966 java.util.List<Profile> profiles = new java.util.ArrayList<Profile>();
967 profilesRoot.setProfiles( profiles );
968 while ( parser.nextTag() == XmlPullParser.START_TAG )
969 {
970 if ( "profile".equals( parser.getName() ) )
971 {
972 profiles.add( parseProfile( parser, strict ) );
973 }
974 else
975 {
976 checkUnknownElement( parser, strict );
977 }
978 }
979 }
980 else if ( checkFieldWithDuplicate( parser, "activeProfiles", null, parsed ) )
981 {
982 java.util.List<String> activeProfiles = new java.util.ArrayList<String>();
983 profilesRoot.setActiveProfiles( activeProfiles );
984 while ( parser.nextTag() == XmlPullParser.START_TAG )
985 {
986 if ( "activeProfile".equals( parser.getName() ) )
987 {
988 activeProfiles.add( interpolatedTrimmed( parser.nextText(), "activeProfiles" ) );
989 }
990 else
991 {
992 checkUnknownElement( parser, strict );
993 }
994 }
995 }
996 else
997 {
998 checkUnknownElement( parser, strict );
999 }
1000 }
1001 return profilesRoot;
1002 }
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014 private Repository parseRepository( XmlPullParser parser, boolean strict )
1015 throws IOException, XmlPullParserException
1016 {
1017 String tagName = parser.getName();
1018 Repository repository = new Repository();
1019 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1020 {
1021 String name = parser.getAttributeName( i );
1022 String value = parser.getAttributeValue( i );
1023
1024 if ( name.indexOf( ':' ) >= 0 )
1025 {
1026
1027 }
1028 else
1029 {
1030 checkUnknownAttribute( parser, name, tagName, strict );
1031 }
1032 }
1033 java.util.Set parsed = new java.util.HashSet();
1034 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1035 {
1036 if ( checkFieldWithDuplicate( parser, "releases", null, parsed ) )
1037 {
1038 repository.setReleases( parseRepositoryPolicy( parser, strict ) );
1039 }
1040 else if ( checkFieldWithDuplicate( parser, "snapshots", null, parsed ) )
1041 {
1042 repository.setSnapshots( parseRepositoryPolicy( parser, strict ) );
1043 }
1044 else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1045 {
1046 repository.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1047 }
1048 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1049 {
1050 repository.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1051 }
1052 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1053 {
1054 repository.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1055 }
1056 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1057 {
1058 repository.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1059 }
1060 else
1061 {
1062 checkUnknownElement( parser, strict );
1063 }
1064 }
1065 return repository;
1066 }
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078 private RepositoryBase parseRepositoryBase( XmlPullParser parser, boolean strict )
1079 throws IOException, XmlPullParserException
1080 {
1081 String tagName = parser.getName();
1082 RepositoryBase repositoryBase = new RepositoryBase();
1083 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1084 {
1085 String name = parser.getAttributeName( i );
1086 String value = parser.getAttributeValue( i );
1087
1088 if ( name.indexOf( ':' ) >= 0 )
1089 {
1090
1091 }
1092 else
1093 {
1094 checkUnknownAttribute( parser, name, tagName, strict );
1095 }
1096 }
1097 java.util.Set parsed = new java.util.HashSet();
1098 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1099 {
1100 if ( checkFieldWithDuplicate( parser, "id", null, parsed ) )
1101 {
1102 repositoryBase.setId( interpolatedTrimmed( parser.nextText(), "id" ) );
1103 }
1104 else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
1105 {
1106 repositoryBase.setName( interpolatedTrimmed( parser.nextText(), "name" ) );
1107 }
1108 else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) )
1109 {
1110 repositoryBase.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) );
1111 }
1112 else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) )
1113 {
1114 repositoryBase.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) );
1115 }
1116 else
1117 {
1118 checkUnknownElement( parser, strict );
1119 }
1120 }
1121 return repositoryBase;
1122 }
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134 private RepositoryPolicy parseRepositoryPolicy( XmlPullParser parser, boolean strict )
1135 throws IOException, XmlPullParserException
1136 {
1137 String tagName = parser.getName();
1138 RepositoryPolicy repositoryPolicy = new RepositoryPolicy();
1139 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1140 {
1141 String name = parser.getAttributeName( i );
1142 String value = parser.getAttributeValue( i );
1143
1144 if ( name.indexOf( ':' ) >= 0 )
1145 {
1146
1147 }
1148 else
1149 {
1150 checkUnknownAttribute( parser, name, tagName, strict );
1151 }
1152 }
1153 java.util.Set parsed = new java.util.HashSet();
1154 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1155 {
1156 if ( checkFieldWithDuplicate( parser, "enabled", null, parsed ) )
1157 {
1158 repositoryPolicy.setEnabled( getBooleanValue( interpolatedTrimmed( parser.nextText(), "enabled" ), "enabled", parser, "true" ) );
1159 }
1160 else if ( checkFieldWithDuplicate( parser, "updatePolicy", null, parsed ) )
1161 {
1162 repositoryPolicy.setUpdatePolicy( interpolatedTrimmed( parser.nextText(), "updatePolicy" ) );
1163 }
1164 else if ( checkFieldWithDuplicate( parser, "checksumPolicy", null, parsed ) )
1165 {
1166 repositoryPolicy.setChecksumPolicy( interpolatedTrimmed( parser.nextText(), "checksumPolicy" ) );
1167 }
1168 else
1169 {
1170 checkUnknownElement( parser, strict );
1171 }
1172 }
1173 return repositoryPolicy;
1174 }
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186 private ProfilesRoot read( XmlPullParser parser, boolean strict )
1187 throws IOException, XmlPullParserException
1188 {
1189 ProfilesRoot profilesRoot = null;
1190 int eventType = parser.getEventType();
1191 boolean parsed = false;
1192 while ( eventType != XmlPullParser.END_DOCUMENT )
1193 {
1194 if ( eventType == XmlPullParser.START_TAG )
1195 {
1196 if ( strict && ! "profilesXml".equals( parser.getName() ) )
1197 {
1198 throw new XmlPullParserException( "Expected root element 'profilesXml' but found '" + parser.getName() + "'", parser, null );
1199 }
1200 else if ( parsed )
1201 {
1202
1203 throw new XmlPullParserException( "Duplicated tag: 'profilesXml'", parser, null );
1204 }
1205 profilesRoot = parseProfilesRoot( parser, strict );
1206 profilesRoot.setModelEncoding( parser.getInputEncoding() );
1207 parsed = true;
1208 }
1209 eventType = parser.next();
1210 }
1211 if ( parsed )
1212 {
1213 return profilesRoot;
1214 }
1215 throw new XmlPullParserException( "Expected root element 'profilesXml' but found no element at all: invalid XML document", parser, null );
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 }