Search in sources :

Example 6 with NodeProxy

use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.

the class TestCase method getResource.

public Resource getResource(Object r) throws XMLDBException {
    LocalCollection collection = null;
    Subject user = null;
    LocalXMLResource res = null;
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    if (r instanceof NodeProxy) {
        NodeProxy p = (NodeProxy) r;
        res = new LocalXMLResource(user, pool, collection, p);
    } else if (r instanceof Node) {
        res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI);
        res.setContentAsDOM((Node) r);
    } else if (r instanceof AtomicValue) {
        res = new LocalXMLResource(user, pool, collection, XmldbURI.EMPTY_URI);
        res.setContent(r);
    } else if (r instanceof LocalXMLResource)
        res = (LocalXMLResource) r;
    else
        throw new XMLDBException(ErrorCodes.VENDOR_ERROR, "unknown object " + r.getClass());
    try {
        Field field = res.getClass().getDeclaredField("outputProperties");
        field.setAccessible(true);
        field.set(res, new Properties(defaultProperties));
    } catch (Exception e) {
    }
    return res;
}
Also used : Field(java.lang.reflect.Field) LocalXMLResource(org.exist.xmldb.LocalXMLResource) LocalCollection(org.exist.xmldb.LocalCollection) Node(org.w3c.dom.Node) XMLDBException(org.xmldb.api.base.XMLDBException) AtomicValue(org.exist.xquery.value.AtomicValue) Properties(java.util.Properties) NodeProxy(org.exist.dom.persistent.NodeProxy) Subject(org.exist.security.Subject) BrokerPool(org.exist.storage.BrokerPool) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 7 with NodeProxy

use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.

the class LuceneFieldConfig method checkCondition.

private boolean checkCondition(DBBroker broker, DocumentImpl document, NodeId nodeId) throws PermissionDeniedException, XPathException {
    if (!condition.isPresent()) {
        return true;
    }
    if (compiledCondition == null && isValid) {
        compiledCondition = compile(broker, condition.get());
    }
    if (!isValid) {
        return false;
    }
    final XQuery xquery = broker.getBrokerPool().getXQueryService();
    final NodeProxy currentNode = new NodeProxy(document, nodeId);
    try {
        Sequence result = xquery.execute(broker, compiledCondition, currentNode);
        return result != null && result.effectiveBooleanValue();
    } catch (PermissionDeniedException | XPathException e) {
        isValid = false;
        throw e;
    } finally {
        compiledCondition.reset();
        compiledCondition.getContext().reset();
    }
}
Also used : XPathException(org.exist.xquery.XPathException) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQuery(org.exist.xquery.XQuery) PermissionDeniedException(org.exist.security.PermissionDeniedException) NodeProxy(org.exist.dom.persistent.NodeProxy)

Example 8 with NodeProxy

use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.

the class AbstractFieldConfig method doBuild.

protected void doBuild(DBBroker broker, DocumentImpl document, NodeId nodeId, Document luceneDoc, CharSequence text) throws PermissionDeniedException, XPathException {
    if (!expression.isPresent()) {
        processText(text, luceneDoc);
        return;
    }
    compile(broker);
    if (!isValid) {
        return;
    }
    final XQuery xquery = broker.getBrokerPool().getXQueryService();
    final NodeProxy currentNode = new NodeProxy(document, nodeId);
    try {
        Sequence result = xquery.execute(broker, compiled, currentNode);
        if (!result.isEmpty()) {
            processResult(result, luceneDoc);
        }
    } catch (PermissionDeniedException | XPathException e) {
        isValid = false;
        throw e;
    } finally {
        compiled.reset();
        compiled.getContext().reset();
    }
}
Also used : XPathException(org.exist.xquery.XPathException) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQuery(org.exist.xquery.XQuery) PermissionDeniedException(org.exist.security.PermissionDeniedException) Sequence(org.exist.xquery.value.Sequence) NodeProxy(org.exist.dom.persistent.NodeProxy)

Example 9 with NodeProxy

use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.

the class DomEnhancingNodeProxyAdapter method create.

public static NodeProxy create(final NodeProxy nodeProxy) {
    final Class<? extends Node>[] clazzes = getNodeClasses(nodeProxy);
    // NoOp Callback is for NodeProxy calls
    // NodeDispatched Callback is for the underlying Node calls
    final Callback[] callbacks = { NoOp.INSTANCE, new NodeDispatcher(nodeProxy) };
    final CallbackFilter callbackFilter = method -> {
        final Class declaringClass = method.getDeclaringClass();
        // look for nodes
        boolean isMethodOnNode = false;
        if (declaringClass.equals(Node.class)) {
            isMethodOnNode = true;
        } else {
            // search parent interfaces
            for (final Class iface : declaringClass.getInterfaces()) {
                if (iface.equals(Node.class)) {
                    isMethodOnNode = true;
                    break;
                }
            }
        }
        if (isMethodOnNode) {
            // The NodeDispatcher
            return 1;
        } else {
            // The NoOp pass through
            return 0;
        }
    };
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(NodeProxy.class);
    enhancer.setInterfaces(clazzes);
    enhancer.setCallbackFilter(callbackFilter);
    enhancer.setCallbacks(callbacks);
    return (NodeProxy) enhancer.create(new Class[] { NodeHandle.class }, new Object[] { nodeProxy });
}
Also used : Callback(net.sf.cglib.proxy.Callback) Text(org.w3c.dom.Text) CallbackFilter(net.sf.cglib.proxy.CallbackFilter) NodeHandle(org.exist.dom.persistent.NodeHandle) Type(org.exist.xquery.value.Type) NodeProxy(org.exist.dom.persistent.NodeProxy) Attr(org.w3c.dom.Attr) Dispatcher(net.sf.cglib.proxy.Dispatcher) Element(org.w3c.dom.Element) NoOp(net.sf.cglib.proxy.NoOp) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) Enhancer(net.sf.cglib.proxy.Enhancer) Callback(net.sf.cglib.proxy.Callback) Enhancer(net.sf.cglib.proxy.Enhancer) NodeHandle(org.exist.dom.persistent.NodeHandle) Node(org.w3c.dom.Node) CallbackFilter(net.sf.cglib.proxy.CallbackFilter) NodeProxy(org.exist.dom.persistent.NodeProxy)

