org.apache.maven.plugin.lifecycle.io.LifecycleStaxReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-plugin-api Show documentation
Show all versions of maven-plugin-api Show documentation
The API for plugins - Mojos - development.
// =================== DO NOT EDIT THIS FILE ====================
// Generated by Modello Velocity from reader-stax.vm
// template, any modifications will be overwritten.
// ==============================================================
package org.apache.maven.plugin.lifecycle.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.api.annotations.Generated;
import org.apache.maven.api.plugin.descriptor.lifecycle.LifecycleConfiguration;
import org.apache.maven.api.plugin.descriptor.lifecycle.Lifecycle;
import org.apache.maven.api.plugin.descriptor.lifecycle.Phase;
import org.apache.maven.api.plugin.descriptor.lifecycle.Execution;
import org.apache.maven.internal.xml.XmlNodeBuilder;
import org.apache.maven.api.xml.XmlNode;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.stream.StreamSource;
import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
import static javax.xml.XMLConstants.XML_NS_URI;
@Generated
public class LifecycleStaxReader {
private static final Map DEFAULT_ENTITIES;
static {
Map entities = new HashMap<>();
entities.put("nbsp", "\u00a0");
entities.put("iexcl", "\u00a1");
entities.put("cent", "\u00a2");
entities.put("pound", "\u00a3");
entities.put("curren", "\u00a4");
entities.put("yen", "\u00a5");
entities.put("brvbar", "\u00a6");
entities.put("sect", "\u00a7");
entities.put("uml", "\u00a8");
entities.put("copy", "\u00a9");
entities.put("ordf", "\u00aa");
entities.put("laquo", "\u00ab");
entities.put("not", "\u00ac");
entities.put("shy", "\u00ad");
entities.put("reg", "\u00ae");
entities.put("macr", "\u00af");
entities.put("deg", "\u00b0");
entities.put("plusmn", "\u00b1");
entities.put("sup2", "\u00b2");
entities.put("sup3", "\u00b3");
entities.put("acute", "\u00b4");
entities.put("micro", "\u00b5");
entities.put("para", "\u00b6");
entities.put("middot", "\u00b7");
entities.put("cedil", "\u00b8");
entities.put("sup1", "\u00b9");
entities.put("ordm", "\u00ba");
entities.put("raquo", "\u00bb");
entities.put("frac14", "\u00bc");
entities.put("frac12", "\u00bd");
entities.put("frac34", "\u00be");
entities.put("iquest", "\u00bf");
entities.put("Agrave", "\u00c0");
entities.put("Aacute", "\u00c1");
entities.put("Acirc", "\u00c2");
entities.put("Atilde", "\u00c3");
entities.put("Auml", "\u00c4");
entities.put("Aring", "\u00c5");
entities.put("AElig", "\u00c6");
entities.put("Ccedil", "\u00c7");
entities.put("Egrave", "\u00c8");
entities.put("Eacute", "\u00c9");
entities.put("Ecirc", "\u00ca");
entities.put("Euml", "\u00cb");
entities.put("Igrave", "\u00cc");
entities.put("Iacute", "\u00cd");
entities.put("Icirc", "\u00ce");
entities.put("Iuml", "\u00cf");
entities.put("ETH", "\u00d0");
entities.put("Ntilde", "\u00d1");
entities.put("Ograve", "\u00d2");
entities.put("Oacute", "\u00d3");
entities.put("Ocirc", "\u00d4");
entities.put("Otilde", "\u00d5");
entities.put("Ouml", "\u00d6");
entities.put("times", "\u00d7");
entities.put("Oslash", "\u00d8");
entities.put("Ugrave", "\u00d9");
entities.put("Uacute", "\u00da");
entities.put("Ucirc", "\u00db");
entities.put("Uuml", "\u00dc");
entities.put("Yacute", "\u00dd");
entities.put("THORN", "\u00de");
entities.put("szlig", "\u00df");
entities.put("agrave", "\u00e0");
entities.put("aacute", "\u00e1");
entities.put("acirc", "\u00e2");
entities.put("atilde", "\u00e3");
entities.put("auml", "\u00e4");
entities.put("aring", "\u00e5");
entities.put("aelig", "\u00e6");
entities.put("ccedil", "\u00e7");
entities.put("egrave", "\u00e8");
entities.put("eacute", "\u00e9");
entities.put("ecirc", "\u00ea");
entities.put("euml", "\u00eb");
entities.put("igrave", "\u00ec");
entities.put("iacute", "\u00ed");
entities.put("icirc", "\u00ee");
entities.put("iuml", "\u00ef");
entities.put("eth", "\u00f0");
entities.put("ntilde", "\u00f1");
entities.put("ograve", "\u00f2");
entities.put("oacute", "\u00f3");
entities.put("ocirc", "\u00f4");
entities.put("otilde", "\u00f5");
entities.put("ouml", "\u00f6");
entities.put("divide", "\u00f7");
entities.put("oslash", "\u00f8");
entities.put("ugrave", "\u00f9");
entities.put("uacute", "\u00fa");
entities.put("ucirc", "\u00fb");
entities.put("uuml", "\u00fc");
entities.put("yacute", "\u00fd");
entities.put("thorn", "\u00fe");
entities.put("yuml", "\u00ff");
// ----------------------------------------------------------------------
// Special entities
// ----------------------------------------------------------------------
entities.put("OElig", "\u0152");
entities.put("oelig", "\u0153");
entities.put("Scaron", "\u0160");
entities.put("scaron", "\u0161");
entities.put("Yuml", "\u0178");
entities.put("circ", "\u02c6");
entities.put("tilde", "\u02dc");
entities.put("ensp", "\u2002");
entities.put("emsp", "\u2003");
entities.put("thinsp", "\u2009");
entities.put("zwnj", "\u200c");
entities.put("zwj", "\u200d");
entities.put("lrm", "\u200e");
entities.put("rlm", "\u200f");
entities.put("ndash", "\u2013");
entities.put("mdash", "\u2014");
entities.put("lsquo", "\u2018");
entities.put("rsquo", "\u2019");
entities.put("sbquo", "\u201a");
entities.put("ldquo", "\u201c");
entities.put("rdquo", "\u201d");
entities.put("bdquo", "\u201e");
entities.put("dagger", "\u2020");
entities.put("Dagger", "\u2021");
entities.put("permil", "\u2030");
entities.put("lsaquo", "\u2039");
entities.put("rsaquo", "\u203a");
entities.put("euro", "\u20ac");
// ----------------------------------------------------------------------
// Symbol entities
// ----------------------------------------------------------------------
entities.put("fnof", "\u0192");
entities.put("Alpha", "\u0391");
entities.put("Beta", "\u0392");
entities.put("Gamma", "\u0393");
entities.put("Delta", "\u0394");
entities.put("Epsilon", "\u0395");
entities.put("Zeta", "\u0396");
entities.put("Eta", "\u0397");
entities.put("Theta", "\u0398");
entities.put("Iota", "\u0399");
entities.put("Kappa", "\u039a");
entities.put("Lambda", "\u039b");
entities.put("Mu", "\u039c");
entities.put("Nu", "\u039d");
entities.put("Xi", "\u039e");
entities.put("Omicron", "\u039f");
entities.put("Pi", "\u03a0");
entities.put("Rho", "\u03a1");
entities.put("Sigma", "\u03a3");
entities.put("Tau", "\u03a4");
entities.put("Upsilon", "\u03a5");
entities.put("Phi", "\u03a6");
entities.put("Chi", "\u03a7");
entities.put("Psi", "\u03a8");
entities.put("Omega", "\u03a9");
entities.put("alpha", "\u03b1");
entities.put("beta", "\u03b2");
entities.put("gamma", "\u03b3");
entities.put("delta", "\u03b4");
entities.put("epsilon", "\u03b5");
entities.put("zeta", "\u03b6");
entities.put("eta", "\u03b7");
entities.put("theta", "\u03b8");
entities.put("iota", "\u03b9");
entities.put("kappa", "\u03ba");
entities.put("lambda", "\u03bb");
entities.put("mu", "\u03bc");
entities.put("nu", "\u03bd");
entities.put("xi", "\u03be");
entities.put("omicron", "\u03bf");
entities.put("pi", "\u03c0");
entities.put("rho", "\u03c1");
entities.put("sigmaf", "\u03c2");
entities.put("sigma", "\u03c3");
entities.put("tau", "\u03c4");
entities.put("upsilon", "\u03c5");
entities.put("phi", "\u03c6");
entities.put("chi", "\u03c7");
entities.put("psi", "\u03c8");
entities.put("omega", "\u03c9");
entities.put("thetasym", "\u03d1");
entities.put("upsih", "\u03d2");
entities.put("piv", "\u03d6");
entities.put("bull", "\u2022");
entities.put("hellip", "\u2026");
entities.put("prime", "\u2032");
entities.put("Prime", "\u2033");
entities.put("oline", "\u203e");
entities.put("frasl", "\u2044");
entities.put("weierp", "\u2118");
entities.put("image", "\u2111");
entities.put("real", "\u211c");
entities.put("trade", "\u2122");
entities.put("alefsym", "\u2135");
entities.put("larr", "\u2190");
entities.put("uarr", "\u2191");
entities.put("rarr", "\u2192");
entities.put("darr", "\u2193");
entities.put("harr", "\u2194");
entities.put("crarr", "\u21b5");
entities.put("lArr", "\u21d0");
entities.put("uArr", "\u21d1");
entities.put("rArr", "\u21d2");
entities.put("dArr", "\u21d3");
entities.put("hArr", "\u21d4");
entities.put("forall", "\u2200");
entities.put("part", "\u2202");
entities.put("exist", "\u2203");
entities.put("empty", "\u2205");
entities.put("nabla", "\u2207");
entities.put("isin", "\u2208");
entities.put("notin", "\u2209");
entities.put("ni", "\u220b");
entities.put("prod", "\u220f");
entities.put("sum", "\u2211");
entities.put("minus", "\u2212");
entities.put("lowast", "\u2217");
entities.put("radic", "\u221a");
entities.put("prop", "\u221d");
entities.put("infin", "\u221e");
entities.put("ang", "\u2220");
entities.put("and", "\u2227");
entities.put("or", "\u2228");
entities.put("cap", "\u2229");
entities.put("cup", "\u222a");
entities.put("int", "\u222b");
entities.put("there4", "\u2234");
entities.put("sim", "\u223c");
entities.put("cong", "\u2245");
entities.put("asymp", "\u2248");
entities.put("ne", "\u2260");
entities.put("equiv", "\u2261");
entities.put("le", "\u2264");
entities.put("ge", "\u2265");
entities.put("sub", "\u2282");
entities.put("sup", "\u2283");
entities.put("nsub", "\u2284");
entities.put("sube", "\u2286");
entities.put("supe", "\u2287");
entities.put("oplus", "\u2295");
entities.put("otimes", "\u2297");
entities.put("perp", "\u22a5");
entities.put("sdot", "\u22c5");
entities.put("lceil", "\u2308");
entities.put("rceil", "\u2309");
entities.put("lfloor", "\u230a");
entities.put("rfloor", "\u230b");
entities.put("lang", "\u2329");
entities.put("rang", "\u232a");
entities.put("loz", "\u25ca");
entities.put("spades", "\u2660");
entities.put("clubs", "\u2663");
entities.put("hearts", "\u2665");
entities.put("diams", "\u2666");
DEFAULT_ENTITIES = Collections.unmodifiableMap(entities);
}
private boolean addDefaultEntities = true;
private final ContentTransformer contentTransformer;
public LifecycleStaxReader() {
this((s, f) -> s);
}
public LifecycleStaxReader(ContentTransformer contentTransformer) {
this.contentTransformer = contentTransformer;
}
/**
* Returns the state of the "add default entities" flag.
*
* @return boolean
*/
public boolean getAddDefaultEntities() {
return addDefaultEntities;
} //-- boolean getAddDefaultEntities()
/**
* Sets the state of the "add default entities" flag.
*
* @param addDefaultEntities a addDefaultEntities object.
*/
public void setAddDefaultEntities(boolean addDefaultEntities) {
this.addDefaultEntities = addDefaultEntities;
} //-- void setAddDefaultEntities(boolean)
public LifecycleConfiguration read(Reader reader) throws XMLStreamException {
return read(reader, true);
}
/**
* @param reader a reader object.
* @param strict a strict object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return LifecycleConfiguration
*/
public LifecycleConfiguration read(Reader reader, boolean strict) throws XMLStreamException {
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
StreamSource streamSource = new StreamSource(reader);
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
return read(parser, strict);
} //-- LifecycleConfiguration read(Reader, boolean)
public LifecycleConfiguration read(InputStream in) throws XMLStreamException {
return read(in, true);
}
/**
* Method read.
*
* @param in a in object.
* @param strict a strict object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return LifecycleConfiguration
*/
public LifecycleConfiguration read(InputStream in, boolean strict) throws XMLStreamException {
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
StreamSource streamSource = new StreamSource(in);
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
return read(parser, strict);
} //-- LifecycleConfiguration read(InputStream, boolean)
/**
* Method read.
*
* @param parser a parser object.
* @param strict a strict object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return LifecycleConfiguration
*/
public LifecycleConfiguration read(XMLStreamReader parser, boolean strict) throws XMLStreamException {
LifecycleConfiguration lifecycleConfiguration = null;
int eventType = parser.getEventType();
boolean parsed = false;
while (eventType != XMLStreamReader.END_DOCUMENT) {
if (eventType == XMLStreamReader.START_ELEMENT) {
if (strict && ! "lifecycles".equals(parser.getLocalName())) {
throw new XMLStreamException("Expected root element 'lifecycles' but found '" + parser.getName() + "'", parser.getLocation(), null);
} else if (parsed) {
// fallback, already expected a XMLStreamException due to invalid XML
throw new XMLStreamException("Duplicated tag: 'lifecycles'", parser.getLocation(), null);
}
lifecycleConfiguration = parseLifecycleConfiguration(parser, strict);
parsed = true;
}
eventType = parser.next();
}
if (parsed) {
return lifecycleConfiguration;
}
throw new XMLStreamException("Expected root element 'lifecycles' but found no element at all: invalid XML document", parser.getLocation(), null);
} //-- LifecycleConfiguration read(XMLStreamReader, boolean)
private LifecycleConfiguration parseLifecycleConfiguration(XMLStreamReader parser, boolean strict) throws XMLStreamException {
String tagName = parser.getLocalName();
LifecycleConfiguration.Builder lifecycleConfiguration = LifecycleConfiguration.newBuilder(true);
for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
String name = parser.getAttributeLocalName(i);
String ns = parser.getAttributeNamespace(i);
String value = parser.getAttributeValue(i);
if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
// just ignore attributes with non-default namespace (for example: xsi and xml)
} else if ("xmlns".equals(name)) {
// ignore xmlns attribute in root class, which is a reserved attribute name
} else {
checkUnknownAttribute(parser, name, tagName, strict);
}
}
Set parsed = new HashSet<>();
List lifecycles = new ArrayList<>();
while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
switch (childName) {
case "lifecycle": {
lifecycles.add(parseLifecycle(parser, strict));
break;
}
default: {
checkUnknownElement(parser, strict);
break;
}
}
}
lifecycleConfiguration.lifecycles(lifecycles);
lifecycleConfiguration.namespaceUri(parser.getNamespaceURI());
lifecycleConfiguration.modelEncoding(parser.getEncoding());
return lifecycleConfiguration.build();
}
private Lifecycle parseLifecycle(XMLStreamReader parser, boolean strict) throws XMLStreamException {
String tagName = parser.getLocalName();
Lifecycle.Builder lifecycle = Lifecycle.newBuilder(true);
for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
String name = parser.getAttributeLocalName(i);
String ns = parser.getAttributeNamespace(i);
String value = parser.getAttributeValue(i);
if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
// just ignore attributes with non-default namespace (for example: xsi and xml)
} else {
checkUnknownAttribute(parser, name, tagName, strict);
}
}
Set parsed = new HashSet<>();
while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
switch (childName) {
case "id": {
lifecycle.id(interpolatedTrimmed(nextText(parser, strict), "id"));
break;
}
case "phases": {
List phases = new ArrayList<>();
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
if ("phase".equals(parser.getLocalName())) {
phases.add(parsePhase(parser, strict));
} else {
checkUnknownElement(parser, strict);
}
}
lifecycle.phases(phases);
break;
}
default: {
checkUnknownElement(parser, strict);
break;
}
}
}
return lifecycle.build();
}
private Phase parsePhase(XMLStreamReader parser, boolean strict) throws XMLStreamException {
String tagName = parser.getLocalName();
Phase.Builder phase = Phase.newBuilder(true);
for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
String name = parser.getAttributeLocalName(i);
String ns = parser.getAttributeNamespace(i);
String value = parser.getAttributeValue(i);
if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
// just ignore attributes with non-default namespace (for example: xsi and xml)
} else {
checkUnknownAttribute(parser, name, tagName, strict);
}
}
Set parsed = new HashSet<>();
while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
switch (childName) {
case "id": {
phase.id(interpolatedTrimmed(nextText(parser, strict), "id"));
break;
}
case "executions": {
List executions = new ArrayList<>();
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
if ("execution".equals(parser.getLocalName())) {
executions.add(parseExecution(parser, strict));
} else {
checkUnknownElement(parser, strict);
}
}
phase.executions(executions);
break;
}
case "configuration": {
phase.configuration(buildXmlNode(parser));
break;
}
default: {
checkUnknownElement(parser, strict);
break;
}
}
}
return phase.build();
}
private Execution parseExecution(XMLStreamReader parser, boolean strict) throws XMLStreamException {
String tagName = parser.getLocalName();
Execution.Builder execution = Execution.newBuilder(true);
for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
String name = parser.getAttributeLocalName(i);
String ns = parser.getAttributeNamespace(i);
String value = parser.getAttributeValue(i);
if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
// just ignore attributes with non-default namespace (for example: xsi and xml)
} else {
checkUnknownAttribute(parser, name, tagName, strict);
}
}
Set parsed = new HashSet<>();
while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
switch (childName) {
case "configuration": {
execution.configuration(buildXmlNode(parser));
break;
}
case "goals": {
List goals = new ArrayList<>();
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
if ("goal".equals(parser.getLocalName())) {
goals.add(interpolatedTrimmed(nextText(parser, strict), "goals"));
} else {
checkUnknownElement(parser, strict);
}
}
execution.goals(goals);
break;
}
default: {
checkUnknownElement(parser, strict);
break;
}
}
}
return execution.build();
}
private String checkDuplicate(String tagName, XMLStreamReader parser, Set parsed) throws XMLStreamException {
switch (tagName) {
case "lifecycle":
break;
default:
if (!parsed.add(tagName)) {
throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
}
}
return tagName;
}
/**
* Method checkUnknownAttribute.
*
* @param parser a parser object.
* @param strict a strict object.
* @param tagName a tagName object.
* @param attribute a attribute object.
* @throws XMLStreamException XMLStreamException if
* any.
* @throws IOException IOException if any.
*/
private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException {
// strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
if (strict) {
throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
}
} //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)
/**
* Method checkUnknownElement.
*
* @param parser a parser object.
* @param strict a strict object.
* @throws XMLStreamException XMLStreamException if
* any.
* @throws IOException IOException if any.
*/
private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException {
if (strict) {
throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
}
for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
int eventType = nextTag(parser);
if (eventType == XMLStreamReader.START_ELEMENT) {
unrecognizedTagCount++;
} else if (eventType == XMLStreamReader.END_ELEMENT) {
unrecognizedTagCount--;
}
}
} //-- void checkUnknownElement(XMLStreamReader, boolean)
/**
* Method getTrimmedValue.
*
* @param s a s object.
* @return String
*/
private String getTrimmedValue(String s) {
if (s != null) {
s = s.trim();
}
return s;
} //-- String getTrimmedValue(String)
/**
* Method interpolatedTrimmed.
*
* @param value a value object.
* @param context a context object.
* @return String
*/
private String interpolatedTrimmed(String value, String context) {
return getTrimmedValue(contentTransformer.transform(value, context));
} //-- String interpolatedTrimmed(String, String)
/**
* Method nextTag.
*
* @param parser a parser object.
* @throws IOException IOException if any.
* @throws XMLStreamException XMLStreamException if
* any.
* @return int
*/
private int nextTag(XMLStreamReader parser) throws XMLStreamException {
while (true) {
int next = parser.next();
switch (next) {
case XMLStreamReader.SPACE:
case XMLStreamReader.COMMENT:
case XMLStreamReader.PROCESSING_INSTRUCTION:
case XMLStreamReader.CDATA:
case XMLStreamReader.CHARACTERS:
continue;
case XMLStreamReader.START_ELEMENT:
case XMLStreamReader.END_ELEMENT:
return next;
}
}
} //-- int nextTag(XMLStreamReader)
private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
int eventType = parser.getEventType();
if (eventType != XMLStreamReader.START_ELEMENT) {
throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
}
eventType = parser.next();
StringBuilder result = new StringBuilder();
while (true) {
if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
result.append(parser.getText());
} else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
String val = null;
if (strict) {
throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
} else if (addDefaultEntities) {
val = DEFAULT_ENTITIES.get(parser.getLocalName());
}
if (val != null) {
result.append(val);
} else {
result.append("&").append(parser.getLocalName()).append(";");
}
} else if (eventType != XMLStreamReader.COMMENT) {
break;
}
eventType = parser.next();
}
if (eventType != XMLStreamReader.END_ELEMENT) {
throw new XMLStreamException(
"TEXT must be immediately followed by END_ELEMENT and not " + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);
}
return result.toString();
}
private XmlNode buildXmlNode(XMLStreamReader parser) throws XMLStreamException {
return XmlNodeBuilder.build(parser);
}
public static interface ContentTransformer {
/**
* Interpolate the value read from the xpp3 document
* @param source The source value
* @param fieldName A description of the field being interpolated. The implementation may use this to
* log stuff.
* @return The interpolated value.
*/
String transform(String source, String fieldName);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy