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);
}
}
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();
}
}
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();
}
}
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;
}
}
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);
}
}
Aggregations