1
2
3
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.plugin.lifecycle.LifecycleConfiguration;
22 import org.apache.maven.plugin.lifecycle.Lifecycle;
23 import org.apache.maven.plugin.lifecycle.Phase;
24 import org.apache.maven.plugin.lifecycle.Execution;
25 import org.apache.maven.internal.xml.XmlNodeBuilder;
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 LifecycleMappingsStaxReader {
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
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
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 LifecycleMappingsStaxReader() {
307 this((s, f) -> s);
308 }
309
310 public LifecycleMappingsStaxReader(ContentTransformer contentTransformer) {
311 this.contentTransformer = contentTransformer;
312 }
313
314
315
316
317
318
319 public boolean getAddDefaultEntities() {
320 return addDefaultEntities;
321 }
322
323
324
325
326
327
328 public void setAddDefaultEntities(boolean addDefaultEntities) {
329 this.addDefaultEntities = addDefaultEntities;
330 }
331
332
333 public LifecycleConfiguration read(Reader reader) throws XMLStreamException {
334 return read(reader, true);
335 }
336
337
338
339
340
341
342
343
344 public LifecycleConfiguration read(Reader reader, boolean strict) throws XMLStreamException {
345 XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
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 }
351
352 public LifecycleConfiguration read(InputStream in) throws XMLStreamException {
353 return read(in, true);
354 }
355
356
357
358
359
360
361
362
363
364
365 public LifecycleConfiguration read(InputStream in, boolean strict) throws XMLStreamException {
366 XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
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 }
372
373
374
375
376
377
378
379
380
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
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 }
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
414 } else if ("xmlns".equals(name)) {
415
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
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
492 } else {
493 checkUnknownAttribute(parser, name, tagName, strict);
494 }
495 }
496 Set<String> parsed = new HashSet<>();
497 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
498 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
499 switch (childName) {
500 case "id": {
501 phase.id(interpolatedTrimmed(nextText(parser, strict), "id"));
502 break;
503 }
504 case "executions": {
505 List<Execution> executions = new ArrayList<>();
506 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
507 if ("execution".equals(parser.getLocalName())) {
508 executions.add(parseExecution(parser, strict));
509 } else {
510 checkUnknownElement(parser, strict);
511 }
512 }
513 phase.executions(executions);
514 break;
515 }
516 case "configuration": {
517 phase.configuration(buildXmlNode(parser));
518 break;
519 }
520 default: {
521 checkUnknownElement(parser, strict);
522 break;
523 }
524 }
525 }
526 return phase.build();
527 }
528
529 private Execution parseExecution(XMLStreamReader parser, boolean strict) throws XMLStreamException {
530 String tagName = parser.getLocalName();
531 Execution.Builder execution = Execution.newBuilder(true);
532 for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
533 String name = parser.getAttributeLocalName(i);
534 String ns = parser.getAttributeNamespace(i);
535 String value = parser.getAttributeValue(i);
536 if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
537
538 } else {
539 checkUnknownAttribute(parser, name, tagName, strict);
540 }
541 }
542 Set<String> parsed = new HashSet<>();
543 while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
544 String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
545 switch (childName) {
546 case "configuration": {
547 execution.configuration(buildXmlNode(parser));
548 break;
549 }
550 case "goals": {
551 List<String> goals = new ArrayList<>();
552 while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
553 if ("goal".equals(parser.getLocalName())) {
554 goals.add(interpolatedTrimmed(nextText(parser, strict), "goals"));
555 } else {
556 checkUnknownElement(parser, strict);
557 }
558 }
559 execution.goals(goals);
560 break;
561 }
562 default: {
563 checkUnknownElement(parser, strict);
564 break;
565 }
566 }
567 }
568 return execution.build();
569 }
570
571
572 private String checkDuplicate(String tagName, XMLStreamReader parser, Set<String> parsed) throws XMLStreamException {
573 switch (tagName) {
574 case "lifecycle":
575 break;
576 default:
577 if (!parsed.add(tagName)) {
578 throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
579 }
580 }
581 return tagName;
582 }
583
584
585
586
587
588
589
590
591
592
593
594
595 private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException {
596
597 if (strict) {
598 throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
599 }
600 }
601
602
603
604
605
606
607
608
609
610
611 private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException {
612 if (strict) {
613 throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
614 }
615
616 for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
617 int eventType = nextTag(parser);
618 if (eventType == XMLStreamReader.START_ELEMENT) {
619 unrecognizedTagCount++;
620 } else if (eventType == XMLStreamReader.END_ELEMENT) {
621 unrecognizedTagCount--;
622 }
623 }
624 }
625
626
627
628
629
630
631
632 private String getTrimmedValue(String s) {
633 if (s != null) {
634 s = s.trim();
635 }
636 return s;
637 }
638
639
640
641
642
643
644
645
646 private String interpolatedTrimmed(String value, String context) {
647 return getTrimmedValue(contentTransformer.transform(value, context));
648 }
649
650
651
652
653
654
655
656
657
658
659 private int nextTag(XMLStreamReader parser) throws XMLStreamException {
660 while (true) {
661 int next = parser.next();
662 switch (next) {
663 case XMLStreamReader.SPACE:
664 case XMLStreamReader.COMMENT:
665 case XMLStreamReader.PROCESSING_INSTRUCTION:
666 case XMLStreamReader.CDATA:
667 case XMLStreamReader.CHARACTERS:
668 continue;
669 case XMLStreamReader.START_ELEMENT:
670 case XMLStreamReader.END_ELEMENT:
671 return next;
672 }
673 }
674 }
675
676 private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
677 int eventType = parser.getEventType();
678 if (eventType != XMLStreamReader.START_ELEMENT) {
679 throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
680 }
681 eventType = parser.next();
682 StringBuilder result = new StringBuilder();
683 while (true) {
684 if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
685 result.append(parser.getText());
686 } else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
687 String val = null;
688 if (strict) {
689 throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
690 } else if (addDefaultEntities) {
691 val = DEFAULT_ENTITIES.get(parser.getLocalName());
692 }
693 if (val != null) {
694 result.append(val);
695 } else {
696 result.append("&").append(parser.getLocalName()).append(";");
697 }
698 } else if (eventType != XMLStreamReader.COMMENT) {
699 break;
700 }
701 eventType = parser.next();
702 }
703 if (eventType != XMLStreamReader.END_ELEMENT) {
704 throw new XMLStreamException(
705 "TEXT must be immediately followed by END_ELEMENT and not " + eventType , parser.getLocation(), null);
706 }
707 return result.toString();
708 }
709
710 private XmlNode buildXmlNode(XMLStreamReader parser) throws XMLStreamException {
711 return XmlNodeBuilder.build(parser);
712 }
713
714 public static interface ContentTransformer {
715
716
717
718
719
720
721
722 String transform(String source, String fieldName);
723 }
724
725 }