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