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