blob: 730cbf89b0ca535e781236f9045229b1e4abfd35 [file] [log] [blame]
#*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*#
#parse ( "common.vm" )
#
#set ( $package = "${packageToolV4}" )
#set ( $className = "${model.name}StaxReader" )
#
#set ( $root = $model.getClass( $model.getRoot($version), $version ) )
#set ( $rootXml = $Helper.xmlClassMetadata( $root ) )
#set ( $rootTag = $rootXml.tagName )
#set ( $rootUcapName = $Helper.capitalise( $root.name ) )
#set ( $rootLcapName = $Helper.uncapitalise( $root.name ) )
#
#set ( $needXmlContext = false )
#foreach ( $class in $model.allClasses )
#set ( $allFields = $Helper.xmlFields( $class ) )
#foreach ( $field in $allFields )
#if ( $Helper.xmlFieldMetadata( $field ).format )
#set ( $needXmlContext = true )
#end
#end
#end
#
#MODELLO-VELOCITY#SAVE-OUTPUT-TO ${package.replace('.','/')}/${className}.java
// =================== DO NOT EDIT THIS FILE ====================
// Generated by Modello Velocity from ${template}
// template, any modifications will be overwritten.
// ==============================================================
package ${package};
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.text.DateFormat;
#if ( $needXmlContext )
import java.util.ArrayDeque;
#end
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
#if ( $needXmlContext )
import java.util.Deque;
#end
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.apache.maven.api.annotations.Generated;
#if ( $locationTracking )
import ${packageModelV4}.InputSource;
import ${packageModelV4}.InputLocation;
#end
#foreach ( $class in $model.allClasses )
import ${packageModelV4}.${class.name};
#end
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.api.xml.XmlService;
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;
import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE;
import static java.util.Map.entry;
@Generated
public class ${className} {
public static interface ContentTransformer {
/**
* Interpolate the value read from the xpp3 document
* @param inputSrc The input 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 inputSrc, String fieldName);
}
static class DefaultEntitiesHolder {
static final Map<String, String> DEFAULT_ENTITIES;
static {
DEFAULT_ENTITIES = doGetDefaultEntities();
}
}
static class InputFactoryHolder {
static final XMLInputFactory XML_INPUT_FACTORY;
static {
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XML_INPUT_FACTORY = factory;
}
}
private boolean addDefaultEntities = true;
#if ( $locationTracking )
private boolean addLocationInformation = true;
#end
private final ContentTransformer contentTransformer;
public ${className}() {
this((s, f) -> s);
}
public ${className}(ContentTransformer contentTransformer) {
this.contentTransformer = contentTransformer;
}
/**
* Returns the {@link XMLInputFactory} used by this reader.
*
* @return the {@link XMLInputFactory} used by this reader.
*/
public XMLInputFactory getXMLInputFactory() {
return InputFactoryHolder.XML_INPUT_FACTORY;
}
/**
* 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)
#if ( $locationTracking )
/**
* Returns the state of the "add location information" flag.
*
* @return boolean
*/
public boolean getAddLocationInformation() {
return addLocationInformation;
} //-- boolean getAddLocationInformation()
/**
* Sets the state of the "add location information" flag.
*
* @param addLocationInformation a addLocationInformation object.
*/
public void setAddLocationInformation(boolean addLocationInformation) {
this.addLocationInformation = addLocationInformation;
} //-- void setAddLocationInformation(boolean)
#end
public ${root.name} read(Reader reader) throws XMLStreamException {
#if ( $locationTracking )
return read(reader, true, null);
#else
return read(reader, true);
#end
}
/**
* @param reader a reader object.
* @param strict a strict object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return ${root.name}
*/
#if ( $locationTracking )
public ${root.name} read(Reader reader, boolean strict, InputSource inputSrc) throws XMLStreamException {
#else
public ${root.name} read(Reader reader, boolean strict) throws XMLStreamException {
#end
#if ( $locationTracking )
StreamSource streamSource = new StreamSource(reader);
streamSource.setPublicId(inputSrc != null ? inputSrc.getLocation() : null);
#else
StreamSource streamSource = new StreamSource(reader);
#end
XMLInputFactory factory = getXMLInputFactory();
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
#if ( $locationTracking )
return read(parser, strict, inputSrc);
#else
return read(parser, strict);
#end
} //-- ${root.name} read(Reader, boolean)
public ${root.name} read(InputStream in) throws XMLStreamException {
#if ( $locationTracking )
return read(in, true, null);
#else
return read(in, true);
#end
}
/**
* Method read.
*
* @param in a in object.
* @param strict a strict object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return ${root.name}
*/
#if ( $locationTracking )
public ${root.name} read(InputStream in, boolean strict, InputSource inputSrc) throws XMLStreamException {
#else
public ${root.name} read(InputStream in, boolean strict) throws XMLStreamException {
#end
#if ( $locationTracking )
StreamSource streamSource = new StreamSource(in);
streamSource.setPublicId(inputSrc != null ? inputSrc.getLocation() : null);
#else
StreamSource streamSource = new StreamSource(in);
#end
XMLInputFactory factory = getXMLInputFactory();
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
#if ( $locationTracking )
return read(parser, strict, inputSrc);
#else
return read(parser, strict);
#end
} //-- ${root.name} read(InputStream, boolean)
/**
* Method read.
*
* @param parser a parser object.
* @param strict a strict object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return ${root.name}
*/
#if ( $locationTracking )
public ${root.name} read(XMLStreamReader parser, boolean strict, InputSource inputSrc) throws XMLStreamException {
#else
public ${root.name} read(XMLStreamReader parser, boolean strict) throws XMLStreamException {
#end
#if ( $needXmlContext )
Deque<Object> context = new ArrayDeque<>();
#end
$rootUcapName $rootLcapName = null;
int eventType = parser.getEventType();
boolean parsed = false;
while (eventType != XMLStreamReader.END_DOCUMENT) {
if (eventType == XMLStreamReader.START_ELEMENT) {
if (strict && ! "${rootTag}".equals(parser.getLocalName())) {
throw new XMLStreamException("Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser.getLocation(), null);
} else if (parsed) {
// fallback, already expected a XMLStreamException due to invalid XML
throw new XMLStreamException("Duplicated tag: '${rootTag}'", parser.getLocation(), null);
}
#if ( $locationTracking )
$rootLcapName = parse${rootUcapName}(parser, strict, parser.getNamespaceURI(), inputSrc);
#elseif ( $needXmlContext )
$rootLcapName = parse${rootUcapName}(parser, strict, parser.getNamespaceURI(), context);
#else
$rootLcapName = parse${rootUcapName}(parser, strict, parser.getNamespaceURI());
#end
parsed = true;
}
eventType = parser.next();
}
if (parsed) {
return $rootLcapName;
}
throw new XMLStreamException("Expected root element '${rootTag}' but found no element at all: invalid XML document", parser.getLocation(), null);
} //-- ${root.name} read(XMLStreamReader, boolean)
#foreach ( $class in $model.allClasses )
#if ( $class.name != "InputSource" && $class.name != "InputLocation" )
#set ( $classUcapName = $Helper.capitalise( $class.name ) )
#set ( $classLcapName = $Helper.uncapitalise( $class.name ) )
#set ( $ancestors = $Helper.ancestors( $class ) )
#set ( $allFields = $Helper.xmlFields( $class ) )
#if ( $locationTracking )
private ${classUcapName} parse${classUcapName}(XMLStreamReader parser, boolean strict, String namespace, InputSource inputSrc) throws XMLStreamException {
#elseif ( $needXmlContext )
private ${classUcapName} parse${classUcapName}(XMLStreamReader parser, boolean strict, String namespace, Deque<Object> context) throws XMLStreamException {
#else
private ${classUcapName} parse${classUcapName}(XMLStreamReader parser, boolean strict, String namespace) throws XMLStreamException {
#end
String tagName = parser.getLocalName();
${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder(true);
#if ( $locationTracking )
if (addLocationInformation) {
${classLcapName}.location("", InputLocation.of(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), inputSrc));
}
#end
#if ( $class == $root )
${classLcapName}.namespaceUri(namespace);
${classLcapName}.modelEncoding(parser.getEncoding());
#end
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)
#if ( $class == $root )
} else if (XMLNS_ATTRIBUTE.equals(name)) {
// ignore xmlns attribute in root class, which is a reserved attribute name
#end
#foreach ( $field in $allFields )
#if ( $Helper.xmlFieldMetadata( $field ).attribute )
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
#if ( ! $fieldTagName )
#set ( $fieldTagName = $field.name )
#end
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
} else if ("$fieldTagName".equals(name)) {
#if ( $locationTracking )
if (addLocationInformation) {
${classLcapName}.location(name, InputLocation.of(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), inputSrc));
}
#end
#if ( $field.type == "String" )
${classLcapName}.${field.name}(interpolatedTrimmed(value, "$fieldTagName"));
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(value, "$fieldTagName"), "$fieldTagName", parser, ${field.defaultValue}));
#elseif ( $field.type == "int" || $field.type == "Integer" )
${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(value, "$fieldTagName"), "$fieldTagName", parser, strict, ${field.defaultValue}));
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
#end
#end
#end
} else {
checkUnknownAttribute(parser, name, tagName, strict);
}
}
Set<String> parsed = new HashSet<>();
#foreach ( $field in $allFields )
#if ( $Helper.isFlatItems( $field ) )
List<$field.to> ${field.name} = new ArrayList<>();
#end
#end
#if ( $needXmlContext )
context.addLast( ${classLcapName} );
#end
while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
checkNamespace(parser, strict, namespace);
String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
#if ( $locationTracking )
int line = addLocationInformation ? parser.getLocation().getLineNumber() : -1;
int column = addLocationInformation ? parser.getLocation().getColumnNumber() : -1;
Map<Object, InputLocation> locations = null;
#end
switch (childName) {
#set( $ift = "if" )
#foreach ( $field in $allFields )
#if ( ! $Helper.xmlFieldMetadata( $field ).attribute && ! $Helper.xmlFieldMetadata( $field ).transient && ! $Helper.xmlFieldMetadata( $field ).format )
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
#if ( ! $fieldTagName )
#set ( $fieldTagName = $field.name )
#end
#if ( $Helper.isFlatItems( $field ) )
#set ( $fieldTagName = $Helper.singular( $fieldTagName ) )
#end
#set ( $fieldCapName = $Helper.capitalise($field.name))
case "${fieldTagName}": {
#if ( $field.type == "String" )
${classLcapName}.${field.name}(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"));
break;
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"), "${fieldTagName}", parser, ${field.defaultValue}));
break;
#elseif ( $field.type == "int" )
${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"), "${fieldTagName}", parser, strict, ${field.defaultValue}));
break;
#elseif ( $field.type == "DOM" )
#if ( $locationTracking )
${classLcapName}.${field.name}(buildXmlNode(parser, inputSrc));
#else
${classLcapName}.${field.name}(buildXmlNode(parser));
#end
break;
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
List<String> ${field.name} = new ArrayList<>();
#if ( $locationTracking )
locations = new HashMap<>();
#end
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
if ("${Helper.singular($fieldTagName)}".equals(parser.getLocalName())) {
#if ( $locationTracking )
if (addLocationInformation) {
locations.put(Integer.valueOf(locations.size()), InputLocation.of(parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber(), inputSrc));
}
#end
${field.name}.add(interpolatedTrimmed(nextText(parser, strict), "${fieldTagName}"));
} else {
checkUnknownElement(parser, strict);
}
}
${classLcapName}.${field.name}(${field.name});
break;
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
Map<String, String> ${field.name} = new LinkedHashMap<>();
#if ( $locationTracking )
locations = new HashMap<>();
#end
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
String key = parser.getLocalName();
#if ( $locationTracking )
int propLine = parser.getLocation().getLineNumber();
int propColumn = parser.getLocation().getColumnNumber();
#end
String value = nextText(parser, strict).trim();
#if ( $locationTracking )
if (addLocationInformation) {
locations.put(key, InputLocation.of(propLine, propColumn, inputSrc));
}
#end
${field.name}.put(key, value);
}
${classLcapName}.${field.name}(${field.name});
break;
#elseif ( $field.to && $field.multiplicity == "1" )
#if ( $locationTracking )
${classLcapName}.${field.name}(parse${field.toClass.name}(parser, strict, namespace, inputSrc));
#elseif ( $needXmlContext )
${classLcapName}.${field.name}(parse${field.toClass.name}(parser, strict, namespace, context));
#else
${classLcapName}.${field.name}(parse${field.toClass.name}(parser, strict, namespace));
#end
break;
#elseif ( $field.to && $field.multiplicity == "*" && $Helper.isFlatItems( $field ) )
#if ( $locationTracking )
${field.name}.add(parse${field.toClass.name}(parser, strict, namespace, inputSrc));
#elseif ( $needXmlContext )
${field.name}.add(parse${field.toClass.name}(parser, strict, namespace, context));
#else
${field.name}.add(parse${field.toClass.name}(parser, strict, namespace));
#end
break;
#elseif ( $field.to && $field.multiplicity == "*" )
List<$field.to> ${field.name} = new ArrayList<>();
while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
if ("${Helper.singular($fieldTagName)}".equals(parser.getLocalName())) {
#if ( $locationTracking )
${field.name}.add(parse${field.toClass.name}(parser, strict, namespace, inputSrc));
#elseif ( $needXmlContext )
${field.name}.add(parse${field.toClass.name}(parser, strict, namespace, context));
#else
${field.name}.add(parse${field.toClass.name}(parser, strict, namespace));
#end
} else {
checkUnknownElement(parser, strict);
}
}
${classLcapName}.${field.name}(${field.name});
break;
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
break;
#end
}
#set( $ift = "else if" )
#end
#end
default: {
checkUnknownElement(parser, strict);
break;
}
}
#if ( $locationTracking )
if (addLocationInformation) {
${classLcapName}.location(childName, InputLocation.of(line, column, inputSrc, locations));
}
#end
}
#if ( $needXmlContext )
context.removeLast();
#end
#foreach ( $field in $allFields )
#if ( $Helper.isFlatItems( $field ) )
${classLcapName}.${field.name}(${field.name});
#end
#end
#foreach ( $field in $allFields )
#if ( $Helper.xmlFieldMetadata( $field ).format )
${classLcapName}.${field.name}($Helper.xmlFieldMetadata( $field ).format);
#end
#end
return ${classLcapName}.build();
}
#end
#end
private void checkNamespace(XMLStreamReader parser, boolean strict, String namespace) throws XMLStreamException {
if (strict) {
String ns = parser.getNamespaceURI();
if (!Objects.equals(namespace, ns)) {
throw new XMLStreamException(
String.format("Unexpected namespace for element '%s': found '%s' but expected '%s'",
parser.getLocalName(),
ns != null ? ns : "no namespace",
namespace),
parser.getLocation(),
null
);
}
}
}
private String checkDuplicate(String tagName, XMLStreamReader parser, Set<String> parsed) throws XMLStreamException {
#set( $aliases = { } )
#set( $flats = { } )
#foreach( $class in $model.allClasses )
#foreach ( $field in $class.getFields($version) )
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
#if ( ! $fieldTagName )
#set ( $fieldTagName = $field.name )
#end
#if ( $field.alias )
#set ( $dummy = $aliases.put( $field.alias, $fieldTagName ) )
#end
#if ( $Helper.isFlatItems( $field ) )
#set ( $fieldTagName = $Helper.singular($fieldTagName) )
#set ( $dummy = $flats.put( $fieldTagName, "" ) )
#end
#end
#end
#if ( ! ${aliases.isEmpty()} )
switch (tagName) {
#foreach( $entry in $aliases.entrySet() )
case "${entry.key}":
tagName = "${entry.value}";
break;
#end
}
#end
#if ( ! ${flats.isEmpty()} )
switch (tagName) {
#foreach( $entry in $flats.entrySet() )
case "${entry.key}":
#end
break;
default:
if (!parsed.add(tagName)) {
throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
}
}
#else
if (!parsed.add(tagName)) {
throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
}
#end
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 = DefaultEntitiesHolder.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();
}
#if ( $locationTracking )
private XmlNode buildXmlNode(XMLStreamReader parser, InputSource inputSrc) throws XMLStreamException {
return XmlService.read(parser,
addLocationInformation
? p -> InputLocation.of(p.getLocation().getLineNumber(), p.getLocation().getColumnNumber(), inputSrc)
: null);
}
#else
private XmlNode buildXmlNode(XMLStreamReader parser) throws XMLStreamException {
return XmlService.read(parser);
}
#end
#foreach ( $class in $model.allClasses )
#foreach ( $field in $class.getFields($version) )
#if ( $field.type == "boolean" || $field.type == "Boolean" )
#set ( $hasBooleanField = true )
#elseif ( $field.type == "int" || $field.type == "Integer" )
#set ( $hasIntegerField = true )
#end
#end
#end
#if ( $hasBooleanField )
/**
* Method getBooleanValue.
*
* @param s a s object.
* @param defaultValue a defaultValue object.
* @param parser a parser object.
* @param attribute a attribute object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return boolean
*/
private boolean getBooleanValue(String s, String attribute, XMLStreamReader parser, boolean defaultValue) throws XMLStreamException {
if (s != null && s.length() != 0) {
return Boolean.valueOf(s).booleanValue();
}
return defaultValue;
} //-- boolean getBooleanValue(String, String, XMLStreamReader, String)
#end
#if ( $hasIntegerField )
/**
* Method getIntegerValue.
*
* @param s a s object.
* @param strict a strict object.
* @param parser a parser object.
* @param attribute a attribute object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return int
*/
private int getIntegerValue(String s, String attribute, XMLStreamReader parser, boolean strict, int defaultValue) throws XMLStreamException {
if (s != null) {
try {
return Integer.valueOf(s).intValue();
} catch (NumberFormatException nfe) {
if (strict) {
throw new XMLStreamException("Unable to parse element '" + attribute + "', must be an integer", parser.getLocation(), nfe);
}
}
}
return defaultValue;
} //-- int getIntegerValue(String, String, XMLStreamReader, boolean)
#end
private static Map<String, String> doGetDefaultEntities() {
return Map.ofEntries(
entry("nbsp", "\u00a0"), entry("iexcl", "\u00a1"), entry("cent", "\u00a2"), entry("pound", "\u00a3"),
entry("curren", "\u00a4"), entry("yen", "\u00a5"), entry("brvbar", "\u00a6"), entry("sect", "\u00a7"),
entry("uml", "\u00a8"), entry("copy", "\u00a9"), entry("ordf", "\u00aa"), entry("laquo", "\u00ab"),
entry("not", "\u00ac"), entry("shy", "\u00ad"), entry("reg", "\u00ae"), entry("macr", "\u00af"),
entry("deg", "\u00b0"), entry("plusmn", "\u00b1"), entry("sup2", "\u00b2"), entry("sup3", "\u00b3"),
entry("acute", "\u00b4"), entry("micro", "\u00b5"), entry("para", "\u00b6"), entry("middot", "\u00b7"),
entry("cedil", "\u00b8"), entry("sup1", "\u00b9"), entry("ordm", "\u00ba"), entry("raquo", "\u00bb"),
entry("frac14", "\u00bc"), entry("frac12", "\u00bd"), entry("frac34", "\u00be"), entry("iquest", "\u00bf"),
entry("Agrave", "\u00c0"), entry("Aacute", "\u00c1"), entry("Acirc", "\u00c2"), entry("Atilde", "\u00c3"),
entry("Auml", "\u00c4"), entry("Aring", "\u00c5"), entry("AElig", "\u00c6"), entry("Ccedil", "\u00c7"),
entry("Egrave", "\u00c8"), entry("Eacute", "\u00c9"), entry("Ecirc", "\u00ca"), entry("Euml", "\u00cb"),
entry("Igrave", "\u00cc"), entry("Iacute", "\u00cd"), entry("Icirc", "\u00ce"), entry("Iuml", "\u00cf"),
entry("ETH", "\u00d0"), entry("Ntilde", "\u00d1"), entry("Ograve", "\u00d2"), entry("Oacute", "\u00d3"),
entry("Ocirc", "\u00d4"), entry("Otilde", "\u00d5"), entry("Ouml", "\u00d6"), entry("times", "\u00d7"),
entry("Oslash", "\u00d8"), entry("Ugrave", "\u00d9"), entry("Uacute", "\u00da"), entry("Ucirc", "\u00db"),
entry("Uuml", "\u00dc"), entry("Yacute", "\u00dd"), entry("THORN", "\u00de"), entry("szlig", "\u00df"),
entry("agrave", "\u00e0"), entry("aacute", "\u00e1"), entry("acirc", "\u00e2"), entry("atilde", "\u00e3"),
entry("auml", "\u00e4"), entry("aring", "\u00e5"), entry("aelig", "\u00e6"), entry("ccedil", "\u00e7"),
entry("egrave", "\u00e8"), entry("eacute", "\u00e9"), entry("ecirc", "\u00ea"), entry("euml", "\u00eb"),
entry("igrave", "\u00ec"), entry("iacute", "\u00ed"), entry("icirc", "\u00ee"), entry("iuml", "\u00ef"),
entry("eth", "\u00f0"), entry("ntilde", "\u00f1"), entry("ograve", "\u00f2"), entry("oacute", "\u00f3"),
entry("ocirc", "\u00f4"), entry("otilde", "\u00f5"), entry("ouml", "\u00f6"), entry("divide", "\u00f7"),
entry("oslash", "\u00f8"), entry("ugrave", "\u00f9"), entry("uacute", "\u00fa"), entry("ucirc", "\u00fb"),
entry("uuml", "\u00fc"), entry("yacute", "\u00fd"), entry("thorn", "\u00fe"), entry("yuml", "\u00ff"),
// Special entities
entry("OElig", "\u0152"), entry("oelig", "\u0153"), entry("Scaron", "\u0160"), entry("scaron", "\u0161"),
entry("Yuml", "\u0178"), entry("circ", "\u02c6"), entry("tilde", "\u02dc"), entry("ensp", "\u2002"),
entry("emsp", "\u2003"), entry("thinsp", "\u2009"), entry("zwnj", "\u200c"), entry("zwj", "\u200d"),
entry("lrm", "\u200e"), entry("rlm", "\u200f"), entry("ndash", "\u2013"), entry("mdash", "\u2014"),
entry("lsquo", "\u2018"), entry("rsquo", "\u2019"), entry("sbquo", "\u201a"), entry("ldquo", "\u201c"),
entry("rdquo", "\u201d"), entry("bdquo", "\u201e"), entry("dagger", "\u2020"), entry("Dagger", "\u2021"),
entry("permil", "\u2030"), entry("lsaquo", "\u2039"), entry("rsaquo", "\u203a"), entry("euro", "\u20ac"),
// Symbol entities
entry("fnof", "\u0192"), entry("Alpha", "\u0391"), entry("Beta", "\u0392"), entry("Gamma", "\u0393"),
entry("Delta", "\u0394"), entry("Epsilon","\u0395"), entry("Zeta", "\u0396"), entry("Eta", "\u0397"),
entry("Theta", "\u0398"), entry("Iota", "\u0399"), entry("Kappa", "\u039a"), entry("Lambda", "\u039b"),
entry("Mu", "\u039c"), entry("Nu", "\u039d"), entry("Xi", "\u039e"), entry("Omicron","\u039f"),
entry("Pi", "\u03a0"), entry("Rho", "\u03a1"), entry("Sigma", "\u03a3"), entry("Tau", "\u03a4"),
entry("Upsilon","\u03a5"), entry("Phi", "\u03a6"), entry("Chi", "\u03a7"), entry("Psi", "\u03a8"),
entry("Omega", "\u03a9"), entry("alpha", "\u03b1"), entry("beta", "\u03b2"), entry("gamma", "\u03b3"),
entry("delta", "\u03b4"), entry("epsilon","\u03b5"), entry("zeta", "\u03b6"), entry("eta", "\u03b7"),
entry("theta", "\u03b8"), entry("iota", "\u03b9"), entry("kappa", "\u03ba"), entry("lambda", "\u03bb"),
entry("mu", "\u03bc"), entry("nu", "\u03bd"), entry("xi", "\u03be"), entry("omicron","\u03bf"),
entry("pi", "\u03c0"), entry("rho", "\u03c1"), entry("sigmaf", "\u03c2"), entry("sigma", "\u03c3"),
entry("tau", "\u03c4"), entry("upsilon","\u03c5"), entry("phi", "\u03c6"), entry("chi", "\u03c7"),
entry("psi", "\u03c8"), entry("omega", "\u03c9"), entry("thetasym","\u03d1"),entry("upsih", "\u03d2"),
entry("piv", "\u03d6"), entry("bull", "\u2022"), entry("hellip", "\u2026"), entry("prime", "\u2032"),
entry("Prime", "\u2033"), entry("oline", "\u203e"), entry("frasl", "\u2044"), entry("weierp", "\u2118"),
entry("image", "\u2111"), entry("real", "\u211c"), entry("trade", "\u2122"), entry("alefsym","\u2135"),
entry("larr", "\u2190"), entry("uarr", "\u2191"), entry("rarr", "\u2192"), entry("darr", "\u2193"),
entry("harr", "\u2194"), entry("crarr", "\u21b5"), entry("lArr", "\u21d0"), entry("uArr", "\u21d1"),
entry("rArr", "\u21d2"), entry("dArr", "\u21d3"), entry("hArr", "\u21d4"), entry("forall", "\u2200"),
entry("part", "\u2202"), entry("exist", "\u2203"), entry("empty", "\u2205"), entry("nabla", "\u2207"),
entry("isin", "\u2208"), entry("notin", "\u2209"), entry("ni", "\u220b"), entry("prod", "\u220f"),
entry("sum", "\u2211"), entry("minus", "\u2212"), entry("lowast", "\u2217"), entry("radic", "\u221a"),
entry("prop", "\u221d"), entry("infin", "\u221e"), entry("ang", "\u2220"), entry("and", "\u2227"),
entry("or", "\u2228"), entry("cap", "\u2229"), entry("cup", "\u222a"), entry("int", "\u222b"),
entry("there4", "\u2234"), entry("sim", "\u223c"), entry("cong", "\u2245"), entry("asymp", "\u2248"),
entry("ne", "\u2260"), entry("equiv", "\u2261"), entry("le", "\u2264"), entry("ge", "\u2265"),
entry("sub", "\u2282"), entry("sup", "\u2283"), entry("nsub", "\u2284"), entry("sube", "\u2286"),
entry("supe", "\u2287"), entry("oplus", "\u2295"), entry("otimes", "\u2297"), entry("perp", "\u22a5"),
entry("sdot", "\u22c5"), entry("lceil", "\u2308"), entry("rceil", "\u2309"), entry("lfloor", "\u230a"),
entry("rfloor", "\u230b"), entry("lang", "\u2329"), entry("rang", "\u232a"), entry("loz", "\u25ca"),
entry("spades", "\u2660"), entry("clubs", "\u2663"), entry("hearts", "\u2665"), entry("diams", "\u2666")
);
}
}