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.XmlNodeBuilder;
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 = new com.ctc.wstx.stax.WstxInputFactory();
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 = new com.ctc.wstx.stax.WstxInputFactory();
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                 default: {
992                     checkUnknownElement(parser, strict);
993                     break;
994                 }
995             }
996             if (addLocationInformation) {
997                 activation.location(childName, new InputLocation(line, column, source, locations));
998             }
999         }
1000         return activation.build();
1001     }
1002 
1003     private RepositoryBase parseRepositoryBase(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1004         String tagName = parser.getLocalName();
1005         RepositoryBase.Builder repositoryBase = RepositoryBase.newBuilder(true);
1006         if (addLocationInformation) {
1007             repositoryBase.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1008         }
1009         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1010             String name = parser.getAttributeLocalName(i);
1011             String ns = parser.getAttributeNamespace(i);
1012             String value = parser.getAttributeValue(i);
1013             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1014                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1015             } else {
1016                 checkUnknownAttribute(parser, name, tagName, strict);
1017             }
1018         }
1019         Set<String> parsed = new HashSet<>();
1020         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1021             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1022             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1023             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1024             Map<Object, InputLocation> locations = null;
1025             switch (childName) {
1026                 case "name": {
1027                     repositoryBase.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1028                     break;
1029                 }
1030                 case "url": {
1031                     repositoryBase.url(interpolatedTrimmed(nextText(parser, strict), "url"));
1032                     break;
1033                 }
1034                 case "layout": {
1035                     repositoryBase.layout(interpolatedTrimmed(nextText(parser, strict), "layout"));
1036                     break;
1037                 }
1038                 case "id": {
1039                     repositoryBase.id(interpolatedTrimmed(nextText(parser, strict), "id"));
1040                     break;
1041                 }
1042                 default: {
1043                     checkUnknownElement(parser, strict);
1044                     break;
1045                 }
1046             }
1047             if (addLocationInformation) {
1048                 repositoryBase.location(childName, new InputLocation(line, column, source, locations));
1049             }
1050         }
1051         return repositoryBase.build();
1052     }
1053 
1054     private Repository parseRepository(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1055         String tagName = parser.getLocalName();
1056         Repository.Builder repository = Repository.newBuilder(true);
1057         if (addLocationInformation) {
1058             repository.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1059         }
1060         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1061             String name = parser.getAttributeLocalName(i);
1062             String ns = parser.getAttributeNamespace(i);
1063             String value = parser.getAttributeValue(i);
1064             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1065                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1066             } else {
1067                 checkUnknownAttribute(parser, name, tagName, strict);
1068             }
1069         }
1070         Set<String> parsed = new HashSet<>();
1071         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1072             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1073             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1074             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1075             Map<Object, InputLocation> locations = null;
1076             switch (childName) {
1077                 case "releases": {
1078                     repository.releases(parseRepositoryPolicy(parser, strict, source));
1079                     break;
1080                 }
1081                 case "snapshots": {
1082                     repository.snapshots(parseRepositoryPolicy(parser, strict, source));
1083                     break;
1084                 }
1085                 case "name": {
1086                     repository.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1087                     break;
1088                 }
1089                 case "url": {
1090                     repository.url(interpolatedTrimmed(nextText(parser, strict), "url"));
1091                     break;
1092                 }
1093                 case "layout": {
1094                     repository.layout(interpolatedTrimmed(nextText(parser, strict), "layout"));
1095                     break;
1096                 }
1097                 case "id": {
1098                     repository.id(interpolatedTrimmed(nextText(parser, strict), "id"));
1099                     break;
1100                 }
1101                 default: {
1102                     checkUnknownElement(parser, strict);
1103                     break;
1104                 }
1105             }
1106             if (addLocationInformation) {
1107                 repository.location(childName, new InputLocation(line, column, source, locations));
1108             }
1109         }
1110         return repository.build();
1111     }
1112 
1113     private RepositoryPolicy parseRepositoryPolicy(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1114         String tagName = parser.getLocalName();
1115         RepositoryPolicy.Builder repositoryPolicy = RepositoryPolicy.newBuilder(true);
1116         if (addLocationInformation) {
1117             repositoryPolicy.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1118         }
1119         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1120             String name = parser.getAttributeLocalName(i);
1121             String ns = parser.getAttributeNamespace(i);
1122             String value = parser.getAttributeValue(i);
1123             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1124                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1125             } else {
1126                 checkUnknownAttribute(parser, name, tagName, strict);
1127             }
1128         }
1129         Set<String> parsed = new HashSet<>();
1130         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1131             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1132             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1133             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1134             Map<Object, InputLocation> locations = null;
1135             switch (childName) {
1136                 case "enabled": {
1137                     repositoryPolicy.enabled(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "enabled"), "enabled", parser, true));
1138                     break;
1139                 }
1140                 case "updatePolicy": {
1141                     repositoryPolicy.updatePolicy(interpolatedTrimmed(nextText(parser, strict), "updatePolicy"));
1142                     break;
1143                 }
1144                 case "checksumPolicy": {
1145                     repositoryPolicy.checksumPolicy(interpolatedTrimmed(nextText(parser, strict), "checksumPolicy"));
1146                     break;
1147                 }
1148                 default: {
1149                     checkUnknownElement(parser, strict);
1150                     break;
1151                 }
1152             }
1153             if (addLocationInformation) {
1154                 repositoryPolicy.location(childName, new InputLocation(line, column, source, locations));
1155             }
1156         }
1157         return repositoryPolicy.build();
1158     }
1159 
1160     private ActivationProperty parseActivationProperty(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1161         String tagName = parser.getLocalName();
1162         ActivationProperty.Builder activationProperty = ActivationProperty.newBuilder(true);
1163         if (addLocationInformation) {
1164             activationProperty.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1165         }
1166         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1167             String name = parser.getAttributeLocalName(i);
1168             String ns = parser.getAttributeNamespace(i);
1169             String value = parser.getAttributeValue(i);
1170             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1171                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1172             } else {
1173                 checkUnknownAttribute(parser, name, tagName, strict);
1174             }
1175         }
1176         Set<String> parsed = new HashSet<>();
1177         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1178             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1179             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1180             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1181             Map<Object, InputLocation> locations = null;
1182             switch (childName) {
1183                 case "name": {
1184                     activationProperty.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1185                     break;
1186                 }
1187                 case "value": {
1188                     activationProperty.value(interpolatedTrimmed(nextText(parser, strict), "value"));
1189                     break;
1190                 }
1191                 default: {
1192                     checkUnknownElement(parser, strict);
1193                     break;
1194                 }
1195             }
1196             if (addLocationInformation) {
1197                 activationProperty.location(childName, new InputLocation(line, column, source, locations));
1198             }
1199         }
1200         return activationProperty.build();
1201     }
1202 
1203     private ActivationOS parseActivationOS(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1204         String tagName = parser.getLocalName();
1205         ActivationOS.Builder activationOS = ActivationOS.newBuilder(true);
1206         if (addLocationInformation) {
1207             activationOS.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1208         }
1209         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1210             String name = parser.getAttributeLocalName(i);
1211             String ns = parser.getAttributeNamespace(i);
1212             String value = parser.getAttributeValue(i);
1213             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1214                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1215             } else {
1216                 checkUnknownAttribute(parser, name, tagName, strict);
1217             }
1218         }
1219         Set<String> parsed = new HashSet<>();
1220         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1221             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1222             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1223             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1224             Map<Object, InputLocation> locations = null;
1225             switch (childName) {
1226                 case "name": {
1227                     activationOS.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1228                     break;
1229                 }
1230                 case "family": {
1231                     activationOS.family(interpolatedTrimmed(nextText(parser, strict), "family"));
1232                     break;
1233                 }
1234                 case "arch": {
1235                     activationOS.arch(interpolatedTrimmed(nextText(parser, strict), "arch"));
1236                     break;
1237                 }
1238                 case "version": {
1239                     activationOS.version(interpolatedTrimmed(nextText(parser, strict), "version"));
1240                     break;
1241                 }
1242                 default: {
1243                     checkUnknownElement(parser, strict);
1244                     break;
1245                 }
1246             }
1247             if (addLocationInformation) {
1248                 activationOS.location(childName, new InputLocation(line, column, source, locations));
1249             }
1250         }
1251         return activationOS.build();
1252     }
1253 
1254     private ActivationFile parseActivationFile(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1255         String tagName = parser.getLocalName();
1256         ActivationFile.Builder activationFile = ActivationFile.newBuilder(true);
1257         if (addLocationInformation) {
1258             activationFile.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1259         }
1260         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1261             String name = parser.getAttributeLocalName(i);
1262             String ns = parser.getAttributeNamespace(i);
1263             String value = parser.getAttributeValue(i);
1264             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1265                 // just ignore attributes with non-default namespace (for example: xsi and xml)
1266             } else {
1267                 checkUnknownAttribute(parser, name, tagName, strict);
1268             }
1269         }
1270         Set<String> parsed = new HashSet<>();
1271         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1272             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1273             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1274             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1275             Map<Object, InputLocation> locations = null;
1276             switch (childName) {
1277                 case "missing": {
1278                     activationFile.missing(interpolatedTrimmed(nextText(parser, strict), "missing"));
1279                     break;
1280                 }
1281                 case "exists": {
1282                     activationFile.exists(interpolatedTrimmed(nextText(parser, strict), "exists"));
1283                     break;
1284                 }
1285                 default: {
1286                     checkUnknownElement(parser, strict);
1287                     break;
1288                 }
1289             }
1290             if (addLocationInformation) {
1291                 activationFile.location(childName, new InputLocation(line, column, source, locations));
1292             }
1293         }
1294         return activationFile.build();
1295     }
1296 
1297 
1298     private String checkDuplicate(String tagName, XMLStreamReader parser, Set<String> parsed) throws XMLStreamException {
1299         if (!parsed.add(tagName)) {
1300             throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
1301         }
1302         return tagName;
1303     }
1304 
1305     /**
1306      * Method checkUnknownAttribute.
1307      *
1308      * @param parser a parser object.
1309      * @param strict a strict object.
1310      * @param tagName a tagName object.
1311      * @param attribute a attribute object.
1312      * @throws XMLStreamException XMLStreamException if
1313      * any.
1314      * @throws IOException IOException if any.
1315      */
1316     private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException {
1317         // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
1318         if (strict) {
1319             throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
1320         }
1321     } //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)
1322 
1323     /**
1324      * Method checkUnknownElement.
1325      *
1326      * @param parser a parser object.
1327      * @param strict a strict object.
1328      * @throws XMLStreamException XMLStreamException if
1329      * any.
1330      * @throws IOException IOException if any.
1331      */
1332     private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException {
1333         if (strict) {
1334             throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
1335         }
1336 
1337         for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
1338             int eventType = nextTag(parser);
1339             if (eventType == XMLStreamReader.START_ELEMENT) {
1340                 unrecognizedTagCount++;
1341             } else if (eventType == XMLStreamReader.END_ELEMENT) {
1342                 unrecognizedTagCount--;
1343             }
1344         }
1345     } //-- void checkUnknownElement(XMLStreamReader, boolean)
1346 
1347     /**
1348      * Method getTrimmedValue.
1349      *
1350      * @param s a s object.
1351      * @return String
1352      */
1353     private String getTrimmedValue(String s) {
1354         if (s != null) {
1355             s = s.trim();
1356         }
1357         return s;
1358     } //-- String getTrimmedValue(String)
1359 
1360     /**
1361      * Method interpolatedTrimmed.
1362      *
1363      * @param value a value object.
1364      * @param context a context object.
1365      * @return String
1366      */
1367     private String interpolatedTrimmed(String value, String context) {
1368         return getTrimmedValue(contentTransformer.transform(value, context));
1369     } //-- String interpolatedTrimmed(String, String)
1370 
1371     /**
1372      * Method nextTag.
1373      *
1374      * @param parser a parser object.
1375      * @throws IOException IOException if any.
1376      * @throws XMLStreamException XMLStreamException if
1377      * any.
1378      * @return int
1379      */
1380     private int nextTag(XMLStreamReader parser) throws XMLStreamException {
1381         while (true) {
1382             int next = parser.next();
1383             switch (next) {
1384                 case XMLStreamReader.SPACE:
1385                 case XMLStreamReader.COMMENT:
1386                 case XMLStreamReader.PROCESSING_INSTRUCTION:
1387                 case XMLStreamReader.CDATA:
1388                 case XMLStreamReader.CHARACTERS:
1389                     continue;
1390                 case XMLStreamReader.START_ELEMENT:
1391                 case XMLStreamReader.END_ELEMENT:
1392                     return next;
1393             }
1394         }
1395     } //-- int nextTag(XMLStreamReader)
1396 
1397     private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
1398         int eventType = parser.getEventType();
1399         if (eventType != XMLStreamReader.START_ELEMENT) {
1400             throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
1401         }
1402         eventType = parser.next();
1403         StringBuilder result = new StringBuilder();
1404         while (true) {
1405             if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
1406                 result.append(parser.getText());
1407             } else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
1408                 String val = null;
1409                 if (strict) {
1410                     throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
1411                 } else if (addDefaultEntities) {
1412                     val = DEFAULT_ENTITIES.get(parser.getLocalName());
1413                 }
1414                 if (val != null) {
1415                     result.append(val);
1416                 } else {
1417                     result.append("&").append(parser.getLocalName()).append(";");
1418                 }
1419             } else if (eventType != XMLStreamReader.COMMENT) {
1420                 break;
1421             }
1422             eventType = parser.next();
1423         }
1424         if (eventType != XMLStreamReader.END_ELEMENT) {
1425             throw new XMLStreamException(
1426                 "TEXT must be immediately followed by END_ELEMENT and not " + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);
1427         }
1428         return result.toString();
1429     }
1430 
1431     private XmlNode buildXmlNode(XMLStreamReader parser, InputSource source) throws XMLStreamException {
1432         return XmlNodeBuilder.build(parser,
1433                 addLocationInformation
1434                         ? p -> new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source)
1435                         : null);
1436     }
1437 
1438     /**
1439      * Method getBooleanValue.
1440      *
1441      * @param s a s object.
1442      * @param defaultValue a defaultValue object.
1443      * @param parser a parser object.
1444      * @param attribute a attribute object.
1445      * @throws XMLStreamException XMLStreamException if
1446      * any.
1447      * @return boolean
1448      */
1449     private boolean getBooleanValue(String s, String attribute, XMLStreamReader parser, boolean defaultValue) throws XMLStreamException {
1450         if (s != null && s.length() != 0) {
1451             return Boolean.valueOf(s).booleanValue();
1452         }
1453         return defaultValue;
1454     } //-- boolean getBooleanValue(String, String, XMLStreamReader, String)
1455 
1456     public static interface ContentTransformer {
1457         /**
1458          * Interpolate the value read from the xpp3 document
1459          * @param source The source value
1460          * @param fieldName A description of the field being interpolated. The implementation may use this to
1461          *                           log stuff.
1462          * @return The interpolated value.
1463          */
1464         String transform(String source, String fieldName);
1465     }
1466 
1467 }