use of org.exist.numbering.NodeId in project exist by eXist-db.
the class SerializerUtils method getSerializationOptions.
/**
* Parse output:serialization-parameters XML fragment into serialization
* properties as defined by the fn:serialize function.
*
* @param parent the parent expression calling this method
* @param parameters root node of the XML fragment
* @param properties parameters are added to the given properties
* @throws XPathException in case of dynamic error
*/
public static void getSerializationOptions(final Expression parent, final NodeValue parameters, final Properties properties) throws XPathException {
try {
final XMLStreamReader reader = parent.getContext().getXMLStreamReader(parameters);
while (reader.hasNext() && (reader.next() != XMLStreamReader.START_ELEMENT)) {
/* advance to the first starting element (root node) of the options */
}
if (!Namespaces.XSLT_XQUERY_SERIALIZATION_NS.equals(reader.getNamespaceURI())) {
throw new XPathException(parent, FnModule.SENR0001, "serialization parameter elements should be in the output namespace");
}
final int thisLevel = ((NodeId) reader.getProperty(ExtendedXMLStreamReader.PROPERTY_NODE_ID)).getTreeLevel();
while (reader.hasNext()) {
final int status = reader.next();
if (status == XMLStreamReader.START_ELEMENT) {
final String key = reader.getLocalName();
if (properties.contains(key)) {
throw new XPathException(parent, FnModule.SEPM0019, "serialization parameter specified twice: " + key);
}
String value = reader.getAttributeValue(XMLConstants.NULL_NS_URI, "value");
if (value == null) {
// backwards compatibility: use element text as value
value = reader.getElementText();
}
setProperty(key, value, properties, reader.getNamespaceContext()::getNamespaceURI);
} else if (status == XMLStreamReader.END_ELEMENT) {
final NodeId otherId = (NodeId) reader.getProperty(ExtendedXMLStreamReader.PROPERTY_NODE_ID);
final int otherLevel = otherId.getTreeLevel();
if (otherLevel == thisLevel) {
// exit-while
break;
}
}
}
} catch (final XMLStreamException | IOException e) {
throw new XPathException(parent, ErrorCodes.EXXQDY0001, e.getMessage());
}
}
Aggregations