Search in sources :

Example 86 with NodeId

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());
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ExtendedXMLStreamReader(org.exist.stax.ExtendedXMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) XPathException(org.exist.xquery.XPathException) NodeId(org.exist.numbering.NodeId) IOException(java.io.IOException)

Aggregations

NodeId (org.exist.numbering.NodeId)86 IOException (java.io.IOException)21 XMLStreamException (javax.xml.stream.XMLStreamException)17 EXistException (org.exist.EXistException)15 PermissionDeniedException (org.exist.security.PermissionDeniedException)13 NodeProxy (org.exist.dom.persistent.NodeProxy)12 ReentrantLock (java.util.concurrent.locks.ReentrantLock)11 DocumentImpl (org.exist.dom.persistent.DocumentImpl)10 Value (org.exist.storage.btree.Value)8 QName (org.exist.dom.QName)7 ExtendedXMLStreamReader (org.exist.stax.ExtendedXMLStreamReader)6 IEmbeddedXMLStreamReader (org.exist.stax.IEmbeddedXMLStreamReader)6 NodeImpl (org.exist.dom.memtree.NodeImpl)5 Txn (org.exist.storage.txn.Txn)5 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)5 LockException (org.exist.util.LockException)5 URISyntaxException (java.net.URISyntaxException)4 IndexController (org.exist.indexing.IndexController)4 StreamListener (org.exist.indexing.StreamListener)4 DBBroker (org.exist.storage.DBBroker)4