Example 10 with NodeProxy

use of org.exist.dom.persistent.NodeProxy in project exist by eXist-db.

the class FunResolveQName method eval.

public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().start(this);
        context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
        if (contextSequence != null) {
            context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
        }
    }
    final Sequence qnameSeq = args[0];
    if (qnameSeq.isEmpty()) {
        return EmptySequence.EMPTY_SEQUENCE;
    } else {
        context.pushInScopeNamespaces();
        final String qnameString = args[0].getStringValue();
        if (QName.isQName(qnameString) == VALID.val) {
            try {
                String prefix = QName.extractPrefix(qnameString);
                if (prefix == null) {
                    prefix = "";
                }
                String uri = null;
                final NodeValue node = (NodeValue) args[1].itemAt(0);
                if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
                    NodeProxy proxy = (NodeProxy) node;
                    final NodeSet ancestors = proxy.getAncestors(contextId, true);
                    for (NodeProxy ancestor : ancestors) {
                        proxy = ancestor;
                        final ElementImpl e = (ElementImpl) proxy.getNode();
                        uri = findNamespaceURI(e, prefix);
                        if (uri != null) {
                            break;
                        }
                    }
                } else {
                    NodeImpl next = (NodeImpl) node;
                    do {
                        uri = findNamespaceURI((org.exist.dom.memtree.ElementImpl) next, prefix);
                        if (uri != null) {
                            break;
                        } else {
                            next = (NodeImpl) next.getParentNode();
                        }
                    } while (next != null && next.getNodeType() == Node.ELEMENT_NODE);
                }
                if (uri == null && prefix != null && !prefix.isEmpty()) {
                    throw new XPathException(this, ErrorCodes.FONS0004, "No namespace found for prefix. No binding for prefix '" + prefix + "' was found.", args[0]);
                }
                final String localPart = QName.extractLocalName(qnameString);
                final QName qn = new QName(localPart, uri, prefix);
                final QNameValue result = new QNameValue(context, qn);
                if (context.getProfiler().isEnabled()) {
                    context.getProfiler().end(this, "", result);
                }
                context.popInScopeNamespaces();
                return result;
            } catch (final QName.IllegalQNameException e) {
                throw new XPathException(this, ErrorCodes.FOCA0002, "Invalid lexical value. '" + qnameString + "' is not a QName.", args[0]);
            }
        } else {
            throw new XPathException(this, ErrorCodes.FOCA0002, "Invalid lexical value. '" + qnameString + "' is not a QName.", args[0]);
        }
    }
}
Also used : NodeSet(org.exist.dom.persistent.NodeSet) NodeValue(org.exist.xquery.value.NodeValue) NodeImpl(org.exist.dom.memtree.NodeImpl) XPathException(org.exist.xquery.XPathException) QName(org.exist.dom.QName) QNameValue(org.exist.xquery.value.QNameValue) EmptySequence(org.exist.xquery.value.EmptySequence) Sequence(org.exist.xquery.value.Sequence) NodeProxy(org.exist.dom.persistent.NodeProxy) ElementImpl(org.exist.dom.persistent.ElementImpl)

Aggregations

NodeProxy (org.exist.dom.persistent.NodeProxy)79 DocumentImpl (org.exist.dom.persistent.DocumentImpl)18 Sequence (org.exist.xquery.value.Sequence)17 NodeSet (org.exist.dom.persistent.NodeSet)16 NodeId (org.exist.numbering.NodeId)16 XPathException (org.exist.xquery.XPathException)16 IOException (java.io.IOException)12 NewArrayNodeSet (org.exist.dom.persistent.NewArrayNodeSet)10 PermissionDeniedException (org.exist.security.PermissionDeniedException)10 LockException (org.exist.util.LockException)10 NodeValue (org.exist.xquery.value.NodeValue)10 Node (org.w3c.dom.Node)9 Document (org.w3c.dom.Document)8 SAXException (org.xml.sax.SAXException)8 NodeImpl (org.exist.dom.memtree.NodeImpl)7 ExtArrayNodeSet (org.exist.dom.persistent.ExtArrayNodeSet)7 SequenceIterator (org.exist.xquery.value.SequenceIterator)7 ReentrantLock (java.util.concurrent.locks.ReentrantLock)6 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)6 Match (org.exist.dom.persistent.Match)6