1
2
3
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
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
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 static class InputFactoryHolder {
317 static XMLInputFactory XML_INPUT_FACTORY;
318 static {
319 XMLInputFactory factory = XMLInputFactory.newFactory();
320 factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
321 XML_INPUT_FACTORY = factory;
322 }
323 }
324
325 private boolean addDefaultEntities = true;
326 private boolean addLocationInformation = true;
327
328 private final ContentTransformer contentTransformer;
329
330 public SettingsStaxReader() {
331 this((s, f) -> s);
332 }
333
334 public SettingsStaxReader(ContentTransformer contentTransformer) {
335 this.contentTransformer = contentTransformer;
336 }
337
338
339
340
341
342
343 public XMLInputFactory getXMLInputFactory() {
344 return InputFactoryHolder.XML_INPUT_FACTORY;
345 }
346
347
348
349
350
351
352 public boolean getAddDefaultEntities() {
353 return addDefaultEntities;
354 }
355
356
357
358
359
360
361 public void setAddDefaultEntities(boolean addDefaultEntities) {
362 this.addDefaultEntities = addDefaultEntities;
363 }
364
365
366
367
368
369
370 public boolean getAddLocationInformation() {
371 return addLocationInformation;
372 }
373
374
375
376
377
378
379 public void setAddLocationInformation(boolean addLocationInformation) {
380 this.addLocationInformation = addLocationInformation;
381 }
382
383 public Settings read(Reader reader) throws XMLStreamException {
384 return read(reader, true, null);
385 }
386
387
388
389
390
391
392
393
394 public Settings read(Reader reader, boolean strict, InputSource source) throws XMLStreamException {
395 StreamSource streamSource = new StreamSource(reader, source != null ? source.getLocation() : null);
396 XMLInputFactory factory = getXMLInputFactory();
397 XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
398 return read(parser, strict, source);
399 }
400
401 public Settings read(InputStream in) throws XMLStreamException {
402 return read(in, true, null);
403 }
404
405
406
407
408
409
410
411
412
413
414 public Settings read(InputStream in, boolean strict, InputSource source) throws XMLStreamException {
415 StreamSource streamSource = new StreamSource(in, source != null ? source.getLocation() : null);
416 XMLInputFactory factory = getXMLInputFactory();
417 XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
418 return read(parser, strict, source);
419 }
420
421
422
423
424
425
426
427
428
429
430 public Settings read(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
431 Settings settings = null;
432 int eventType = parser.getEventType();
433 boolean parsed = false;
434 while (eventType != XMLStreamReader.END_DOCUMENT) {
435 if (eventType == XMLStreamReader.START_ELEMENT) {
436 if (strict && ! "settings".equals(parser.getLocalName())) {
437 throw new XMLStreamException("Expected root element 'settings' but found '" + parser.getName() + "'", parser.getLocation(), null);
438 } else if (parsed) {
439
440 throw new XMLStreamException("Duplicated tag: 'settings'", parser.getLocation(), null);
441 }
442 settings = parseSettings(parser, strict, source);
443 parsed = true;
444 }
445 eventType = parser.next();
446 }
447 if (parsed) {
448 return settings;
449 }
450 throw new XMLStreamException("Expected root element 'settings' but found no element at all: invalid XML document", parser.getLocation(), null);
451 }
452
453 private TrackableBase parseTrackableBase(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
454 String tagName = parser.getLocalName();
455 TrackableBase.Builder trackableBase = TrackableBase.newBuilder(true);
456 if (addLocationInformation) {
457 trackableBase.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
458 }
459 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
460 String name = parser.getAttributeLocalName(i);
461 String ns = parser.getAttributeNamespace(i);
462 String value = parser.getAttributeValue(i);
463 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
464
465 } else {
466 checkUnknownAttribute(parser, name, tagName, strict);
467 }
468 }
469 Set<String> parsed = new HashSet<>();
470 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
471 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
472 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
473 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
474 Map<Object, InputLocation> locations = null;
475 switch (childName) {
476 default: {
477 checkUnknownElement(parser, strict);
478 break;
479 }
480 }
481 if (addLocationInformation) {
482 trackableBase.location(childName, new InputLocation(line, column, source, locations));
483 }
484 }
485 return trackableBase.build();
486 }
487
488 private IdentifiableBase parseIdentifiableBase(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
489 String tagName = parser.getLocalName();
490 IdentifiableBase.Builder identifiableBase = IdentifiableBase.newBuilder(true);
491 if (addLocationInformation) {
492 identifiableBase.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
493 }
494 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
495 String name = parser.getAttributeLocalName(i);
496 String ns = parser.getAttributeNamespace(i);
497 String value = parser.getAttributeValue(i);
498 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
499
500 } else {
501 checkUnknownAttribute(parser, name, tagName, strict);
502 }
503 }
504 Set<String> parsed = new HashSet<>();
505 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
506 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
507 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
508 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
509 Map<Object, InputLocation> locations = null;
510 switch (childName) {
511 case "id": {
512 identifiableBase.id(interpolatedTrimmed(nextText(parser, strict), "id"));
513 break;
514 }
515 default: {
516 checkUnknownElement(parser, strict);
517 break;
518 }
519 }
520 if (addLocationInformation) {
521 identifiableBase.location(childName, new InputLocation(line, column, source, locations));
522 }
523 }
524 return identifiableBase.build();
525 }
526
527 private Settings parseSettings(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
528 String tagName = parser.getLocalName();
529 Settings.Builder settings = Settings.newBuilder(true);
530 if (addLocationInformation) {
531 settings.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
532 }
533 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
534 String name = parser.getAttributeLocalName(i);
535 String ns = parser.getAttributeNamespace(i);
536 String value = parser.getAttributeValue(i);
537 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
538
539 } else if ("xmlns".equals(name)) {
540
541 } else {
542 checkUnknownAttribute(parser, name, tagName, strict);
543 }
544 }
545 Set<String> parsed = new HashSet<>();
546 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
547 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
548 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
549 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
550 Map<Object, InputLocation> locations = null;
551 switch (childName) {
552 case "localRepository": {
553 settings.localRepository(interpolatedTrimmed(nextText(parser, strict), "localRepository"));
554 break;
555 }
556 case "interactiveMode": {
557 settings.interactiveMode(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "interactiveMode"), "interactiveMode", parser, true));
558 break;
559 }
560 case "usePluginRegistry": {
561 settings.usePluginRegistry(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "usePluginRegistry"), "usePluginRegistry", parser, false));
562 break;
563 }
564 case "offline": {
565 settings.offline(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "offline"), "offline", parser, false));
566 break;
567 }
568 case "proxies": {
569 List<Proxy> proxies = new ArrayList<>();
570 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
571 if ("proxy".equals(parser.getLocalName())) {
572 proxies.add(parseProxy(parser, strict, source));
573 } else {
574 checkUnknownElement(parser, strict);
575 }
576 }
577 settings.proxies(proxies);
578 break;
579 }
580 case "servers": {
581 List<Server> servers = new ArrayList<>();
582 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
583 if ("server".equals(parser.getLocalName())) {
584 servers.add(parseServer(parser, strict, source));
585 } else {
586 checkUnknownElement(parser, strict);
587 }
588 }
589 settings.servers(servers);
590 break;
591 }
592 case "mirrors": {
593 List<Mirror> mirrors = new ArrayList<>();
594 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
595 if ("mirror".equals(parser.getLocalName())) {
596 mirrors.add(parseMirror(parser, strict, source));
597 } else {
598 checkUnknownElement(parser, strict);
599 }
600 }
601 settings.mirrors(mirrors);
602 break;
603 }
604 case "repositories": {
605 List<Repository> repositories = new ArrayList<>();
606 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
607 if ("repository".equals(parser.getLocalName())) {
608 repositories.add(parseRepository(parser, strict, source));
609 } else {
610 checkUnknownElement(parser, strict);
611 }
612 }
613 settings.repositories(repositories);
614 break;
615 }
616 case "pluginRepositories": {
617 List<Repository> pluginRepositories = new ArrayList<>();
618 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
619 if ("pluginRepository".equals(parser.getLocalName())) {
620 pluginRepositories.add(parseRepository(parser, strict, source));
621 } else {
622 checkUnknownElement(parser, strict);
623 }
624 }
625 settings.pluginRepositories(pluginRepositories);
626 break;
627 }
628 case "profiles": {
629 List<Profile> profiles = new ArrayList<>();
630 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
631 if ("profile".equals(parser.getLocalName())) {
632 profiles.add(parseProfile(parser, strict, source));
633 } else {
634 checkUnknownElement(parser, strict);
635 }
636 }
637 settings.profiles(profiles);
638 break;
639 }
640 case "activeProfiles": {
641 List<String> activeProfiles = new ArrayList<>();
642 locations = new HashMap<>();
643 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
644 if ("activeProfile".equals(parser.getLocalName())) {
645 if (addLocationInformation) {
646 locations.put(Integer.valueOf(locations.size()), new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
647 }
648 activeProfiles.add(interpolatedTrimmed(nextText(parser, strict), "activeProfiles"));
649 } else {
650 checkUnknownElement(parser, strict);
651 }
652 }
653 settings.activeProfiles(activeProfiles);
654 break;
655 }
656 case "pluginGroups": {
657 List<String> pluginGroups = new ArrayList<>();
658 locations = new HashMap<>();
659 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
660 if ("pluginGroup".equals(parser.getLocalName())) {
661 if (addLocationInformation) {
662 locations.put(Integer.valueOf(locations.size()), new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
663 }
664 pluginGroups.add(interpolatedTrimmed(nextText(parser, strict), "pluginGroups"));
665 } else {
666 checkUnknownElement(parser, strict);
667 }
668 }
669 settings.pluginGroups(pluginGroups);
670 break;
671 }
672 default: {
673 checkUnknownElement(parser, strict);
674 break;
675 }
676 }
677 if (addLocationInformation) {
678 settings.location(childName, new InputLocation(line, column, source, locations));
679 }
680 }
681 settings.namespaceUri(parser.getNamespaceURI());
682 settings.modelEncoding(parser.getEncoding());
683 return settings.build();
684 }
685
686 private Proxy parseProxy(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
687 String tagName = parser.getLocalName();
688 Proxy.Builder proxy = Proxy.newBuilder(true);
689 if (addLocationInformation) {
690 proxy.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
691 }
692 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
693 String name = parser.getAttributeLocalName(i);
694 String ns = parser.getAttributeNamespace(i);
695 String value = parser.getAttributeValue(i);
696 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
697
698 } else {
699 checkUnknownAttribute(parser, name, tagName, strict);
700 }
701 }
702 Set<String> parsed = new HashSet<>();
703 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
704 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
705 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
706 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
707 Map<Object, InputLocation> locations = null;
708 switch (childName) {
709 case "active": {
710 proxy.activeString(interpolatedTrimmed(nextText(parser, strict), "active"));
711 break;
712 }
713 case "protocol": {
714 proxy.protocol(interpolatedTrimmed(nextText(parser, strict), "protocol"));
715 break;
716 }
717 case "username": {
718 proxy.username(interpolatedTrimmed(nextText(parser, strict), "username"));
719 break;
720 }
721 case "password": {
722 proxy.password(interpolatedTrimmed(nextText(parser, strict), "password"));
723 break;
724 }
725 case "port": {
726 proxy.portString(interpolatedTrimmed(nextText(parser, strict), "port"));
727 break;
728 }
729 case "host": {
730 proxy.host(interpolatedTrimmed(nextText(parser, strict), "host"));
731 break;
732 }
733 case "nonProxyHosts": {
734 proxy.nonProxyHosts(interpolatedTrimmed(nextText(parser, strict), "nonProxyHosts"));
735 break;
736 }
737 case "id": {
738 proxy.id(interpolatedTrimmed(nextText(parser, strict), "id"));
739 break;
740 }
741 default: {
742 checkUnknownElement(parser, strict);
743 break;
744 }
745 }
746 if (addLocationInformation) {
747 proxy.location(childName, new InputLocation(line, column, source, locations));
748 }
749 }
750 return proxy.build();
751 }
752
753 private Server parseServer(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
754 String tagName = parser.getLocalName();
755 Server.Builder server = Server.newBuilder(true);
756 if (addLocationInformation) {
757 server.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
758 }
759 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
760 String name = parser.getAttributeLocalName(i);
761 String ns = parser.getAttributeNamespace(i);
762 String value = parser.getAttributeValue(i);
763 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
764
765 } else {
766 checkUnknownAttribute(parser, name, tagName, strict);
767 }
768 }
769 Set<String> parsed = new HashSet<>();
770 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
771 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
772 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
773 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
774 Map<Object, InputLocation> locations = null;
775 switch (childName) {
776 case "username": {
777 server.username(interpolatedTrimmed(nextText(parser, strict), "username"));
778 break;
779 }
780 case "password": {
781 server.password(interpolatedTrimmed(nextText(parser, strict), "password"));
782 break;
783 }
784 case "privateKey": {
785 server.privateKey(interpolatedTrimmed(nextText(parser, strict), "privateKey"));
786 break;
787 }
788 case "passphrase": {
789 server.passphrase(interpolatedTrimmed(nextText(parser, strict), "passphrase"));
790 break;
791 }
792 case "filePermissions": {
793 server.filePermissions(interpolatedTrimmed(nextText(parser, strict), "filePermissions"));
794 break;
795 }
796 case "directoryPermissions": {
797 server.directoryPermissions(interpolatedTrimmed(nextText(parser, strict), "directoryPermissions"));
798 break;
799 }
800 case "configuration": {
801 server.configuration(buildXmlNode(parser, source));
802 break;
803 }
804 case "id": {
805 server.id(interpolatedTrimmed(nextText(parser, strict), "id"));
806 break;
807 }
808 default: {
809 checkUnknownElement(parser, strict);
810 break;
811 }
812 }
813 if (addLocationInformation) {
814 server.location(childName, new InputLocation(line, column, source, locations));
815 }
816 }
817 return server.build();
818 }
819
820 private Mirror parseMirror(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
821 String tagName = parser.getLocalName();
822 Mirror.Builder mirror = Mirror.newBuilder(true);
823 if (addLocationInformation) {
824 mirror.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
825 }
826 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
827 String name = parser.getAttributeLocalName(i);
828 String ns = parser.getAttributeNamespace(i);
829 String value = parser.getAttributeValue(i);
830 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
831
832 } else {
833 checkUnknownAttribute(parser, name, tagName, strict);
834 }
835 }
836 Set<String> parsed = new HashSet<>();
837 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
838 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
839 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
840 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
841 Map<Object, InputLocation> locations = null;
842 switch (childName) {
843 case "mirrorOf": {
844 mirror.mirrorOf(interpolatedTrimmed(nextText(parser, strict), "mirrorOf"));
845 break;
846 }
847 case "name": {
848 mirror.name(interpolatedTrimmed(nextText(parser, strict), "name"));
849 break;
850 }
851 case "url": {
852 mirror.url(interpolatedTrimmed(nextText(parser, strict), "url"));
853 break;
854 }
855 case "layout": {
856 mirror.layout(interpolatedTrimmed(nextText(parser, strict), "layout"));
857 break;
858 }
859 case "mirrorOfLayouts": {
860 mirror.mirrorOfLayouts(interpolatedTrimmed(nextText(parser, strict), "mirrorOfLayouts"));
861 break;
862 }
863 case "blocked": {
864 mirror.blocked(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "blocked"), "blocked", parser, false));
865 break;
866 }
867 case "id": {
868 mirror.id(interpolatedTrimmed(nextText(parser, strict), "id"));
869 break;
870 }
871 default: {
872 checkUnknownElement(parser, strict);
873 break;
874 }
875 }
876 if (addLocationInformation) {
877 mirror.location(childName, new InputLocation(line, column, source, locations));
878 }
879 }
880 return mirror.build();
881 }
882
883 private Profile parseProfile(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
884 String tagName = parser.getLocalName();
885 Profile.Builder profile = Profile.newBuilder(true);
886 if (addLocationInformation) {
887 profile.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
888 }
889 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
890 String name = parser.getAttributeLocalName(i);
891 String ns = parser.getAttributeNamespace(i);
892 String value = parser.getAttributeValue(i);
893 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
894
895 } else {
896 checkUnknownAttribute(parser, name, tagName, strict);
897 }
898 }
899 Set<String> parsed = new HashSet<>();
900 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
901 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
902 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
903 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
904 Map<Object, InputLocation> locations = null;
905 switch (childName) {
906 case "activation": {
907 profile.activation(parseActivation(parser, strict, source));
908 break;
909 }
910 case "properties": {
911 Map<String, String> properties = new LinkedHashMap<>();
912 locations = new HashMap<>();
913 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
914 String key = parser.getLocalName();
915 String value = nextText(parser, strict).trim();
916 if (addLocationInformation) {
917 locations.put(key, new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
918 }
919 properties.put(key, value);
920 }
921 profile.properties(properties);
922 break;
923 }
924 case "repositories": {
925 List<Repository> repositories = new ArrayList<>();
926 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
927 if ("repository".equals(parser.getLocalName())) {
928 repositories.add(parseRepository(parser, strict, source));
929 } else {
930 checkUnknownElement(parser, strict);
931 }
932 }
933 profile.repositories(repositories);
934 break;
935 }
936 case "pluginRepositories": {
937 List<Repository> pluginRepositories = new ArrayList<>();
938 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
939 if ("pluginRepository".equals(parser.getLocalName())) {
940 pluginRepositories.add(parseRepository(parser, strict, source));
941 } else {
942 checkUnknownElement(parser, strict);
943 }
944 }
945 profile.pluginRepositories(pluginRepositories);
946 break;
947 }
948 case "id": {
949 profile.id(interpolatedTrimmed(nextText(parser, strict), "id"));
950 break;
951 }
952 default: {
953 checkUnknownElement(parser, strict);
954 break;
955 }
956 }
957 if (addLocationInformation) {
958 profile.location(childName, new InputLocation(line, column, source, locations));
959 }
960 }
961 return profile.build();
962 }
963
964 private Activation parseActivation(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
965 String tagName = parser.getLocalName();
966 Activation.Builder activation = Activation.newBuilder(true);
967 if (addLocationInformation) {
968 activation.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
969 }
970 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
971 String name = parser.getAttributeLocalName(i);
972 String ns = parser.getAttributeNamespace(i);
973 String value = parser.getAttributeValue(i);
974 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
975
976 } else {
977 checkUnknownAttribute(parser, name, tagName, strict);
978 }
979 }
980 Set<String> parsed = new HashSet<>();
981 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
982 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
983 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
984 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
985 Map<Object, InputLocation> locations = null;
986 switch (childName) {
987 case "activeByDefault": {
988 activation.activeByDefault(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "activeByDefault"), "activeByDefault", parser, false));
989 break;
990 }
991 case "jdk": {
992 activation.jdk(interpolatedTrimmed(nextText(parser, strict), "jdk"));
993 break;
994 }
995 case "os": {
996 activation.os(parseActivationOS(parser, strict, source));
997 break;
998 }
999 case "property": {
1000 activation.property(parseActivationProperty(parser, strict, source));
1001 break;
1002 }
1003 case "file": {
1004 activation.file(parseActivationFile(parser, strict, source));
1005 break;
1006 }
1007 case "packaging": {
1008 activation.packaging(interpolatedTrimmed(nextText(parser, strict), "packaging"));
1009 break;
1010 }
1011 case "condition": {
1012 activation.condition(interpolatedTrimmed(nextText(parser, strict), "condition"));
1013 break;
1014 }
1015 default: {
1016 checkUnknownElement(parser, strict);
1017 break;
1018 }
1019 }
1020 if (addLocationInformation) {
1021 activation.location(childName, new InputLocation(line, column, source, locations));
1022 }
1023 }
1024 return activation.build();
1025 }
1026
1027 private RepositoryBase parseRepositoryBase(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1028 String tagName = parser.getLocalName();
1029 RepositoryBase.Builder repositoryBase = RepositoryBase.newBuilder(true);
1030 if (addLocationInformation) {
1031 repositoryBase.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1032 }
1033 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1034 String name = parser.getAttributeLocalName(i);
1035 String ns = parser.getAttributeNamespace(i);
1036 String value = parser.getAttributeValue(i);
1037 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1038
1039 } else {
1040 checkUnknownAttribute(parser, name, tagName, strict);
1041 }
1042 }
1043 Set<String> parsed = new HashSet<>();
1044 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1045 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1046 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1047 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1048 Map<Object, InputLocation> locations = null;
1049 switch (childName) {
1050 case "name": {
1051 repositoryBase.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1052 break;
1053 }
1054 case "url": {
1055 repositoryBase.url(interpolatedTrimmed(nextText(parser, strict), "url"));
1056 break;
1057 }
1058 case "layout": {
1059 repositoryBase.layout(interpolatedTrimmed(nextText(parser, strict), "layout"));
1060 break;
1061 }
1062 case "id": {
1063 repositoryBase.id(interpolatedTrimmed(nextText(parser, strict), "id"));
1064 break;
1065 }
1066 default: {
1067 checkUnknownElement(parser, strict);
1068 break;
1069 }
1070 }
1071 if (addLocationInformation) {
1072 repositoryBase.location(childName, new InputLocation(line, column, source, locations));
1073 }
1074 }
1075 return repositoryBase.build();
1076 }
1077
1078 private Repository parseRepository(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1079 String tagName = parser.getLocalName();
1080 Repository.Builder repository = Repository.newBuilder(true);
1081 if (addLocationInformation) {
1082 repository.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1083 }
1084 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1085 String name = parser.getAttributeLocalName(i);
1086 String ns = parser.getAttributeNamespace(i);
1087 String value = parser.getAttributeValue(i);
1088 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1089
1090 } else {
1091 checkUnknownAttribute(parser, name, tagName, strict);
1092 }
1093 }
1094 Set<String> parsed = new HashSet<>();
1095 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1096 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1097 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1098 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1099 Map<Object, InputLocation> locations = null;
1100 switch (childName) {
1101 case "releases": {
1102 repository.releases(parseRepositoryPolicy(parser, strict, source));
1103 break;
1104 }
1105 case "snapshots": {
1106 repository.snapshots(parseRepositoryPolicy(parser, strict, source));
1107 break;
1108 }
1109 case "name": {
1110 repository.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1111 break;
1112 }
1113 case "url": {
1114 repository.url(interpolatedTrimmed(nextText(parser, strict), "url"));
1115 break;
1116 }
1117 case "layout": {
1118 repository.layout(interpolatedTrimmed(nextText(parser, strict), "layout"));
1119 break;
1120 }
1121 case "id": {
1122 repository.id(interpolatedTrimmed(nextText(parser, strict), "id"));
1123 break;
1124 }
1125 default: {
1126 checkUnknownElement(parser, strict);
1127 break;
1128 }
1129 }
1130 if (addLocationInformation) {
1131 repository.location(childName, new InputLocation(line, column, source, locations));
1132 }
1133 }
1134 return repository.build();
1135 }
1136
1137 private RepositoryPolicy parseRepositoryPolicy(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1138 String tagName = parser.getLocalName();
1139 RepositoryPolicy.Builder repositoryPolicy = RepositoryPolicy.newBuilder(true);
1140 if (addLocationInformation) {
1141 repositoryPolicy.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1142 }
1143 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1144 String name = parser.getAttributeLocalName(i);
1145 String ns = parser.getAttributeNamespace(i);
1146 String value = parser.getAttributeValue(i);
1147 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1148
1149 } else {
1150 checkUnknownAttribute(parser, name, tagName, strict);
1151 }
1152 }
1153 Set<String> parsed = new HashSet<>();
1154 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1155 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1156 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1157 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1158 Map<Object, InputLocation> locations = null;
1159 switch (childName) {
1160 case "enabled": {
1161 repositoryPolicy.enabled(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "enabled"), "enabled", parser, true));
1162 break;
1163 }
1164 case "updatePolicy": {
1165 repositoryPolicy.updatePolicy(interpolatedTrimmed(nextText(parser, strict), "updatePolicy"));
1166 break;
1167 }
1168 case "checksumPolicy": {
1169 repositoryPolicy.checksumPolicy(interpolatedTrimmed(nextText(parser, strict), "checksumPolicy"));
1170 break;
1171 }
1172 default: {
1173 checkUnknownElement(parser, strict);
1174 break;
1175 }
1176 }
1177 if (addLocationInformation) {
1178 repositoryPolicy.location(childName, new InputLocation(line, column, source, locations));
1179 }
1180 }
1181 return repositoryPolicy.build();
1182 }
1183
1184 private ActivationProperty parseActivationProperty(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1185 String tagName = parser.getLocalName();
1186 ActivationProperty.Builder activationProperty = ActivationProperty.newBuilder(true);
1187 if (addLocationInformation) {
1188 activationProperty.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1189 }
1190 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1191 String name = parser.getAttributeLocalName(i);
1192 String ns = parser.getAttributeNamespace(i);
1193 String value = parser.getAttributeValue(i);
1194 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1195
1196 } else {
1197 checkUnknownAttribute(parser, name, tagName, strict);
1198 }
1199 }
1200 Set<String> parsed = new HashSet<>();
1201 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1202 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1203 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1204 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1205 Map<Object, InputLocation> locations = null;
1206 switch (childName) {
1207 case "name": {
1208 activationProperty.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1209 break;
1210 }
1211 case "value": {
1212 activationProperty.value(interpolatedTrimmed(nextText(parser, strict), "value"));
1213 break;
1214 }
1215 default: {
1216 checkUnknownElement(parser, strict);
1217 break;
1218 }
1219 }
1220 if (addLocationInformation) {
1221 activationProperty.location(childName, new InputLocation(line, column, source, locations));
1222 }
1223 }
1224 return activationProperty.build();
1225 }
1226
1227 private ActivationOS parseActivationOS(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1228 String tagName = parser.getLocalName();
1229 ActivationOS.Builder activationOS = ActivationOS.newBuilder(true);
1230 if (addLocationInformation) {
1231 activationOS.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1232 }
1233 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1234 String name = parser.getAttributeLocalName(i);
1235 String ns = parser.getAttributeNamespace(i);
1236 String value = parser.getAttributeValue(i);
1237 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1238
1239 } else {
1240 checkUnknownAttribute(parser, name, tagName, strict);
1241 }
1242 }
1243 Set<String> parsed = new HashSet<>();
1244 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1245 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1246 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1247 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1248 Map<Object, InputLocation> locations = null;
1249 switch (childName) {
1250 case "name": {
1251 activationOS.name(interpolatedTrimmed(nextText(parser, strict), "name"));
1252 break;
1253 }
1254 case "family": {
1255 activationOS.family(interpolatedTrimmed(nextText(parser, strict), "family"));
1256 break;
1257 }
1258 case "arch": {
1259 activationOS.arch(interpolatedTrimmed(nextText(parser, strict), "arch"));
1260 break;
1261 }
1262 case "version": {
1263 activationOS.version(interpolatedTrimmed(nextText(parser, strict), "version"));
1264 break;
1265 }
1266 default: {
1267 checkUnknownElement(parser, strict);
1268 break;
1269 }
1270 }
1271 if (addLocationInformation) {
1272 activationOS.location(childName, new InputLocation(line, column, source, locations));
1273 }
1274 }
1275 return activationOS.build();
1276 }
1277
1278 private ActivationFile parseActivationFile(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
1279 String tagName = parser.getLocalName();
1280 ActivationFile.Builder activationFile = ActivationFile.newBuilder(true);
1281 if (addLocationInformation) {
1282 activationFile.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
1283 }
1284 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
1285 String name = parser.getAttributeLocalName(i);
1286 String ns = parser.getAttributeNamespace(i);
1287 String value = parser.getAttributeValue(i);
1288 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
1289
1290 } else {
1291 checkUnknownAttribute(parser, name, tagName, strict);
1292 }
1293 }
1294 Set<String> parsed = new HashSet<>();
1295 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
1296 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
1297 int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
1298 int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
1299 Map<Object, InputLocation> locations = null;
1300 switch (childName) {
1301 case "missing": {
1302 activationFile.missing(interpolatedTrimmed(nextText(parser, strict), "missing"));
1303 break;
1304 }
1305 case "exists": {
1306 activationFile.exists(interpolatedTrimmed(nextText(parser, strict), "exists"));
1307 break;
1308 }
1309 default: {
1310 checkUnknownElement(parser, strict);
1311 break;
1312 }
1313 }
1314 if (addLocationInformation) {
1315 activationFile.location(childName, new InputLocation(line, column, source, locations));
1316 }
1317 }
1318 return activationFile.build();
1319 }
1320
1321
1322 private String checkDuplicate(String tagName, XMLStreamReader parser, Set<String> parsed) throws XMLStreamException {
1323 if (!parsed.add(tagName)) {
1324 throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
1325 }
1326 return tagName;
1327 }
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340 private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException {
1341
1342 if (strict) {
1343 throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
1344 }
1345 }
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356 private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException {
1357 if (strict) {
1358 throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
1359 }
1360
1361 for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
1362 int eventType = nextTag(parser);
1363 if (eventType == XMLStreamReader.START_ELEMENT) {
1364 unrecognizedTagCount++;
1365 } else if (eventType == XMLStreamReader.END_ELEMENT) {
1366 unrecognizedTagCount--;
1367 }
1368 }
1369 }
1370
1371
1372
1373
1374
1375
1376
1377 private String getTrimmedValue(String s) {
1378 if (s != null) {
1379 s = s.trim();
1380 }
1381 return s;
1382 }
1383
1384
1385
1386
1387
1388
1389
1390
1391 private String interpolatedTrimmed(String value, String context) {
1392 return getTrimmedValue(contentTransformer.transform(value, context));
1393 }
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404 private int nextTag(XMLStreamReader parser) throws XMLStreamException {
1405 while (true) {
1406 int next = parser.next();
1407 switch (next) {
1408 case XMLStreamReader.SPACE:
1409 case XMLStreamReader.COMMENT:
1410 case XMLStreamReader.PROCESSING_INSTRUCTION:
1411 case XMLStreamReader.CDATA:
1412 case XMLStreamReader.CHARACTERS:
1413 continue;
1414 case XMLStreamReader.START_ELEMENT:
1415 case XMLStreamReader.END_ELEMENT:
1416 return next;
1417 }
1418 }
1419 }
1420
1421 private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
1422 int eventType = parser.getEventType();
1423 if (eventType != XMLStreamReader.START_ELEMENT) {
1424 throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
1425 }
1426 eventType = parser.next();
1427 StringBuilder result = new StringBuilder();
1428 while (true) {
1429 if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
1430 result.append(parser.getText());
1431 } else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
1432 String val = null;
1433 if (strict) {
1434 throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
1435 } else if (addDefaultEntities) {
1436 val = DEFAULT_ENTITIES.get(parser.getLocalName());
1437 }
1438 if (val != null) {
1439 result.append(val);
1440 } else {
1441 result.append("&").append(parser.getLocalName()).append(";");
1442 }
1443 } else if (eventType != XMLStreamReader.COMMENT) {
1444 break;
1445 }
1446 eventType = parser.next();
1447 }
1448 if (eventType != XMLStreamReader.END_ELEMENT) {
1449 throw new XMLStreamException(
1450 "TEXT must be immediately followed by END_ELEMENT and not " + eventType , parser.getLocation(), null);
1451 }
1452 return result.toString();
1453 }
1454
1455 private XmlNode buildXmlNode(XMLStreamReader parser, InputSource source) throws XMLStreamException {
1456 return XmlNodeStaxBuilder.build(parser,
1457 addLocationInformation
1458 ? p -> new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source)
1459 : null);
1460 }
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473 private boolean getBooleanValue(String s, String attribute, XMLStreamReader parser, boolean defaultValue) throws XMLStreamException {
1474 if (s != null && s.length() != 0) {
1475 return Boolean.valueOf(s).booleanValue();
1476 }
1477 return defaultValue;
1478 }
1479
1480 public static interface ContentTransformer {
1481
1482
1483
1484
1485
1486
1487
1488 String transform(String source, String fieldName);
1489 }
1490
1491 }