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.toolchain.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.toolchain.InputSource;
22  import org.apache.maven.api.toolchain.InputLocation;
23  import org.apache.maven.api.toolchain.TrackableBase;
24  import org.apache.maven.api.toolchain.PersistedToolchains;
25  import org.apache.maven.api.toolchain.ToolchainModel;
26  import org.apache.maven.api.toolchain.InputLocation;
27  import org.apache.maven.api.toolchain.InputSource;
28  import org.apache.maven.internal.xml.XmlNodeStaxBuilder;
29  import org.apache.maven.api.xml.XmlNode;
30  import javax.xml.stream.XMLInputFactory;
31  import javax.xml.stream.XMLStreamException;
32  import javax.xml.stream.XMLStreamReader;
33  import javax.xml.transform.stream.StreamSource;
34  
35  import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
36  import static javax.xml.XMLConstants.XML_NS_URI;
37  
38  @Generated
39  public class MavenToolchainsStaxReader {
40  
41      private static final Map<String, String> DEFAULT_ENTITIES;
42      static {
43          Map<String, String> entities = new HashMap<>();
44          entities.put("nbsp", "\u00a0");
45          entities.put("iexcl", "\u00a1");
46          entities.put("cent", "\u00a2");
47          entities.put("pound", "\u00a3");
48          entities.put("curren", "\u00a4");
49          entities.put("yen", "\u00a5");
50          entities.put("brvbar", "\u00a6");
51          entities.put("sect", "\u00a7");
52          entities.put("uml", "\u00a8");
53          entities.put("copy", "\u00a9");
54          entities.put("ordf", "\u00aa");
55          entities.put("laquo", "\u00ab");
56          entities.put("not", "\u00ac");
57          entities.put("shy", "\u00ad");
58          entities.put("reg", "\u00ae");
59          entities.put("macr", "\u00af");
60          entities.put("deg", "\u00b0");
61          entities.put("plusmn", "\u00b1");
62          entities.put("sup2", "\u00b2");
63          entities.put("sup3", "\u00b3");
64          entities.put("acute", "\u00b4");
65          entities.put("micro", "\u00b5");
66          entities.put("para", "\u00b6");
67          entities.put("middot", "\u00b7");
68          entities.put("cedil", "\u00b8");
69          entities.put("sup1", "\u00b9");
70          entities.put("ordm", "\u00ba");
71          entities.put("raquo", "\u00bb");
72          entities.put("frac14", "\u00bc");
73          entities.put("frac12", "\u00bd");
74          entities.put("frac34", "\u00be");
75          entities.put("iquest", "\u00bf");
76          entities.put("Agrave", "\u00c0");
77          entities.put("Aacute", "\u00c1");
78          entities.put("Acirc", "\u00c2");
79          entities.put("Atilde", "\u00c3");
80          entities.put("Auml", "\u00c4");
81          entities.put("Aring", "\u00c5");
82          entities.put("AElig", "\u00c6");
83          entities.put("Ccedil", "\u00c7");
84          entities.put("Egrave", "\u00c8");
85          entities.put("Eacute", "\u00c9");
86          entities.put("Ecirc", "\u00ca");
87          entities.put("Euml", "\u00cb");
88          entities.put("Igrave", "\u00cc");
89          entities.put("Iacute", "\u00cd");
90          entities.put("Icirc", "\u00ce");
91          entities.put("Iuml", "\u00cf");
92          entities.put("ETH", "\u00d0");
93          entities.put("Ntilde", "\u00d1");
94          entities.put("Ograve", "\u00d2");
95          entities.put("Oacute", "\u00d3");
96          entities.put("Ocirc", "\u00d4");
97          entities.put("Otilde", "\u00d5");
98          entities.put("Ouml", "\u00d6");
99          entities.put("times", "\u00d7");
100         entities.put("Oslash", "\u00d8");
101         entities.put("Ugrave", "\u00d9");
102         entities.put("Uacute", "\u00da");
103         entities.put("Ucirc", "\u00db");
104         entities.put("Uuml", "\u00dc");
105         entities.put("Yacute", "\u00dd");
106         entities.put("THORN", "\u00de");
107         entities.put("szlig", "\u00df");
108         entities.put("agrave", "\u00e0");
109         entities.put("aacute", "\u00e1");
110         entities.put("acirc", "\u00e2");
111         entities.put("atilde", "\u00e3");
112         entities.put("auml", "\u00e4");
113         entities.put("aring", "\u00e5");
114         entities.put("aelig", "\u00e6");
115         entities.put("ccedil", "\u00e7");
116         entities.put("egrave", "\u00e8");
117         entities.put("eacute", "\u00e9");
118         entities.put("ecirc", "\u00ea");
119         entities.put("euml", "\u00eb");
120         entities.put("igrave", "\u00ec");
121         entities.put("iacute", "\u00ed");
122         entities.put("icirc", "\u00ee");
123         entities.put("iuml", "\u00ef");
124         entities.put("eth", "\u00f0");
125         entities.put("ntilde", "\u00f1");
126         entities.put("ograve", "\u00f2");
127         entities.put("oacute", "\u00f3");
128         entities.put("ocirc", "\u00f4");
129         entities.put("otilde", "\u00f5");
130         entities.put("ouml", "\u00f6");
131         entities.put("divide", "\u00f7");
132         entities.put("oslash", "\u00f8");
133         entities.put("ugrave", "\u00f9");
134         entities.put("uacute", "\u00fa");
135         entities.put("ucirc", "\u00fb");
136         entities.put("uuml", "\u00fc");
137         entities.put("yacute", "\u00fd");
138         entities.put("thorn", "\u00fe");
139         entities.put("yuml", "\u00ff");
140 
141         // ----------------------------------------------------------------------
142         // Special entities
143         // ----------------------------------------------------------------------
144 
145         entities.put("OElig", "\u0152");
146         entities.put("oelig", "\u0153");
147         entities.put("Scaron", "\u0160");
148         entities.put("scaron", "\u0161");
149         entities.put("Yuml", "\u0178");
150         entities.put("circ", "\u02c6");
151         entities.put("tilde", "\u02dc");
152         entities.put("ensp", "\u2002");
153         entities.put("emsp", "\u2003");
154         entities.put("thinsp", "\u2009");
155         entities.put("zwnj", "\u200c");
156         entities.put("zwj", "\u200d");
157         entities.put("lrm", "\u200e");
158         entities.put("rlm", "\u200f");
159         entities.put("ndash", "\u2013");
160         entities.put("mdash", "\u2014");
161         entities.put("lsquo", "\u2018");
162         entities.put("rsquo", "\u2019");
163         entities.put("sbquo", "\u201a");
164         entities.put("ldquo", "\u201c");
165         entities.put("rdquo", "\u201d");
166         entities.put("bdquo", "\u201e");
167         entities.put("dagger", "\u2020");
168         entities.put("Dagger", "\u2021");
169         entities.put("permil", "\u2030");
170         entities.put("lsaquo", "\u2039");
171         entities.put("rsaquo", "\u203a");
172         entities.put("euro", "\u20ac");
173 
174         // ----------------------------------------------------------------------
175         // Symbol entities
176         // ----------------------------------------------------------------------
177 
178         entities.put("fnof", "\u0192");
179         entities.put("Alpha", "\u0391");
180         entities.put("Beta", "\u0392");
181         entities.put("Gamma", "\u0393");
182         entities.put("Delta", "\u0394");
183         entities.put("Epsilon", "\u0395");
184         entities.put("Zeta", "\u0396");
185         entities.put("Eta", "\u0397");
186         entities.put("Theta", "\u0398");
187         entities.put("Iota", "\u0399");
188         entities.put("Kappa", "\u039a");
189         entities.put("Lambda", "\u039b");
190         entities.put("Mu", "\u039c");
191         entities.put("Nu", "\u039d");
192         entities.put("Xi", "\u039e");
193         entities.put("Omicron", "\u039f");
194         entities.put("Pi", "\u03a0");
195         entities.put("Rho", "\u03a1");
196         entities.put("Sigma", "\u03a3");
197         entities.put("Tau", "\u03a4");
198         entities.put("Upsilon", "\u03a5");
199         entities.put("Phi", "\u03a6");
200         entities.put("Chi", "\u03a7");
201         entities.put("Psi", "\u03a8");
202         entities.put("Omega", "\u03a9");
203         entities.put("alpha", "\u03b1");
204         entities.put("beta", "\u03b2");
205         entities.put("gamma", "\u03b3");
206         entities.put("delta", "\u03b4");
207         entities.put("epsilon", "\u03b5");
208         entities.put("zeta", "\u03b6");
209         entities.put("eta", "\u03b7");
210         entities.put("theta", "\u03b8");
211         entities.put("iota", "\u03b9");
212         entities.put("kappa", "\u03ba");
213         entities.put("lambda", "\u03bb");
214         entities.put("mu", "\u03bc");
215         entities.put("nu", "\u03bd");
216         entities.put("xi", "\u03be");
217         entities.put("omicron", "\u03bf");
218         entities.put("pi", "\u03c0");
219         entities.put("rho", "\u03c1");
220         entities.put("sigmaf", "\u03c2");
221         entities.put("sigma", "\u03c3");
222         entities.put("tau", "\u03c4");
223         entities.put("upsilon", "\u03c5");
224         entities.put("phi", "\u03c6");
225         entities.put("chi", "\u03c7");
226         entities.put("psi", "\u03c8");
227         entities.put("omega", "\u03c9");
228         entities.put("thetasym", "\u03d1");
229         entities.put("upsih", "\u03d2");
230         entities.put("piv", "\u03d6");
231         entities.put("bull", "\u2022");
232         entities.put("hellip", "\u2026");
233         entities.put("prime", "\u2032");
234         entities.put("Prime", "\u2033");
235         entities.put("oline", "\u203e");
236         entities.put("frasl", "\u2044");
237         entities.put("weierp", "\u2118");
238         entities.put("image", "\u2111");
239         entities.put("real", "\u211c");
240         entities.put("trade", "\u2122");
241         entities.put("alefsym", "\u2135");
242         entities.put("larr", "\u2190");
243         entities.put("uarr", "\u2191");
244         entities.put("rarr", "\u2192");
245         entities.put("darr", "\u2193");
246         entities.put("harr", "\u2194");
247         entities.put("crarr", "\u21b5");
248         entities.put("lArr", "\u21d0");
249         entities.put("uArr", "\u21d1");
250         entities.put("rArr", "\u21d2");
251         entities.put("dArr", "\u21d3");
252         entities.put("hArr", "\u21d4");
253         entities.put("forall", "\u2200");
254         entities.put("part", "\u2202");
255         entities.put("exist", "\u2203");
256         entities.put("empty", "\u2205");
257         entities.put("nabla", "\u2207");
258         entities.put("isin", "\u2208");
259         entities.put("notin", "\u2209");
260         entities.put("ni", "\u220b");
261         entities.put("prod", "\u220f");
262         entities.put("sum", "\u2211");
263         entities.put("minus", "\u2212");
264         entities.put("lowast", "\u2217");
265         entities.put("radic", "\u221a");
266         entities.put("prop", "\u221d");
267         entities.put("infin", "\u221e");
268         entities.put("ang", "\u2220");
269         entities.put("and", "\u2227");
270         entities.put("or", "\u2228");
271         entities.put("cap", "\u2229");
272         entities.put("cup", "\u222a");
273         entities.put("int", "\u222b");
274         entities.put("there4", "\u2234");
275         entities.put("sim", "\u223c");
276         entities.put("cong", "\u2245");
277         entities.put("asymp", "\u2248");
278         entities.put("ne", "\u2260");
279         entities.put("equiv", "\u2261");
280         entities.put("le", "\u2264");
281         entities.put("ge", "\u2265");
282         entities.put("sub", "\u2282");
283         entities.put("sup", "\u2283");
284         entities.put("nsub", "\u2284");
285         entities.put("sube", "\u2286");
286         entities.put("supe", "\u2287");
287         entities.put("oplus", "\u2295");
288         entities.put("otimes", "\u2297");
289         entities.put("perp", "\u22a5");
290         entities.put("sdot", "\u22c5");
291         entities.put("lceil", "\u2308");
292         entities.put("rceil", "\u2309");
293         entities.put("lfloor", "\u230a");
294         entities.put("rfloor", "\u230b");
295         entities.put("lang", "\u2329");
296         entities.put("rang", "\u232a");
297         entities.put("loz", "\u25ca");
298         entities.put("spades", "\u2660");
299         entities.put("clubs", "\u2663");
300         entities.put("hearts", "\u2665");
301         entities.put("diams", "\u2666");
302         DEFAULT_ENTITIES = Collections.unmodifiableMap(entities);
303     }
304 
305     private boolean addDefaultEntities = true;
306     private boolean addLocationInformation = true;
307 
308     private final ContentTransformer contentTransformer;
309 
310     public MavenToolchainsStaxReader() {
311         this((s, f) -> s);
312     }
313 
314     public MavenToolchainsStaxReader(ContentTransformer contentTransformer) {
315         this.contentTransformer = contentTransformer;
316     }
317 
318     /**
319      * Returns the state of the "add default entities" flag.
320      *
321      * @return boolean
322      */
323     public boolean getAddDefaultEntities() {
324         return addDefaultEntities;
325     } //-- boolean getAddDefaultEntities()
326 
327     /**
328      * Sets the state of the "add default entities" flag.
329      *
330      * @param addDefaultEntities a addDefaultEntities object.
331      */
332     public void setAddDefaultEntities(boolean addDefaultEntities) {
333         this.addDefaultEntities = addDefaultEntities;
334     } //-- void setAddDefaultEntities(boolean)
335 
336     /**
337      * Returns the state of the "add location information" flag.
338      *
339      * @return boolean
340      */
341     public boolean getAddLocationInformation() {
342         return addLocationInformation;
343     } //-- boolean getAddLocationInformation()
344 
345     /**
346      * Sets the state of the "add location information" flag.
347      *
348      * @param addLocationInformation a addLocationInformation object.
349      */
350     public void setAddLocationInformation(boolean addLocationInformation) {
351         this.addLocationInformation = addLocationInformation;
352     } //-- void setAddLocationInformation(boolean)
353 
354     public PersistedToolchains read(Reader reader) throws XMLStreamException {
355         return read(reader, true, null);
356     }
357 
358     /**
359      * @param reader a reader object.
360      * @param strict a strict object.
361      * @throws XMLStreamException XMLStreamException if
362      * any.
363      * @return PersistedToolchains
364      */
365     public PersistedToolchains read(Reader reader, boolean strict, InputSource source) throws XMLStreamException {
366         XMLInputFactory factory = XMLInputFactory.newFactory();
367         factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
368         StreamSource streamSource = new StreamSource(reader, source != null ? source.getLocation() : null);
369         XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
370         return read(parser, strict, source);
371     } //-- PersistedToolchains read(Reader, boolean)
372 
373     public PersistedToolchains read(InputStream in) throws XMLStreamException {
374         return read(in, true, null);
375     }
376 
377     /**
378      * Method read.
379      *
380      * @param in a in object.
381      * @param strict a strict object.
382      * @throws XMLStreamException XMLStreamException if
383      * any.
384      * @return PersistedToolchains
385      */
386     public PersistedToolchains read(InputStream in, boolean strict, InputSource source) throws XMLStreamException {
387         XMLInputFactory factory = XMLInputFactory.newFactory();
388         factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
389         StreamSource streamSource = new StreamSource(in, source != null ? source.getLocation() : null);
390         XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
391         return read(parser, strict, source);
392     } //-- PersistedToolchains read(InputStream, boolean)
393 
394     /**
395      * Method read.
396      *
397      * @param parser a parser object.
398      * @param strict a strict object.
399      * @throws XMLStreamException XMLStreamException if
400      * any.
401      * @return PersistedToolchains
402      */
403     public PersistedToolchains read(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
404         PersistedToolchains persistedToolchains = null;
405         int eventType = parser.getEventType();
406         boolean parsed = false;
407         while (eventType != XMLStreamReader.END_DOCUMENT) {
408             if (eventType == XMLStreamReader.START_ELEMENT) {
409                 if (strict && ! "toolchains".equals(parser.getLocalName())) {
410                     throw new XMLStreamException("Expected root element 'toolchains' but found '" + parser.getName() + "'", parser.getLocation(), null);
411                 } else if (parsed) {
412                     // fallback, already expected a XMLStreamException due to invalid XML
413                     throw new XMLStreamException("Duplicated tag: 'toolchains'", parser.getLocation(), null);
414                 }
415                 persistedToolchains = parsePersistedToolchains(parser, strict, source);
416                 parsed = true;
417             }
418             eventType = parser.next();
419         }
420         if (parsed) {
421             return persistedToolchains;
422         }
423         throw new XMLStreamException("Expected root element 'toolchains' but found no element at all: invalid XML document", parser.getLocation(), null);
424     } //-- PersistedToolchains read(XMLStreamReader, boolean)
425 
426     private TrackableBase parseTrackableBase(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
427         String tagName = parser.getLocalName();
428         TrackableBase.Builder trackableBase = TrackableBase.newBuilder(true);
429         if (addLocationInformation) {
430             trackableBase.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
431         }
432         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
433             String name = parser.getAttributeLocalName(i);
434             String ns = parser.getAttributeNamespace(i);
435             String value = parser.getAttributeValue(i);
436             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
437                 // just ignore attributes with non-default namespace (for example: xsi and xml)
438             } else {
439                 checkUnknownAttribute(parser, name, tagName, strict);
440             }
441         }
442         Set<String> parsed = new HashSet<>();
443         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
444             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
445             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
446             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
447             Map<Object, InputLocation> locations = null;
448             switch (childName) {
449                 default: {
450                     checkUnknownElement(parser, strict);
451                     break;
452                 }
453             }
454             if (addLocationInformation) {
455                 trackableBase.location(childName, new InputLocation(line, column, source, locations));
456             }
457         }
458         return trackableBase.build();
459     }
460 
461     private PersistedToolchains parsePersistedToolchains(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
462         String tagName = parser.getLocalName();
463         PersistedToolchains.Builder persistedToolchains = PersistedToolchains.newBuilder(true);
464         if (addLocationInformation) {
465             persistedToolchains.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
466         }
467         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
468             String name = parser.getAttributeLocalName(i);
469             String ns = parser.getAttributeNamespace(i);
470             String value = parser.getAttributeValue(i);
471             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
472                 // just ignore attributes with non-default namespace (for example: xsi and xml)
473             } else if ("xmlns".equals(name)) {
474                 // ignore xmlns attribute in root class, which is a reserved attribute name
475             } else {
476                 checkUnknownAttribute(parser, name, tagName, strict);
477             }
478         }
479         Set<String> parsed = new HashSet<>();
480         List<ToolchainModel> toolchains = new ArrayList<>();
481         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
482             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
483             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
484             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
485             Map<Object, InputLocation> locations = null;
486             switch (childName) {
487                 case "toolchain": {
488                     toolchains.add(parseToolchainModel(parser, strict, source));
489                     break;
490                 }
491                 default: {
492                     checkUnknownElement(parser, strict);
493                     break;
494                 }
495             }
496             if (addLocationInformation) {
497                 persistedToolchains.location(childName, new InputLocation(line, column, source, locations));
498             }
499         }
500         persistedToolchains.toolchains(toolchains);
501         persistedToolchains.namespaceUri(parser.getNamespaceURI());
502         persistedToolchains.modelEncoding(parser.getEncoding());
503         return persistedToolchains.build();
504     }
505 
506     private ToolchainModel parseToolchainModel(XMLStreamReader parser, boolean strict, InputSource source) throws XMLStreamException {
507         String tagName = parser.getLocalName();
508         ToolchainModel.Builder toolchainModel = ToolchainModel.newBuilder(true);
509         if (addLocationInformation) {
510             toolchainModel.location("", new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
511         }
512         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
513             String name = parser.getAttributeLocalName(i);
514             String ns = parser.getAttributeNamespace(i);
515             String value = parser.getAttributeValue(i);
516             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
517                 // just ignore attributes with non-default namespace (for example: xsi and xml)
518             } else {
519                 checkUnknownAttribute(parser, name, tagName, strict);
520             }
521         }
522         Set<String> parsed = new HashSet<>();
523         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
524             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
525             int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
526             int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
527             Map<Object, InputLocation> locations = null;
528             switch (childName) {
529                 case "type": {
530                     toolchainModel.type(interpolatedTrimmed(nextText(parser, strict), "type"));
531                     break;
532                 }
533                 case "provides": {
534                     Map<String, String> provides = new LinkedHashMap<>();
535                     locations = new HashMap<>();
536                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
537                         String key = parser.getLocalName();
538                         String value = nextText(parser, strict).trim();
539                         if (addLocationInformation) {
540                             locations.put(key, new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source));
541                         }
542                         provides.put(key, value);
543                     }
544                     toolchainModel.provides(provides);
545                     break;
546                 }
547                 case "configuration": {
548                     toolchainModel.configuration(buildXmlNode(parser, source));
549                     break;
550                 }
551                 default: {
552                     checkUnknownElement(parser, strict);
553                     break;
554                 }
555             }
556             if (addLocationInformation) {
557                 toolchainModel.location(childName, new InputLocation(line, column, source, locations));
558             }
559         }
560         return toolchainModel.build();
561     }
562 
563 
564     private String checkDuplicate(String tagName, XMLStreamReader parser, Set<String> parsed) throws XMLStreamException {
565         switch (tagName) {
566         case "toolchain":
567             break;
568         default:
569             if (!parsed.add(tagName)) {
570                 throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
571             }
572         }
573         return tagName;
574     }
575 
576     /**
577      * Method checkUnknownAttribute.
578      *
579      * @param parser a parser object.
580      * @param strict a strict object.
581      * @param tagName a tagName object.
582      * @param attribute a attribute object.
583      * @throws XMLStreamException XMLStreamException if
584      * any.
585      * @throws IOException IOException if any.
586      */
587     private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException {
588         // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
589         if (strict) {
590             throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
591         }
592     } //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)
593 
594     /**
595      * Method checkUnknownElement.
596      *
597      * @param parser a parser object.
598      * @param strict a strict object.
599      * @throws XMLStreamException XMLStreamException if
600      * any.
601      * @throws IOException IOException if any.
602      */
603     private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException {
604         if (strict) {
605             throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
606         }
607 
608         for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
609             int eventType = nextTag(parser);
610             if (eventType == XMLStreamReader.START_ELEMENT) {
611                 unrecognizedTagCount++;
612             } else if (eventType == XMLStreamReader.END_ELEMENT) {
613                 unrecognizedTagCount--;
614             }
615         }
616     } //-- void checkUnknownElement(XMLStreamReader, boolean)
617 
618     /**
619      * Method getTrimmedValue.
620      *
621      * @param s a s object.
622      * @return String
623      */
624     private String getTrimmedValue(String s) {
625         if (s != null) {
626             s = s.trim();
627         }
628         return s;
629     } //-- String getTrimmedValue(String)
630 
631     /**
632      * Method interpolatedTrimmed.
633      *
634      * @param value a value object.
635      * @param context a context object.
636      * @return String
637      */
638     private String interpolatedTrimmed(String value, String context) {
639         return getTrimmedValue(contentTransformer.transform(value, context));
640     } //-- String interpolatedTrimmed(String, String)
641 
642     /**
643      * Method nextTag.
644      *
645      * @param parser a parser object.
646      * @throws IOException IOException if any.
647      * @throws XMLStreamException XMLStreamException if
648      * any.
649      * @return int
650      */
651     private int nextTag(XMLStreamReader parser) throws XMLStreamException {
652         while (true) {
653             int next = parser.next();
654             switch (next) {
655                 case XMLStreamReader.SPACE:
656                 case XMLStreamReader.COMMENT:
657                 case XMLStreamReader.PROCESSING_INSTRUCTION:
658                 case XMLStreamReader.CDATA:
659                 case XMLStreamReader.CHARACTERS:
660                     continue;
661                 case XMLStreamReader.START_ELEMENT:
662                 case XMLStreamReader.END_ELEMENT:
663                     return next;
664             }
665         }
666     } //-- int nextTag(XMLStreamReader)
667 
668     private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
669         int eventType = parser.getEventType();
670         if (eventType != XMLStreamReader.START_ELEMENT) {
671             throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
672         }
673         eventType = parser.next();
674         StringBuilder result = new StringBuilder();
675         while (true) {
676             if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
677                 result.append(parser.getText());
678             } else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
679                 String val = null;
680                 if (strict) {
681                     throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
682                 } else if (addDefaultEntities) {
683                     val = DEFAULT_ENTITIES.get(parser.getLocalName());
684                 }
685                 if (val != null) {
686                     result.append(val);
687                 } else {
688                     result.append("&").append(parser.getLocalName()).append(";");
689                 }
690             } else if (eventType != XMLStreamReader.COMMENT) {
691                 break;
692             }
693             eventType = parser.next();
694         }
695         if (eventType != XMLStreamReader.END_ELEMENT) {
696             throw new XMLStreamException(
697                 "TEXT must be immediately followed by END_ELEMENT and not " + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);
698         }
699         return result.toString();
700     }
701 
702     private XmlNode buildXmlNode(XMLStreamReader parser, InputSource source) throws XMLStreamException {
703         return XmlNodeStaxBuilder.build(parser,
704                 addLocationInformation
705                         ? p -> new InputLocation(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), source)
706                         : null);
707     }
708 
709     public static interface ContentTransformer {
710         /**
711          * Interpolate the value read from the xpp3 document
712          * @param source The source value
713          * @param fieldName A description of the field being interpolated. The implementation may use this to
714          *                           log stuff.
715          * @return The interpolated value.
716          */
717         String transform(String source, String fieldName);
718     }
719 
720 }