Search in sources :

Example 26 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class RestXqServiceSerializerImpl method serializeNodeBody.

@Override
protected void serializeNodeBody(final Sequence result, final HttpResponse response, final Map<SerializationProperty, String> serializationProperties) throws RestXqServiceException {
    try (final DBBroker broker = getBrokerPool().getBroker();
        final Writer writer = new OutputStreamWriter(response.getOutputStream(), serializationProperties.get(SerializationProperty.ENCODING))) {
        final Properties outputProperties = serializationPropertiesToProperties(serializationProperties);
        final XQuerySerializer xqSerializer = new XQuerySerializer(broker, outputProperties, writer);
        xqSerializer.serialize(((SequenceAdapter) result).getExistSequence());
        writer.flush();
    } catch (IOException | XPathException | SAXException | EXistException ioe) {
        throw new RestXqServiceException("Error while serializing xml: " + ioe.toString(), ioe);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) RestXqServiceException(org.exquery.restxq.RestXqServiceException) XQuerySerializer(org.exist.util.serializer.XQuerySerializer) XPathException(org.exist.xquery.XPathException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) EXistException(org.exist.EXistException) Properties(java.util.Properties) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) SAXException(org.xml.sax.SAXException)

Example 27 with XPathException

use of org.exist.xquery.XPathException 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 28 with XPathException

use of org.exist.xquery.XPathException 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 29 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class AbstractFieldConfig method compile.

protected CompiledXQuery compile(DBBroker broker, String code) {
    final XQuery xquery = broker.getBrokerPool().getXQueryService();
    final XQueryContext context = new XQueryContext(broker.getBrokerPool());
    try {
        return xquery.compile(context, code);
    } catch (XPathException | PermissionDeniedException e) {
        LOG.error("Failed to compile expression: {}: {}", code, e.getMessage(), e);
        isValid = false;
        return null;
    }
}
Also used : XPathException(org.exist.xquery.XPathException) CompiledXQuery(org.exist.xquery.CompiledXQuery) XQuery(org.exist.xquery.XQuery) XQueryContext(org.exist.xquery.XQueryContext) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Example 30 with XPathException

use of org.exist.xquery.XPathException in project exist by eXist-db.

the class SendRequestFunction method sendRequest.

private Sequence sendRequest(final NodeValue request, final String href, final Sequence bodies) throws XPathException {
    HttpRequest req = null;
    try {
        final org.expath.tools.model.Sequence b = new EXistSequence(bodies, getContext());
        final Element r = new EXistElement(request, getContext());
        final RequestParser parser = new RequestParser(r);
        req = parser.parse(b, href);
        // override anyway it href exists
        if (href != null && !href.isEmpty()) {
            req.setHref(href);
        }
        final URI uri = new URI(req.getHref());
        final EXistResult result = sendOnce(uri, req, parser);
        return result.getResult();
    } catch (final URISyntaxException ex) {
        throw new XPathException(this, "Href is not valid: " + req != null ? req.getHref() : "" + ". " + ex.getMessage(), ex);
    } catch (final HttpClientException hce) {
        throw new XPathException(this, hce.getMessage(), hce);
    }
}
Also used : HttpRequest(org.expath.httpclient.HttpRequest) EXistSequence(org.expath.tools.model.exist.EXistSequence) EXistElement(org.expath.tools.model.exist.EXistElement) XPathException(org.exist.xquery.XPathException) Element(org.expath.tools.model.Element) EXistElement(org.expath.tools.model.exist.EXistElement) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HttpClientException(org.expath.httpclient.HttpClientException) RequestParser(org.expath.httpclient.impl.RequestParser) EXistResult(org.expath.httpclient.model.exist.EXistResult)

Aggregations

XPathException (org.exist.xquery.XPathException)306 Sequence (org.exist.xquery.value.Sequence)86 IOException (java.io.IOException)61 SAXException (org.xml.sax.SAXException)43 StringValue (org.exist.xquery.value.StringValue)40 PermissionDeniedException (org.exist.security.PermissionDeniedException)34 NodeValue (org.exist.xquery.value.NodeValue)34 DBBroker (org.exist.storage.DBBroker)32 IntegerValue (org.exist.xquery.value.IntegerValue)32 ValueSequence (org.exist.xquery.value.ValueSequence)27 Item (org.exist.xquery.value.Item)26 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)24 EXistException (org.exist.EXistException)23 Path (java.nio.file.Path)22 XmldbURI (org.exist.xmldb.XmldbURI)22 BrokerPool (org.exist.storage.BrokerPool)21 Txn (org.exist.storage.txn.Txn)21 XQueryContext (org.exist.xquery.XQueryContext)21 Element (org.w3c.dom.Element)21 XQuery (org.exist.xquery.XQuery)20