View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from reader-stax.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.settings.v4;
6   
7   import java.io.IOException;
8   import java.io.InputStream;
9   import java.io.Reader;
10  import java.text.DateFormat;
11  import java.util.ArrayList;
12  import java.util.Collections;
13  import java.util.Date;
14  import java.util.HashMap;
15  import java.util.HashSet;
16  import java.util.LinkedHashMap;
17  import java.util.List;
18  import java.util.Map;
19  import java.util.Set;
20  import org.apache.maven.api.annotations.Generated;
21  import org.apache.maven.api.settings.InputSource;
22  import org.apache.maven.api.settings.InputLocation;
23  import org.apache.maven.api.settings.TrackableBase;
24  import org.apache.maven.api.settings.IdentifiableBase;
25  import org.apache.maven.api.settings.Settings;
26  import org.apache.maven.api.settings.Proxy;
27  import org.apache.maven.api.settings.Server;
28  import org.apache.maven.api.settings.Mirror;
29  import org.apache.maven.api.settings.Profile;
30  import org.apache.maven.api.settings.Activation;
31  import org.apache.maven.api.settings.RepositoryBase;
32  import org.apache.maven.api.settings.Repository;
33  import org.apache.maven.api.settings.RepositoryPolicy;
34  import org.apache.maven.api.settings.ActivationProperty;
35  import org.apache.maven.api.settings.ActivationOS;
36  import org.apache.maven.api.settings.ActivationFile;
37  import org.apache.maven.api.settings.InputLocation;
38  import org.apache.maven.api.settings.InputSource;
39  import org.apache.maven.internal.xml.XmlNodeStaxBuilder;
40  import org.apache.maven.api.xml.XmlNode;
41  import javax.xml.stream.XMLInputFactory;
42  import javax.xml.stream.XMLStreamException;
43  import javax.xml.stream.XMLStreamReader;
44  import javax.xml.transform.stream.StreamSource;
45  
46  import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
47  import static javax.xml.XMLConstants.XML_NS_URI;
48  
49  @Generated
50  public class SettingsStaxReader {
51  
52      private static final Map<String, String> DEFAULT_ENTITIES;
53      static {
54          Map<String, String> entities = new HashMap<>();
55          entities.put("nbsp", "\u00a0");
56          entities.put("iexcl", "\u00a1");
57          entities.put("cent", "\u00a2");
58          entities.put("pound", "\u00a3");
59          entities.put("curren", "\u00a4");
60          entities.put("yen", "\u00a5");
61          entities.put("brvbar", "\u00a6");
62          entities.put("sect", "\u00a7");
63          entities.put("uml", "\u00a8");
64          entities.put("copy", "\u00a9");
65          entities.put("ordf", "\u00aa");
66          entities.put("laquo", "\u00ab");
67          entities.put("not", "\u00ac");
68          entities.put("shy", "\u00ad");
69          entities.put("reg", "\u00ae");
70          entities.put("macr", "\u00af");
71          entities.put("deg", "\u00b0");
72          entities.put("plusmn", "\u00b1");
73          entities.put("sup2", "\u00b2");
74          entities.put("sup3", "\u00b3");
75          entities.put("acute", "\u00b4");
76          entities.put("micro", "\u00b5");
77          entities.put("para", "\u00b6");
78          entities.put("middot", "\u00b7");
79          entities.put("cedil", "\u00b8");
80          entities.put("sup1", "\u00b9");
81          entities.put("ordm", "\u00ba");
82          entities.put("raquo", "\u00bb");
83          entities.put("frac14", "\u00bc");
84          entities.put("frac12", "\u00bd");
85          entities.put("frac34", "\u00be");
86          entities.put("iquest", "\u00bf");
87          entities.put("Agrave", "\u00c0");
88          entities.put("Aacute", "\u00c1");
89          entities.put("Acirc", "\u00c2");
90          entities.put("Atilde", "\u00c3");
91          entities.put("Auml", "\u00c4");
92          entities.put("Aring", "\u00c5");
93          entities.put("AElig", "\u00c6");
94          entities.put("Ccedil", "\u00c7");
95          entities.put("Egrave", "\u00c8");
96          entities.put("Eacute", "\u00c9");
97          entities.put("Ecirc", "\u00ca");
98          entities.put("Euml", "\u00cb");
99          entities.put("Igrave", "\u00cc");
100         entities.put("Iacute", "\u00cd");
101         entities.put("Icirc", "\u00ce");
102         entities.put("Iuml", "\u00cf");
103         entities.put("ETH", "\u00d0");
104         entities.put("Ntilde", "\u00d1");
105         entities.put("Ograve", "\u00d2");
106         entities.put("Oacute", "\u00d3");
107         entities.put("Ocirc", "\u00d4");
108         entities.put("Otilde", "\u00d5");
109         entities.put("Ouml", "\u00d6");
110         entities.put("times", "\u00d7");
111         entities.put("Oslash", "\u00d8");
112         entities.put("Ugrave", "\u00d9");
113         entities.put("Uacute", "\u00da");
114         entities.put("Ucirc", "\u00db");
115         entities.put("Uuml", "\u00dc");
116         entities.put("Yacute", "\u00dd");
117         entities.put("THORN", "\u00de");
118         entities.put("szlig", "\u00df");
119         entities.put("agrave", "\u00e0");
120         entities.put("aacute", "\u00e1");
121         entities.put("acirc", "\u00e2");
122         entities.put("atilde", "\u00e3");
123         entities.put("auml", "\u00e4");
124         entities.put("aring", "\u00e5");
125         entities.put("aelig", "\u00e6");
126         entities.put("ccedil", "\u00e7");
127         entities.put("egrave", "\u00e8");
128         entities.put("eacute", "\u00e9");
129         entities.put("ecirc", "\u00ea");
130         entities.put("euml", "\u00eb");
131         entities.put("igrave", "\u00ec");
132         entities.put("iacute", "\u00ed");
133         entities.put("icirc", "\u00ee");
134         entities.put("iuml", "\u00ef");
135         entities.put("eth", "\u00f0");
136         entities.put("ntilde", "\u00f1");
137         entities.put("ograve", "\u00f2");
138         entities.put("oacute", "\u00f3");
139         entities.put("ocirc", "\u00f4");
140         entities.put("otilde", "\u00f5");
141         entities.put("ouml", "\u00f6");
142         entities.put("divide", "\u00f7");
143         entities.put("oslash", "\u00f8");
144         entities.put("ugrave", "\u00f9");
145         entities.put("uacute", "\u00fa");
146         entities.put("ucirc", "\u00fb");
147         entities.put("uuml", "\u00fc");
148         entities.put("yacute", "\u00fd");
149         entities.put("thorn", "\u00fe");
150         entities.put("yuml", "\u00ff");
151 
152         // ----------------------------------------------------------------------
153         // Special entities
154         // ----------------------------------------------------------------------
155 
156         entities.put("OElig", "\u0152");
157         entities.put("oelig", "\u0153");
158         entities.put("Scaron", "\u0160");
159         entities.put("scaron", "\u0161");
160         entities.put("Yuml", "\u0178");
161         entities.put("circ", "\u02c6");
162         entities.put("tilde", "\u02dc");
163         entities.put("ensp", "\u2002");
164         entities.put("emsp", "\u2003");
165         entities.put("thinsp", "\u2009");
166         entities.put("zwnj", "\u200c");
167         entities.put("zwj", "\u200d");
168         entities.put("lrm", "\u200e");
169         entities.put("rlm", "\u200f");
170         entities.put("ndash", "\u2013");
171         entities.put("mdash", "\u2014");
172         entities.put("lsquo", "\u2018");
173         entities.put("rsquo", "\u2019");
174         entities.put("sbquo", "\u201a");
175         entities.put("ldquo", "\u201c");
176         entities.put("rdquo", "\u201d");
177         entities.put("bdquo", "\u201e");
178         entities.put("dagger", "\u2020");
179         entities.put("Dagger", "\u2021");
180         entities.put("permil", "\u2030");
181         entities.put("lsaquo", "\u2039");
182         entities.put("rsaquo", "\u203a");
183         entities.put("euro", "\u20ac");
184 
185         // ----------------------------------------------------------------------
186         // Symbol entities
187         // ----------------------------------------------------------------------
188 
189         entities.put("fnof", "\u0192");
190         entities.put("Alpha", "\u0391");
191         entities.put("Beta", "\u0392");
192         entities.put("Gamma", "\u0393");
193         entities.put("Delta", "\u0394");
194         entities.put("Epsilon", "\u0395");
195         entities.put("Zeta", "\u0396");
196         entities.put("Eta", "\u0397");
197         entities.put("Theta", "\u0398");
198         entities.put("Iota", "\u0399");
199         entities.put("Kappa", "\u039a");
200         entities.put("Lambda", "\u039b");
201         entities.put("Mu", "\u039c");
202         entities.put("Nu", "\u039d");
203         entities.put("Xi", "\u039e");
204         entities.put("Omicron", "\u039f");
205         entities.put("Pi", "\u03a0");
206         entities.put("Rho", "\u03a1");
207         entities.put("Sigma", "\u03a3");
208         entities.put("Tau", "\u03a4");
209         entities.put("Upsilon", "\u03a5");
210         entities.put("Phi", "\u03a6");
211         entities.put("Chi", "\u03a7");
212         entities.put("Psi", "\u03a8");
213         entities.put("Omega", "\u03a9");
214         entities.put("alpha", "\u03b1");
215         entities.put("beta", "\u03b2");
216         entities.put("gamma", "\u03b3");
217         entities.put("delta", "\u03b4");
218         entities.put("epsilon", "\u03b5");
219         entities.put("zeta", "\u03b6");
220         entities.put("eta", "\u03b7");
221         entities.put("theta", "\u03b8");
222         entities.put("iota", "\u03b9");
223         entities.put("kappa", "\u03ba");
224         entities.put("lambda", "\u03bb");
225         entities.put("mu", "\u03bc");
226         entities.put("nu", "\u03bd");
227         entities.put("xi", "\u03be");
228         entities.put("omicron", "\u03bf");
229         entities.put("pi", "\u03c0");
230         entities.put("rho", "\u03c1");
231         entities.put("sigmaf", "\u03c2");
232         entities.put("sigma", "\u03c3");
233         entities.put("tau", "\u03c4");
234         entities.put("upsilon", "\u03c5");
235         entities.put("phi", "\u03c6");
236         entities.put("chi", "\u03c7");
237         entities.put("psi", "\u03c8");
238         entities.put("omega", "\u03c9");
239         entities.put("thetasym", "\u03d1");
240         entities.put("upsih", "\u03d2");
241         entities.put("piv", "\u03d6");
242         entities.put("bull", "\u2022");
243         entities.put("hellip", "\u2026");
244         entities.put("prime", "\u2032");
245         entities.put("Prime", "\u2033");
246         entities.put("oline", "\u203e");
247         entities.put("frasl", "\u2044");
248         entities.put("weierp", "\u2118");
249         entities.put("image", "\u2111");
250         entities.put("real", "\u211c");
251         entities.put("trade", "\u2122");
252         entities.put("alefsym", "\u2135");
253         entities.put("larr", "\u2190");
254         entities.put("uarr", "\u2191");
255         entities.put("rarr", "\u2192");
256         entities.put("darr", "\u2193");
257         entities.put("harr", "\u2194");
258         entities.put("crarr", "\u21b5");
259         entities.put("lArr", "\u21d0");
260         entities.put("uArr", "\u21d1");
261         entities.put("rArr", "\u21d2");
262         entities.put("dArr", "\u21d3");
263         entities.put("hArr", "\u21d4");
264         entities.put("forall", "\u2200");
265         entities.put("part", "\u2202");
266         entities.put("exist", "\u2203");
267         entities.put("empty", "\u2205");
268         entities.put("nabla", "\u2207");
269         entities.put("isin", "\u2208");
270         entities.put("notin", "\u2209");
271         entities.put("ni", "\u220b");
272         entities.put("prod", "\u220f");
273         entities.put("sum", "\u2211");
274         entities.put("minus", "\u2212");
275         entities.put("lowast", "\u2217");
276         entities.put("radic", "\u221a");
277         entities.put("prop", "\u221d");
278         entities.put("infin", "\u221e");
279         entities.put("ang", "\u2220");
280         entities.put("and", "\u2227");
281         entities.put("or", "\u2228");
282         entities.put("cap", "\u2229");
283         entities.put("cup", "\u222a");
284         entities.put("int", "\u222b");
285         entities.put("there4", "\u2234");
286         entities.put("sim", "\u223c");
287         entities.put("cong", "\u2245");
288         entities.put("asymp", "\u2248");
289         entities.put("ne", "\u2260");
290         entities.put("equiv", "\u2261");
291         entities.put("le", "\u2264");
292         entities.put("ge", "\u2265");
293         entities.put("sub", "\u2282");
294         entities.put("sup", "\u2283");
295         entities.put("nsub", "\u2284");
296         entities.put("sube", "\u2286");
297         entities.put("supe", "\u2287");
298         entities.put("oplus", "\u2295");
299         entities.put("otimes", "\u2297");
300         entities.put("perp", "\u22a5");
301         entities.put("sdot", "\u22c5");
302         entities.put("lceil", "\u2308");
303         entities.put("rceil", "\u2309");
304         entities.put("lfloor", "\u230a");
305         entities.put("rfloor", "\u230b");
306         entities.put("lang", "\u2329");
307         entities.put("rang", "\u232a");
308         entities.put("loz", "\u25ca");
309         entities.put("spades", "\u2660");
310         entities.put("clubs", "\u2663");
311         entities.put("hearts", "\u2665");
312         entities.put("diams", "\u2666");
313         DEFAULT_ENTITIES = Collections.unmodifiableMap(entities);
314     }
315 
316     private boolean addDefaultEntities = true;
317     private boolean addLocationInformation = true;
318 
319     private final ContentTransformer contentTransformer;
320 
321     public SettingsStaxReader() {
322         this((s, f) -> s);
323     }
324 
325     public SettingsStaxReader(ContentTransformer contentTransformer) {
326         this.contentTransformer = contentTransformer;
327     }
328 
329     /**
330      * Returns the state of the "add default entities" flag.
331      *
332      * @return boolean
333      */
334     public boolean getAddDefaultEntities() {
335         return addDefaultEntities;
336     } //-- boolean getAddDefaultEntities()
337 
338     /**
339      * Sets the state of the "add default entities" flag.
340      *
341      * @param addDefaultEntities a addDefaultEntities object.
342      */
343     public void setAddDefaultEntities(boolean addDefaultEntities) {
344         this.addDefaultEntities = addDefaultEntities;
345     } //-- void setAddDefaultEntities(boolean)
346 
347     /**
348      * Returns the state of the "add location information" flag.
349      *
350      * @return boolean
351      */
352     public boolean getAddLocationInformation() {
353         return addLocationInformation;
354     } //-- boolean getAddLocationInformation()
355 
356     /**
357      * Sets the state of the "add location information" flag.
358      *
359      * @param addLocationInformation a addLocationInformation object.
360      */
361     public void setAddLocationInformation(boolean addLocationInformation) {
362         this.addLocationInformation = addLocationInformation;
363     } //-- void setAddLocationInformation(boolean)
364 
365     public Settings read(Reader reader) throws XMLStreamException {
366         return read(reader, true, null);
367     }
368 
369     /**
370      * @param reader a reader object.
371      * @param strict a strict object.
372      * @throws XMLStreamException XMLStreamException if
373      * any.
374      * @return Settings
375      */
376     public Settings read(Reader reader, boolean strict, InputSource source) throws XMLStreamException {
377         XMLInputFactory factory = XMLInputFactory.newFactory();
378         factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
379         StreamSource streamSource = new StreamSource(reader, source != null ? source.getLocation() : null);
380         XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
381         return read(parser, strict, source);
382     } //-- Settings read(Reader, boolean)
383 
384     public Settings read(InputStream in) throws XMLStreamException {
385         return read(in, true, null);
386     }
387 
388     /**
389      * Method read.
390      *
391      * @param in a in object.
392      * @param strict a strict object.
393      * @throws XMLStreamException XMLStreamException if
394      * any.
395      * @return Settings
396      */
397     public Settings read(InputStream in, boolean strict, InputSource source) throws XMLStreamException {
398         XMLInputFactory factory = XMLInputFactory.newFactory();
399         factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
400         StreamSource streamSource = new StreamSource(in, source != null ? source.getLocation() : null);
401         XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
402         return read(parser, strict, source);
403     } //-- Settings read(InputStream, boolean)
404 
405     /**
406      * Method read.
407      *
408      * @param parser a parser object.
409      * @param strict a strict object.
410      * @throws XMLStreamException XMLStreamException if
411      * any.
412      * @return Settings
413      */
414     public Settings read(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
415         Settings settings = null;
416         int eventType = parser.getEventType();
417         boolean parsed = false;
418         while (eventType != XMLStreamReader.END_DOCUMENT) {
419             if (eventType == XMLStreamReader.START_ELEMENT) {
420                 if (strict && ! "settings".equals(parser.getLocalName())) {
421                     throw new XMLStreamException("Expected root element 'settings' but found '" + parser.getName() + "'", parser.getLocation(), null);
422                 } else if (parsed) {
423                     // fallback, already expected a XMLStreamException due to invalid XML
424                     throw new XMLStreamException("Duplicated tag: 'settings'", parser.getLocation(), null);
425                 }
426                 settings = parseSettings(parser, strict, source);
427                 parsed = true;
428             }
429             eventType = parser.next();
430         }
431         if (parsed) {
432             return settings;
433         }
434         throw new XMLStreamException("Expected root element 'settings' but found no element at all: invalid XML document", parser.getLocation(), null);
435     } //-- Settings read(XMLStreamReader, boolean)
436 
437     private TrackableBase parseTrackableBase(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
438         String tagName = parser.getLocalName();
439         TrackableBase.Builder trackableBase = TrackableBase.newBuilder(true);
440         if (addLocationInformation) {
441             trackableBase.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
442         }
443         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
444             String name = parser.getAttributeLocalName(i);
445             String ns = parser.getAttributeNamespace(i);
446             String value = parser.getAttributeValue(i);
447             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
448                 // just ignore attributes with non-default namespace (for example: xsi and xml)
449             } else {
450                 checkUnknownAttribute(parser, name, tagName, strict);
451             }
452         }
453         Set<String> parsed = new HashSet<>();
454         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
455             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
456             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
457             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
458             Map<Object, InputLocation> locations = null;
459             switch (childName) {
460                 default: {
461                     checkUnknownElement(parser, strict);
462                     break;
463                 }
464             }
465             if (addLocationInformation) {
466                 trackableBase.location(childName, new InputLocation(line, column, source, locations));
467             }
468         }
469         return trackableBase.build();
470     }
471 
472     private IdentifiableBase parseIdentifiableBase(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
473         String tagName = parser.getLocalName();
474         IdentifiableBase.Builder identifiableBase = IdentifiableBase.newBuilder(true);
475         if (addLocationInformation) {
476             identifiableBase.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
477         }
478         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
479             String name = parser.getAttributeLocalName(i);
480             String ns = parser.getAttributeNamespace(i);
481             String value = parser.getAttributeValue(i);
482             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
483                 // just ignore attributes with non-default namespace (for example: xsi and xml)
484             } else {
485                 checkUnknownAttribute(parser, name, tagName, strict);
486             }
487         }
488         Set<String> parsed = new HashSet<>();
489         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
490             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
491             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
492             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
493             Map<Object, InputLocation> locations = null;
494             switch (childName) {
495                 case "id": {
496                     identifiableBase.id(interpolatedTrimmed(nextText(parser, strict), "id"));
497                     break;
498                 }
499                 default: {
500                     checkUnknownElement(parser, strict);
501                     break;
502                 }
503             }
504             if (addLocationInformation) {
505                 identifiableBase.location(childName, new InputLocation(line, column, source, locations));
506             }
507         }
508         return identifiableBase.build();
509     }
510 
511     private Settings parseSettings(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
512         String tagName = parser.getLocalName();
513         Settings.Builder settings = Settings.newBuilder(true);
514         if (addLocationInformation) {
515             settings.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
516         }
517         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
518             String name = parser.getAttributeLocalName(i);
519             String ns = parser.getAttributeNamespace(i);
520             String value = parser.getAttributeValue(i);
521             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
522                 // just ignore attributes with non-default namespace (for example: xsi and xml)
523             } else if ("xmlns".equals(name)) {
524                 // ignore xmlns attribute in root class, which is a reserved attribute name
525             } else {
526                 checkUnknownAttribute(parser, name, tagName, strict);
527             }
528         }
529         Set<String> parsed = new HashSet<>();
530         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
531             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
532             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
533             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
534             Map<Object, InputLocation> locations = null;
535             switch (childName) {
536                 case "localRepository": {
537                     settings.localRepository(interpolatedTrimmed(nextText(parser, strict), "localRepository"));
538                     break;
539                 }
540                 case "interactiveMode": {
541                     settings.interactiveMode(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "interactiveMode"), "interactiveMode", parser, true));
542                     break;
543                 }
544                 case "usePluginRegistry": {
545                     settings.usePluginRegistry(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "usePluginRegistry"), "usePluginRegistry", parser, false));
546                     break;
547                 }
548                 case "offline": {
549                     settings.offline(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "offline"), "offline", parser, false));
550                     break;
551                 }
552                 case "proxies": {
553                     List<Proxy> proxies = new ArrayList<>();
554                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
555                         if ("proxy".equals(parser.getLocalName())) {
556                             proxies.add(parseProxy(parser, strict, source));
557                         } else {
558                             checkUnknownElement(parser, strict);
559                         }
560                     }
561                     settings.proxies(proxies);
562                     break;
563                 }
564                 case "servers": {
565                     List<Server> servers = new ArrayList<>();
566                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
567                         if ("server".equals(parser.getLocalName())) {
568                             servers.add(parseServer(parser, strict, source));
569                         } else {
570                             checkUnknownElement(parser, strict);
571                         }
572                     }
573                     settings.servers(servers);
574                     break;
575                 }
576                 case "mirrors": {
577                     List<Mirror> mirrors = new ArrayList<>();
578                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
579                         if ("mirror".equals(parser.getLocalName())) {
580                             mirrors.add(parseMirror(parser, strict, source));
581                         } else {
582                             checkUnknownElement(parser, strict);
583                         }
584                     }
585                     settings.mirrors(mirrors);
586                     break;
587                 }
588                 case "repositories": {
589                     List<Repository> repositories = new ArrayList<>();
590                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
591                         if ("repository".equals(parser.getLocalName())) {
592                             repositories.add(parseRepository(parser, strict, source));
593                         } else {
594                             checkUnknownElement(parser, strict);
595                         }
596                     }
597                     settings.repositories(repositories);
598                     break;
599                 }
600                 case "pluginRepositories": {
601                     List<Repository> pluginRepositories = new ArrayList<>();
602                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
603                         if ("pluginRepository".equals(parser.getLocalName())) {
604                             pluginRepositories.add(parseRepository(parser, strict, source));
605                         } else {
606                             checkUnknownElement(parser, strict);
607                         }
608                     }
609                     settings.pluginRepositories(pluginRepositories);
610                     break;
611                 }
612                 case "profiles": {
613                     List<Profile> profiles = new ArrayList<>();
614                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
615                         if ("profile".equals(parser.getLocalName())) {
616                             profiles.add(parseProfile(parser, strict, source));
617                         } else {
618                             checkUnknownElement(parser, strict);
619                         }
620                     }
621                     settings.profiles(profiles);
622                     break;
623                 }
624                 case "activeProfiles": {
625                     List<String> activeProfiles = new ArrayList<>();
626                     locations = new HashMap<>();
627                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
628                         if ("activeProfile".equals(parser.getLocalName())) {
629                             if (addLocationInformation) {
630                                 locations.put(Integer.valueOf(locations.size()), new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
631                             }
632                             activeProfiles.add(interpolatedTrimmed(nextText(parser, strict), "activeProfiles"));
633                         } else {
634                             checkUnknownElement(parser, strict);
635                         }
636                     }
637                     settings.activeProfiles(activeProfiles);
638                     break;
639                 }
640                 case "pluginGroups": {
641                     List<String> pluginGroups = new ArrayList<>();
642                     locations = new HashMap<>();
643                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
644                         if ("pluginGroup".equals(parser.getLocalName())) {
645                             if (addLocationInformation) {
646                                 locations.put(Integer.valueOf(locations.size()), new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
647                             }
648                             pluginGroups.add(interpolatedTrimmed(nextText(parser, strict), "pluginGroups"));
649                         } else {
650                             checkUnknownElement(parser, strict);
651                         }
652                     }
653                     settings.pluginGroups(pluginGroups);
654                     break;
655                 }
656                 default: {
657                     checkUnknownElement(parser, strict);
658                     break;
659                 }
660             }
661             if (addLocationInformation) {
662                 settings.location(childName, new InputLocation(line, column, source, locations));
663             }
664         }
665         settings.namespaceUri(parser.getNamespaceURI());
666         settings.modelEncoding(parser.getEncoding());
667         return settings.build();
668     }
669 
670     private Proxy parseProxy(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
671         String tagName = parser.getLocalName();
672         Proxy.Builder proxy = Proxy.newBuilder(true);
673         if (addLocationInformation) {
674             proxy.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
675         }
676         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
677             String name = parser.getAttributeLocalName(i);
678             String ns = parser.getAttributeNamespace(i);
679             String value = parser.getAttributeValue(i);
680             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
681                 // just ignore attributes with non-default namespace (for example: xsi and xml)
682             } else {
683                 checkUnknownAttribute(parser, name, tagName, strict);
684             }
685         }
686         Set<String> parsed = new HashSet<>();
687         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
688             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
689             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
690             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
691             Map<Object, InputLocation> locations = null;
692             switch (childName) {
693                 case "active": {
694                     proxy.activeString(interpolatedTrimmed(nextText(parser, strict), "active"));
695                     break;
696                 }
697                 case "protocol": {
698                     proxy.protocol(interpolatedTrimmed(nextText(parser, strict), "protocol"));
699                     break;
700                 }
701                 case "username": {
702                     proxy.username(interpolatedTrimmed(nextText(parser, strict), "username"));
703                     break;
704                 }
705                 case "password": {
706                     proxy.password(interpolatedTrimmed(nextText(parser, strict), "password"));
707                     break;
708                 }
709                 case "port": {
710                     proxy.portString(interpolatedTrimmed(nextText(parser, strict), "port"));
711                     break;
712                 }
713                 case "host": {
714                     proxy.host(interpolatedTrimmed(nextText(parser, strict), "host"));
715                     break;
716                 }
717                 case "nonProxyHosts": {
718                     proxy.nonProxyHosts(interpolatedTrimmed(nextText(parser, strict), "nonProxyHosts"));
719                     break;
720                 }
721                 case "id": {
722                     proxy.id(interpolatedTrimmed(nextText(parser, strict), "id"));
723                     break;
724                 }
725                 default: {
726                     checkUnknownElement(parser, strict);
727                     break;
728                 }
729             }
730             if (addLocationInformation) {
731                 proxy.location(childName, new InputLocation(line, column, source, locations));
732             }
733         }
734         return proxy.build();
735     }
736 
737     private Server parseServer(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
738         String tagName = parser.getLocalName();
739         Server.Builder server = Server.newBuilder(true);
740         if (addLocationInformation) {
741             server.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
742         }
743         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
744             String name = parser.getAttributeLocalName(i);
745             String ns = parser.getAttributeNamespace(i);
746             String value = parser.getAttributeValue(i);
747             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
748                 // just ignore attributes with non-default namespace (for example: xsi and xml)
749             } else {
750                 checkUnknownAttribute(parser, name, tagName, strict);
751             }
752         }
753         Set<String> parsed = new HashSet<>();
754         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
755             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
756             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
757             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
758             Map<Object, InputLocation> locations = null;
759             switch (childName) {
760                 case "username": {
761                     server.username(interpolatedTrimmed(nextText(parser, strict), "username"));
762                     break;
763                 }
764                 case "password": {
765                     server.password(interpolatedTrimmed(nextText(parser, strict), "password"));
766                     break;
767                 }
768                 case "privateKey": {
769                     server.privateKey(interpolatedTrimmed(nextText(parser, strict), "privateKey"));
770                     break;
771                 }
772                 case "passphrase": {
773                     server.passphrase(interpolatedTrimmed(nextText(parser, strict), "passphrase"));
774                     break;
775                 }
776                 case "filePermissions": {
777                     server.filePermissions(interpolatedTrimmed(nextText(parser, strict), "filePermissions"));
778                     break;
779                 }
780                 case "directoryPermissions": {
781                     server.directoryPermissions(interpolatedTrimmed(nextText(parser, strict), "directoryPermissions"));
782                     break;
783                 }
784                 case "configuration": {
785                     server.configuration(buildXmlNode(parser, source));
786                     break;
787                 }
788                 case "id": {
789                     server.id(interpolatedTrimmed(nextText(parser, strict), "id"));
790                     break;
791                 }
792                 default: {
793                     checkUnknownElement(parser, strict);
794                     break;
795                 }
796             }
797             if (addLocationInformation) {
798                 server.location(childName, new InputLocation(line, column, source, locations));
799             }
800         }
801         return server.build();
802     }
803 
804     private Mirror parseMirror(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
805         String tagName = parser.getLocalName();
806         Mirror.Builder mirror = Mirror.newBuilder(true);
807         if (addLocationInformation) {
808             mirror.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
809         }
810         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
811             String name = parser.getAttributeLocalName(i);
812             String ns = parser.getAttributeNamespace(i);
813             String value = parser.getAttributeValue(i);
814             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
815                 // just ignore attributes with non-default namespace (for example: xsi and xml)
816             } else {
817                 checkUnknownAttribute(parser, name, tagName, strict);
818             }
819         }
820         Set<String> parsed = new HashSet<>();
821         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
822             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
823             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
824             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
825             Map<Object, InputLocation> locations = null;
826             switch (childName) {
827                 case "mirrorOf": {
828                     mirror.mirrorOf(interpolatedTrimmed(nextText(parser, strict), "mirrorOf"));
829                     break;
830                 }
831                 case "name": {
832                     mirror.name(interpolatedTrimmed(nextText(parser, strict), "name"));
833                     break;
834                 }
835                 case "url": {
836                     mirror.url(interpolatedTrimmed(nextText(parser, strict), "url"));
837                     break;
838                 }
839                 case "layout": {
840                     mirror.layout(interpolatedTrimmed(nextText(parser, strict), "layout"));
841                     break;
842                 }
843                 case "mirrorOfLayouts": {
844                     mirror.mirrorOfLayouts(interpolatedTrimmed(nextText(parser, strict), "mirrorOfLayouts"));
845                     break;
846                 }
847                 case "blocked": {
848                     mirror.blocked(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "blocked"), "blocked", parser, false));
849                     break;
850                 }
851                 case "id": {
852                     mirror.id(interpolatedTrimmed(nextText(parser, strict), "id"));
853                     break;
854                 }
855                 default: {
856                     checkUnknownElement(parser, strict);
857                     break;
858                 }
859             }
860             if (addLocationInformation) {
861                 mirror.location(childName, new InputLocation(line, column, source, locations));
862             }
863         }
864         return mirror.build();
865     }
866 
867     private Profile parseProfile(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
868         String tagName = parser.getLocalName();
869         Profile.Builder profile = Profile.newBuilder(true);
870         if (addLocationInformation) {
871             profile.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
872         }
873         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
874             String name = parser.getAttributeLocalName(i);
875             String ns = parser.getAttributeNamespace(i);
876             String value = parser.getAttributeValue(i);
877             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
878                 // just ignore attributes with non-default namespace (for example: xsi and xml)
879             } else {
880                 checkUnknownAttribute(parser, name, tagName, strict);
881             }
882         }
883         Set<String> parsed = new HashSet<>();
884         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
885             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
886             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
887             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
888             Map<Object, InputLocation> locations = null;
889             switch (childName) {
890                 case "activation": {
891                     profile.activation(parseActivation(parser, strict, source));
892                     break;
893                 }
894                 case "properties": {
895                     Map<String, String> properties = new LinkedHashMap<>();
896                     locations = new HashMap<>();
897                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
898                         String key = parser.getLocalName();
899                         String value = nextText(parser, strict).trim();
900                         if (addLocationInformation) {
901                             locations.put(key, new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
902                         }
903                         properties.put(key, value);
904                     }
905                     profile.properties(properties);
906                     break;
907                 }
908                 case "repositories": {
909                     List<Repository> repositories = new ArrayList<>();
910                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
911                         if ("repository".equals(parser.getLocalName())) {
912                             repositories.add(parseRepository(parser, strict, source));
913                         } else {
914                             checkUnknownElement(parser, strict);
915                         }
916                     }
917                     profile.repositories(repositories);
918                     break;
919                 }
920                 case "pluginRepositories": {
921                     List<Repository> pluginRepositories = new ArrayList<>();
922                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
923                         if ("pluginRepository".equals(parser.getLocalName())) {
924                             pluginRepositories.add(parseRepository(parser, strict, source));
925                         } else {
926                             checkUnknownElement(parser, strict);
927                         }
928                     }
929                     profile.pluginRepositories(pluginRepositories);
930                     break;
931                 }
932                 case "id": {
933                     profile.id(interpolatedTrimmed(nextText(parser, strict), "id"));
934                     break;
935                 }
936                 default: {
937                     checkUnknownElement(parser, strict);
938                     break;
939                 }
940             }
941             if (addLocationInformation) {
942                 profile.location(childName, new InputLocation(line, column, source, locations));
943             }
944         }
945         return profile.build();
946     }
947 
948     private Activation parseActivation(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
949         String tagName = parser.getLocalName();
950         Activation.Builder activation = Activation.newBuilder(true);
951         if (addLocationInformation) {
952             activation.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
953         }
954         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
955             String name = parser.getAttributeLocalName(i);
956             String ns = parser.getAttributeNamespace(i);
957             String value = parser.getAttributeValue(i);
958             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
959                 // just ignore attributes with non-default namespace (for example: xsi and xml)
960             } else {
961                 checkUnknownAttribute(parser, name, tagName, strict);
962             }
963         }
964         Set<String> parsed = new HashSet<>();
965         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
966             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
967             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
968             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
969             Map<Object, InputLocation> locations = null;
970             switch (childName) {
971                 case "activeByDefault": {
972                     activation.activeByDefault(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "activeByDefault"), "activeByDefault", parser, false));
973                     break;
974                 }
975                 case "jdk": {
976                     activation.jdk(interpolatedTrimmed(nextText(parser, strict), "jdk"));
977                     break;
978                 }
979                 case "os": {
980                     activation.os(parseActivationOS(parser, strict, source));
981                     break;
982                 }
983                 case "property": {
984                     activation.property(parseActivationProperty(parser, strict, source));
985                     break;
986                 }
987                 case "file": {
988                     activation.file(parseActivationFile(parser, strict, source));
989                     break;
990                 }
991                 case "packaging": {
992                     activation.packaging(interpolatedTrimmed(nextText(parser, strict), "packaging"));
993                     break;
994                 }
995                 default: {
996                     checkUnknownElement(parser, strict);
997                     break;
998                 }
999             }
1000             if (addLocationInformation) {
1001                 activation.location(childName, new InputLocation(line, column, source, locations));
1002             }
1003         }
1004         return activation.build();
1005     }
1006 
1007     private RepositoryBase parseRepositoryBase(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1008         String tagName = parser.getLocalName();
1009         RepositoryBase.Builder repositoryBase = RepositoryBase.newBuilder(true);
1010         if (addLocationInformation) {
1011             repositoryBase.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1012         }
1013         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1014             String name = parser.getAttributeLocalName(i);
1015             String ns = parser.getAttributeNamespace(i);
1016             String value = parser.getAttributeValue(i);
1017             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1018                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1019             } else {
1020                 checkUnknownAttribute(parser, name, tagName, strict);
1021             }
1022         }
1023         Set<String> parsed = new HashSet<>();
1024         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1025             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1026             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1027             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1028             Map<Object, InputLocation> locations = null;
1029             switch (childName) {
1030                 case "name": {
1031                     repositoryBase.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1032                     break;
1033                 }
1034                 case "url": {
1035                     repositoryBase.url(interpolatedTrimmed(nextText(parser, strict), "url"));
1036                     break;
1037                 }
1038                 case "layout": {
1039                     repositoryBase.layout(interpolatedTrimmed(nextText(parser, strict), "layout"));
1040                     break;
1041                 }
1042                 case "id": {
1043                     repositoryBase.id(interpolatedTrimmed(nextText(parser, strict), "id"));
1044                     break;
1045                 }
1046                 default: {
1047                     checkUnknownElement(parser, strict);
1048                     break;
1049                 }
1050             }
1051             if (addLocationInformation) {
1052                 repositoryBase.location(childName, new InputLocation(line, column, source, locations));
1053             }
1054         }
1055         return repositoryBase.build();
1056     }
1057 
1058     private Repository parseRepository(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1059         String tagName = parser.getLocalName();
1060         Repository.Builder repository = Repository.newBuilder(true);
1061         if (addLocationInformation) {
1062             repository.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1063         }
1064         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1065             String name = parser.getAttributeLocalName(i);
1066             String ns = parser.getAttributeNamespace(i);
1067             String value = parser.getAttributeValue(i);
1068             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1069                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1070             } else {
1071                 checkUnknownAttribute(parser, name, tagName, strict);
1072             }
1073         }
1074         Set<String> parsed = new HashSet<>();
1075         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1076             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1077             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1078             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1079             Map<Object, InputLocation> locations = null;
1080             switch (childName) {
1081                 case "releases": {
1082                     repository.releases(parseRepositoryPolicy(parser, strict, source));
1083                     break;
1084                 }
1085                 case "snapshots": {
1086                     repository.snapshots(parseRepositoryPolicy(parser, strict, source));
1087                     break;
1088                 }
1089                 case "name": {
1090                     repository.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1091                     break;
1092                 }
1093                 case "url": {
1094                     repository.url(interpolatedTrimmed(nextText(parser, strict), "url"));
1095                     break;
1096                 }
1097                 case "layout": {
1098                     repository.layout(interpolatedTrimmed(nextText(parser, strict), "layout"));
1099                     break;
1100                 }
1101                 case "id": {
1102                     repository.id(interpolatedTrimmed(nextText(parser, strict), "id"));
1103                     break;
1104                 }
1105                 default: {
1106                     checkUnknownElement(parser, strict);
1107                     break;
1108                 }
1109             }
1110             if (addLocationInformation) {
1111                 repository.location(childName, new InputLocation(line, column, source, locations));
1112             }
1113         }
1114         return repository.build();
1115     }
1116 
1117     private RepositoryPolicy parseRepositoryPolicy(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1118         String tagName = parser.getLocalName();
1119         RepositoryPolicy.Builder repositoryPolicy = RepositoryPolicy.newBuilder(true);
1120         if (addLocationInformation) {
1121             repositoryPolicy.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1122         }
1123         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1124             String name = parser.getAttributeLocalName(i);
1125             String ns = parser.getAttributeNamespace(i);
1126             String value = parser.getAttributeValue(i);
1127             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1128                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1129             } else {
1130                 checkUnknownAttribute(parser, name, tagName, strict);
1131             }
1132         }
1133         Set<String> parsed = new HashSet<>();
1134         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1135             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1136             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1137             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1138             Map<Object, InputLocation> locations = null;
1139             switch (childName) {
1140                 case "enabled": {
1141                     repositoryPolicy.enabled(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "enabled"), "enabled", parser, true));
1142                     break;
1143                 }
1144                 case "updatePolicy": {
1145                     repositoryPolicy.updatePolicy(interpolatedTrimmed(nextText(parser, strict), "updatePolicy"));
1146                     break;
1147                 }
1148                 case "checksumPolicy": {
1149                     repositoryPolicy.checksumPolicy(interpolatedTrimmed(nextText(parser, strict), "checksumPolicy"));
1150                     break;
1151                 }
1152                 default: {
1153                     checkUnknownElement(parser, strict);
1154                     break;
1155                 }
1156             }
1157             if (addLocationInformation) {
1158                 repositoryPolicy.location(childName, new InputLocation(line, column, source, locations));
1159             }
1160         }
1161         return repositoryPolicy.build();
1162     }
1163 
1164     private ActivationProperty parseActivationProperty(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1165         String tagName = parser.getLocalName();
1166         ActivationProperty.Builder activationProperty = ActivationProperty.newBuilder(true);
1167         if (addLocationInformation) {
1168             activationProperty.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1169         }
1170         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1171             String name = parser.getAttributeLocalName(i);
1172             String ns = parser.getAttributeNamespace(i);
1173             String value = parser.getAttributeValue(i);
1174             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1175                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1176             } else {
1177                 checkUnknownAttribute(parser, name, tagName, strict);
1178             }
1179         }
1180         Set<String> parsed = new HashSet<>();
1181         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1182             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1183             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1184             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1185             Map<Object, InputLocation> locations = null;
1186             switch (childName) {
1187                 case "name": {
1188                     activationProperty.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1189                     break;
1190                 }
1191                 case "value": {
1192                     activationProperty.value(interpolatedTrimmed(nextText(parser, strict), "value"));
1193                     break;
1194                 }
1195                 default: {
1196                     checkUnknownElement(parser, strict);
1197                     break;
1198                 }
1199             }
1200             if (addLocationInformation) {
1201                 activationProperty.location(childName, new InputLocation(line, column, source, locations));
1202             }
1203         }
1204         return activationProperty.build();
1205     }
1206 
1207     private ActivationOS parseActivationOS(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1208         String tagName = parser.getLocalName();
1209         ActivationOS.Builder activationOS = ActivationOS.newBuilder(true);
1210         if (addLocationInformation) {
1211             activationOS.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1212         }
1213         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1214             String name = parser.getAttributeLocalName(i);
1215             String ns = parser.getAttributeNamespace(i);
1216             String value = parser.getAttributeValue(i);
1217             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1218                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1219             } else {
1220                 checkUnknownAttribute(parser, name, tagName, strict);
1221             }
1222         }
1223         Set<String> parsed = new HashSet<>();
1224         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1225             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1226             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1227             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1228             Map<Object, InputLocation> locations = null;
1229             switch (childName) {
1230                 case "name": {
1231                     activationOS.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1232                     break;
1233                 }
1234                 case "family": {
1235                     activationOS.family(interpolatedTrimmed(nextText(parser, strict), "family"));
1236                     break;
1237                 }
1238                 case "arch": {
1239                     activationOS.arch(interpolatedTrimmed(nextText(parser, strict), "arch"));
1240                     break;
1241                 }
1242                 case "version": {
1243                     activationOS.version(interpolatedTrimmed(nextText(parser, strict), "version"));
1244                     break;
1245                 }
1246                 default: {
1247                     checkUnknownElement(parser, strict);
1248                     break;
1249                 }
1250             }
1251             if (addLocationInformation) {
1252                 activationOS.location(childName, new InputLocation(line, column, source, locations));
1253             }
1254         }
1255         return activationOS.build();
1256     }
1257 
1258     private ActivationFile parseActivationFile(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1259         String tagName = parser.getLocalName();
1260         ActivationFile.Builder activationFile = ActivationFile.newBuilder(true);
1261         if (addLocationInformation) {
1262             activationFile.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1263         }
1264         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1265             String name = parser.getAttributeLocalName(i);
1266             String ns = parser.getAttributeNamespace(i);
1267             String value = parser.getAttributeValue(i);
1268             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1269                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1270             } else {
1271                 checkUnknownAttribute(parser, name, tagName, strict);
1272             }
1273         }
1274         Set<String> parsed = new HashSet<>();
1275         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1276             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1277             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1278             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1279             Map<Object, InputLocation> locations = null;
1280             switch (childName) {
1281                 case "missing": {
1282                     activationFile.missing(interpolatedTrimmed(nextText(parser, strict), "missing"));
1283                     break;
1284                 }
1285                 case "exists": {
1286                     activationFile.exists(interpolatedTrimmed(nextText(parser, strict), "exists"));
1287                     break;
1288                 }
1289                 default: {
1290                     checkUnknownElement(parser, strict);
1291                     break;
1292                 }
1293             }
1294             if (addLocationInformation) {
1295                 activationFile.location(childName, new InputLocation(line, column, source, locations));
1296             }
1297         }
1298         return activationFile.build();
1299     }
1300 
1301 
1302     private String checkDuplicate(String tagName, XMLStreamReader parser, Set<String> parsed) throws XMLStreamException {
1303         if (!parsed.add(tagName)) {
1304             throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
1305         }
1306         return tagName;
1307     }
1308 
1309     /**
1310      * Method checkUnknownAttribute.
1311      *
1312      * @param parser a parser object.
1313      * @param strict a strict object.
1314      * @param tagName a tagName object.
1315      * @param attribute a attribute object.
1316      * @throws XMLStreamException XMLStreamException if
1317      * any.
1318      * @throws IOException IOException if any.
1319      */
1320     private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException {
1321         // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
1322         if (strict) {
1323             throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
1324         }
1325     } //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)
1326 
1327     /**
1328      * Method checkUnknownElement.
1329      *
1330      * @param parser a parser object.
1331      * @param strict a strict object.
1332      * @throws XMLStreamException XMLStreamException if
1333      * any.
1334      * @throws IOException IOException if any.
1335      */
1336     private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException {
1337         if (strict) {
1338             throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
1339         }
1340 
1341         for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
1342             int eventType = nextTag(parser);
1343             if (eventType == XMLStreamReader.START_ELEMENT) {
1344                 unrecognizedTagCount++;
1345             } else if (eventType == XMLStreamReader.END_ELEMENT) {
1346                 unrecognizedTagCount--;
1347             }
1348         }
1349     } //-- void checkUnknownElement(XMLStreamReader, boolean)
1350 
1351     /**
1352      * Method getTrimmedValue.
1353      *
1354      * @param s a s object.
1355      * @return String
1356      */
1357     private String getTrimmedValue(String s) {
1358         if (s != null) {
1359             s = s.trim();
1360         }
1361         return s;
1362     } //-- String getTrimmedValue(String)
1363 
1364     /**
1365      * Method interpolatedTrimmed.
1366      *
1367      * @param value a value object.
1368      * @param context a context object.
1369      * @return String
1370      */
1371     private String interpolatedTrimmed(String value, String context) {
1372         return getTrimmedValue(contentTransformer.transform(value, context));
1373     } //-- String interpolatedTrimmed(String, String)
1374 
1375     /**
1376      * Method nextTag.
1377      *
1378      * @param parser a parser object.
1379      * @throws IOException IOException if any.
1380      * @throws XMLStreamException XMLStreamException if
1381      * any.
1382      * @return int
1383      */
1384     private int nextTag(XMLStreamReader parser) throws XMLStreamException {
1385         while (true) {
1386             int next = parser.next();
1387             switch (next) {
1388                 case XMLStreamReader.SPACE:
1389                 case XMLStreamReader.COMMENT:
1390                 case XMLStreamReader.PROCESSING_INSTRUCTION:
1391                 case XMLStreamReader.CDATA:
1392                 case XMLStreamReader.CHARACTERS:
1393                     continue;
1394                 case XMLStreamReader.START_ELEMENT:
1395                 case XMLStreamReader.END_ELEMENT:
1396                     return next;
1397             }
1398         }
1399     } //-- int nextTag(XMLStreamReader)
1400 
1401     private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
1402         int eventType = parser.getEventType();
1403         if (eventType != XMLStreamReader.START_ELEMENT) {
1404             throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
1405         }
1406         eventType = parser.next();
1407         StringBuilder result = new StringBuilder();
1408         while (true) {
1409             if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
1410                 result.append(parser.getText());
1411             } else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
1412                 String val = null;
1413                 if (strict) {
1414                     throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
1415                 } else if (addDefaultEntities) {
1416                     val = DEFAULT_ENTITIES.get(parser.getLocalName());
1417                 }
1418                 if (val != null) {
1419                     result.append(val);
1420                 } else {
1421                     result.append("&").append(parser.getLocalName()).append(";");
1422                 }
1423             } else if (eventType != XMLStreamReader.COMMENT) {
1424                 break;
1425             }
1426             eventType = parser.next();
1427         }
1428         if (eventType != XMLStreamReader.END_ELEMENT) {
1429             throw new XMLStreamException(
1430                 "TEXT must be immediately followed by END_ELEMENT and not " + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);
1431         }
1432         return result.toString();
1433     }
1434 
1435     private XmlNode buildXmlNode(XMLStreamReader parser, InputSource source) throws XMLStreamException {
1436         return XmlNodeStaxBuilder.build(parser,
1437                 addLocationInformation
1438                         ? p -> new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source)
1439                         : null);
1440     }
1441 
1442     /**
1443      * Method getBooleanValue.
1444      *
1445      * @param s a s object.
1446      * @param defaultValue a defaultValue object.
1447      * @param parser a parser object.
1448      * @param attribute a attribute object.
1449      * @throws XMLStreamException XMLStreamException if
1450      * any.
1451      * @return boolean
1452      */
1453     private boolean getBooleanValue(String s, String attribute, XMLStreamReader parser, boolean defaultValue) throws XMLStreamException {
1454         if (s != null && s.length() != 0) {
1455             return Boolean.valueOf(s).booleanValue();
1456         }
1457         return defaultValue;
1458     } //-- boolean getBooleanValue(String, String, XMLStreamReader, String)
1459 
1460     public static interface ContentTransformer {
1461         /**
1462          * Interpolate the value read from the xpp3 document
1463          * @param source The source value
1464          * @param fieldName A description of the field being interpolated. The implementation may use this to
1465          *                           log stuff.
1466          * @return The interpolated value.
1467          */
1468         String transform(String source, String fieldName);
1469     }
1470 
1471 }